From d0897dd52247cfcfcda2e645749136aeda40a03c Mon Sep 17 00:00:00 2001 From: esrrhs Date: Sun, 27 Oct 2019 12:39:55 +0800 Subject: [PATCH] add --- client.go | 8 ++++++++ server.go | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/client.go b/client.go index 03e3342..9a99c8b 100644 --- a/client.go +++ b/client.go @@ -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) diff --git a/server.go b/server.go index badf6b5..abdc002 100644 --- a/server.go +++ b/server.go @@ -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)