mirror of
https://github.com/ehang-io/nps.git
synced 2025-09-02 20:16:52 +00:00
bug
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
package conn
|
||||
|
||||
import (
|
||||
"github.com/cnlh/nps/lib/common"
|
||||
"github.com/cnlh/nps/lib/file"
|
||||
"github.com/cnlh/nps/lib/pool"
|
||||
"github.com/cnlh/nps/lib/rate"
|
||||
"net"
|
||||
)
|
||||
@@ -18,6 +20,9 @@ type Link struct {
|
||||
UdpListener *net.UDPConn
|
||||
Rate *rate.Rate
|
||||
UdpRemoteAddr *net.UDPAddr
|
||||
MsgCh chan []byte
|
||||
MsgConn *Conn
|
||||
StatusCh chan bool
|
||||
}
|
||||
|
||||
func NewLink(id int, connType string, host string, en, de int, crypt bool, c *Conn, flow *file.Flow, udpListener *net.UDPConn, rate *rate.Rate, UdpRemoteAddr *net.UDPAddr) *Link {
|
||||
@@ -33,5 +38,37 @@ func NewLink(id int, connType string, host string, en, de int, crypt bool, c *Co
|
||||
UdpListener: udpListener,
|
||||
Rate: rate,
|
||||
UdpRemoteAddr: UdpRemoteAddr,
|
||||
MsgCh: make(chan []byte),
|
||||
StatusCh: make(chan bool),
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Link) Run(flow bool) {
|
||||
go func() {
|
||||
for {
|
||||
select {
|
||||
case content := <-s.MsgCh:
|
||||
if len(content) == len(common.IO_EOF) && string(content) == common.IO_EOF {
|
||||
if s.Conn != nil {
|
||||
s.Conn.Close()
|
||||
}
|
||||
return
|
||||
} else {
|
||||
if s.UdpListener != nil && s.UdpRemoteAddr != nil {
|
||||
s.UdpListener.WriteToUDP(content, s.UdpRemoteAddr)
|
||||
} else {
|
||||
s.Conn.Write(content)
|
||||
}
|
||||
if flow {
|
||||
s.Flow.Add(0, len(content))
|
||||
}
|
||||
if s.ConnType == common.CONN_UDP {
|
||||
return
|
||||
}
|
||||
s.MsgConn.WriteWriteSuccess(s.Id)
|
||||
pool.PutBufPoolCopy(content)
|
||||
}
|
||||
}
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
Reference in New Issue
Block a user