diff --git a/client.go b/client.go index 601406d..8d1858d 100644 --- a/client.go +++ b/client.go @@ -226,7 +226,7 @@ func (p *Client) AcceptTcpConn(conn *net.TCPConn) { left := common.MinOfInt(clientConn.fm.GetSendBufferLeft(), len(bytes)) if left > 0 { - conn.SetReadDeadline(time.Now().Add(time.Millisecond * 100)) + conn.SetReadDeadline(time.Now().Add(time.Millisecond * 10)) n, err := conn.Read(bytes[0:left]) if err != nil { nerr, ok := err.(net.Error) @@ -262,13 +262,11 @@ func (p *Client) AcceptTcpConn(conn *net.TCPConn) { p.sendPacket++ p.sendPacketSize += (uint64)(len(mb)) } - } else { - time.Sleep(time.Millisecond * 10) } if clientConn.fm.GetRecvBufferSize() > 0 { rr := clientConn.fm.GetRecvReadLineBuffer() - conn.SetWriteDeadline(time.Now().Add(time.Millisecond * 100)) + conn.SetWriteDeadline(time.Now().Add(time.Millisecond * 10)) n, err := conn.Write(rr) if err != nil { nerr, ok := err.(net.Error) @@ -282,8 +280,6 @@ func (p *Client) AcceptTcpConn(conn *net.TCPConn) { clientConn.fm.SkipRecvBuffer(n) tcpActiveSendTime = now } - } else { - time.Sleep(time.Millisecond * 10) } diffrecv := now.Sub(clientConn.activeRecvTime) diff --git a/server.go b/server.go index 9e8e61a..5711f33 100644 --- a/server.go +++ b/server.go @@ -192,7 +192,7 @@ func (p *Server) RecvTCP(conn *ServerConn, id string, src *net.IPAddr) { left := common.MinOfInt(conn.fm.GetSendBufferLeft(), len(bytes)) if left > 0 { - conn.tcpconn.SetReadDeadline(time.Now().Add(time.Millisecond * 100)) + conn.tcpconn.SetReadDeadline(time.Now().Add(time.Millisecond * 10)) n, err := conn.tcpconn.Read(bytes[0:left]) if err != nil { nerr, ok := err.(net.Error) @@ -227,13 +227,11 @@ func (p *Server) RecvTCP(conn *ServerConn, id string, src *net.IPAddr) { p.sendPacket++ p.sendPacketSize += (uint64)(len(mb)) } - } else { - time.Sleep(time.Millisecond * 10) } if conn.fm.GetRecvBufferSize() > 0 { rr := conn.fm.GetRecvReadLineBuffer() - conn.tcpconn.SetWriteDeadline(time.Now().Add(time.Millisecond * 100)) + conn.tcpconn.SetWriteDeadline(time.Now().Add(time.Millisecond * 10)) n, err := conn.tcpconn.Write(rr) if err != nil { nerr, ok := err.(net.Error) @@ -247,8 +245,6 @@ func (p *Server) RecvTCP(conn *ServerConn, id string, src *net.IPAddr) { conn.fm.SkipRecvBuffer(n) tcpActiveSendTime = now } - } else { - time.Sleep(time.Millisecond * 10) } diffrecv := now.Sub(conn.activeRecvTime)