This commit is contained in:
esrrhs 2019-10-27 12:39:55 +08:00
parent dc02a58284
commit d0897dd522
2 changed files with 16 additions and 0 deletions

View File

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

View File

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