add
This commit is contained in:
parent
30b1cd117b
commit
1657f46784
16
server.go
16
server.go
@ -41,6 +41,7 @@ type Server struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type ServerConn struct {
|
type ServerConn struct {
|
||||||
|
exit bool
|
||||||
timeout int
|
timeout int
|
||||||
ipaddrTarget *net.UDPAddr
|
ipaddrTarget *net.UDPAddr
|
||||||
conn *net.UDPConn
|
conn *net.UDPConn
|
||||||
@ -153,7 +154,7 @@ func (p *Server) processPacket(packet *Packet) {
|
|||||||
fm := NewFrameMgr((int)(packet.my.TcpmodeBuffersize), (int)(packet.my.TcpmodeMaxwin), (int)(packet.my.TcpmodeResendTimems), (int)(packet.my.TcpmodeCompress),
|
fm := NewFrameMgr((int)(packet.my.TcpmodeBuffersize), (int)(packet.my.TcpmodeMaxwin), (int)(packet.my.TcpmodeResendTimems), (int)(packet.my.TcpmodeCompress),
|
||||||
(int)(packet.my.TcpmodeStat))
|
(int)(packet.my.TcpmodeStat))
|
||||||
|
|
||||||
localConn = &ServerConn{timeout: (int)(packet.my.Timeout), tcpconn: targetConn, tcpaddrTarget: ipaddrTarget, id: id, activeRecvTime: now, activeSendTime: now, close: false,
|
localConn = &ServerConn{exit: false, timeout: (int)(packet.my.Timeout), tcpconn: targetConn, tcpaddrTarget: ipaddrTarget, id: id, activeRecvTime: now, activeSendTime: now, close: false,
|
||||||
rproto: (int)(packet.my.Rproto), fm: fm, tcpmode: (int)(packet.my.Tcpmode)}
|
rproto: (int)(packet.my.Rproto), fm: fm, tcpmode: (int)(packet.my.Tcpmode)}
|
||||||
|
|
||||||
p.addServerConn(id, localConn)
|
p.addServerConn(id, localConn)
|
||||||
@ -173,7 +174,7 @@ func (p *Server) processPacket(packet *Packet) {
|
|||||||
targetConn := c.(*net.UDPConn)
|
targetConn := c.(*net.UDPConn)
|
||||||
ipaddrTarget := targetConn.RemoteAddr().(*net.UDPAddr)
|
ipaddrTarget := targetConn.RemoteAddr().(*net.UDPAddr)
|
||||||
|
|
||||||
localConn = &ServerConn{timeout: (int)(packet.my.Timeout), conn: targetConn, ipaddrTarget: ipaddrTarget, id: id, activeRecvTime: now, activeSendTime: now, close: false,
|
localConn = &ServerConn{exit: false, timeout: (int)(packet.my.Timeout), conn: targetConn, ipaddrTarget: ipaddrTarget, id: id, activeRecvTime: now, activeSendTime: now, close: false,
|
||||||
rproto: (int)(packet.my.Rproto), tcpmode: (int)(packet.my.Tcpmode)}
|
rproto: (int)(packet.my.Rproto), tcpmode: (int)(packet.my.Tcpmode)}
|
||||||
|
|
||||||
p.addServerConn(id, localConn)
|
p.addServerConn(id, localConn)
|
||||||
@ -219,7 +220,7 @@ func (p *Server) RecvTCP(conn *ServerConn, id string, src *net.IPAddr) {
|
|||||||
|
|
||||||
loggo.Info("start wait remote connect tcp %s %s", conn.id, conn.tcpaddrTarget.String())
|
loggo.Info("start wait remote connect tcp %s %s", conn.id, conn.tcpaddrTarget.String())
|
||||||
startConnectTime := time.Now()
|
startConnectTime := time.Now()
|
||||||
for !p.exit {
|
for !p.exit && !conn.exit {
|
||||||
if conn.fm.IsConnected() {
|
if conn.fm.IsConnected() {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@ -245,14 +246,16 @@ func (p *Server) RecvTCP(conn *ServerConn, id string, src *net.IPAddr) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
loggo.Info("remote connected tcp %s %s", conn.id, conn.tcpaddrTarget.String())
|
if !conn.exit {
|
||||||
|
loggo.Info("remote connected tcp %s %s", conn.id, conn.tcpaddrTarget.String())
|
||||||
|
}
|
||||||
|
|
||||||
bytes := make([]byte, 10240)
|
bytes := make([]byte, 10240)
|
||||||
|
|
||||||
tcpActiveRecvTime := time.Now()
|
tcpActiveRecvTime := time.Now()
|
||||||
tcpActiveSendTime := time.Now()
|
tcpActiveSendTime := time.Now()
|
||||||
|
|
||||||
for !p.exit {
|
for !p.exit && !conn.exit {
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
sleep := true
|
sleep := true
|
||||||
|
|
||||||
@ -339,7 +342,7 @@ func (p *Server) RecvTCP(conn *ServerConn, id string, src *net.IPAddr) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
startCloseTime := time.Now()
|
startCloseTime := time.Now()
|
||||||
for !p.exit {
|
for !p.exit && !conn.exit {
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
|
|
||||||
conn.fm.Update()
|
conn.fm.Update()
|
||||||
@ -426,6 +429,7 @@ func (p *Server) Recv(conn *ServerConn, id string, src *net.IPAddr) {
|
|||||||
|
|
||||||
func (p *Server) close(conn *ServerConn) {
|
func (p *Server) close(conn *ServerConn) {
|
||||||
if p.getServerConnById(conn.id) != nil {
|
if p.getServerConnById(conn.id) != nil {
|
||||||
|
conn.exit = true
|
||||||
if conn.conn != nil {
|
if conn.conn != nil {
|
||||||
conn.conn.Close()
|
conn.conn.Close()
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user