This commit is contained in:
esrrhs 2019-10-27 12:52:02 +08:00
parent d0897dd522
commit 37005c8ae8
2 changed files with 4 additions and 16 deletions

View File

@ -223,7 +223,6 @@ func (p *Client) AcceptTcpConn(conn *net.TCPConn) {
for { for {
now := time.Now() now := time.Now()
sleep := true
left := common.MinOfInt(clientConn.fm.GetSendBufferLeft(), len(bytes)) left := common.MinOfInt(clientConn.fm.GetSendBufferLeft(), len(bytes))
if left > 0 { if left > 0 {
@ -238,9 +237,10 @@ func (p *Client) AcceptTcpConn(conn *net.TCPConn) {
} }
} }
if n > 0 { if n > 0 {
sleep = false
clientConn.fm.WriteSendBuffer(bytes[:n]) clientConn.fm.WriteSendBuffer(bytes[:n])
tcpActiveRecvTime = now tcpActiveRecvTime = now
} else {
time.Sleep(time.Millisecond * 10)
} }
} }
@ -248,7 +248,6 @@ func (p *Client) AcceptTcpConn(conn *net.TCPConn) {
sendlist := clientConn.fm.getSendList() sendlist := clientConn.fm.getSendList()
if sendlist.Len() > 0 { if sendlist.Len() > 0 {
sleep = false
clientConn.activeSendTime = now clientConn.activeSendTime = now
for e := sendlist.Front(); e != nil; e = e.Next() { for e := sendlist.Front(); e != nil; e = e.Next() {
f := e.Value.(*Frame) f := e.Value.(*Frame)
@ -268,7 +267,6 @@ func (p *Client) AcceptTcpConn(conn *net.TCPConn) {
} }
if clientConn.fm.GetRecvBufferSize() > 0 { if clientConn.fm.GetRecvBufferSize() > 0 {
sleep = false
rr := clientConn.fm.GetRecvReadLineBuffer() rr := clientConn.fm.GetRecvReadLineBuffer()
conn.SetWriteDeadline(time.Now().Add(time.Millisecond * 1)) conn.SetWriteDeadline(time.Now().Add(time.Millisecond * 1))
n, err := conn.Write(rr) n, err := conn.Write(rr)
@ -286,10 +284,6 @@ func (p *Client) AcceptTcpConn(conn *net.TCPConn) {
} }
} }
if sleep {
time.Sleep(time.Millisecond * 1)
}
diffrecv := now.Sub(clientConn.activeRecvTime) diffrecv := now.Sub(clientConn.activeRecvTime)
diffsend := now.Sub(clientConn.activeSendTime) diffsend := now.Sub(clientConn.activeSendTime)
tcpdiffrecv := now.Sub(tcpActiveRecvTime) tcpdiffrecv := now.Sub(tcpActiveRecvTime)

View File

@ -189,7 +189,6 @@ func (p *Server) RecvTCP(conn *ServerConn, id string, src *net.IPAddr) {
for { for {
now := time.Now() now := time.Now()
sleep := true
left := common.MinOfInt(conn.fm.GetSendBufferLeft(), len(bytes)) left := common.MinOfInt(conn.fm.GetSendBufferLeft(), len(bytes))
if left > 0 { if left > 0 {
@ -204,9 +203,10 @@ func (p *Server) RecvTCP(conn *ServerConn, id string, src *net.IPAddr) {
} }
} }
if n > 0 { if n > 0 {
sleep = false
conn.fm.WriteSendBuffer(bytes[:n]) conn.fm.WriteSendBuffer(bytes[:n])
tcpActiveRecvTime = now tcpActiveRecvTime = now
} else {
time.Sleep(time.Millisecond * 10)
} }
} }
@ -214,7 +214,6 @@ func (p *Server) RecvTCP(conn *ServerConn, id string, src *net.IPAddr) {
sendlist := conn.fm.getSendList() sendlist := conn.fm.getSendList()
if sendlist.Len() > 0 { if sendlist.Len() > 0 {
sleep = false
conn.activeSendTime = now conn.activeSendTime = now
for e := sendlist.Front(); e != nil; e = e.Next() { for e := sendlist.Front(); e != nil; e = e.Next() {
f := e.Value.(*Frame) f := e.Value.(*Frame)
@ -233,7 +232,6 @@ func (p *Server) RecvTCP(conn *ServerConn, id string, src *net.IPAddr) {
} }
if conn.fm.GetRecvBufferSize() > 0 { if conn.fm.GetRecvBufferSize() > 0 {
sleep = false
rr := conn.fm.GetRecvReadLineBuffer() rr := conn.fm.GetRecvReadLineBuffer()
conn.tcpconn.SetWriteDeadline(time.Now().Add(time.Millisecond * 1)) conn.tcpconn.SetWriteDeadline(time.Now().Add(time.Millisecond * 1))
n, err := conn.tcpconn.Write(rr) n, err := conn.tcpconn.Write(rr)
@ -251,10 +249,6 @@ func (p *Server) RecvTCP(conn *ServerConn, id string, src *net.IPAddr) {
} }
} }
if sleep {
time.Sleep(time.Millisecond * 1)
}
diffrecv := now.Sub(conn.activeRecvTime) diffrecv := now.Sub(conn.activeRecvTime)
diffsend := now.Sub(conn.activeSendTime) diffsend := now.Sub(conn.activeSendTime)
tcpdiffrecv := now.Sub(tcpActiveRecvTime) tcpdiffrecv := now.Sub(tcpActiveRecvTime)