TCP单次向客户端写入数据时超过30秒即认为超时

This commit is contained in:
刘祥超
2022-12-10 18:22:00 +08:00
parent 9fa24bed0a
commit 60a8de13e7

View File

@@ -114,6 +114,9 @@ func (this *ClientConn) Read(b []byte) (n int, err error) {
}
func (this *ClientConn) Write(b []byte) (n int, err error) {
// 设置超时时间
_ = this.rawConn.SetWriteDeadline(time.Now().Add(30 * time.Second)) // TODO 时间可以设置
n, err = this.rawConn.Write(b)
if n > 0 {
// 统计当前服务带宽