mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-12-18 17:36:36 +08:00
向客户端写入数据超时时立即关闭连接
This commit is contained in:
@@ -115,7 +115,7 @@ func (this *ClientConn) Read(b []byte) (n int, err error) {
|
|||||||
|
|
||||||
func (this *ClientConn) Write(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 时间可以设置
|
_ = this.rawConn.SetWriteDeadline(time.Now().Add(60 * time.Second)) // TODO 时间可以设置
|
||||||
|
|
||||||
n, err = this.rawConn.Write(b)
|
n, err = this.rawConn.Write(b)
|
||||||
if n > 0 {
|
if n > 0 {
|
||||||
@@ -128,6 +128,14 @@ func (this *ClientConn) Write(b []byte) (n int, err error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 如果是写入超时,则立即关闭连接
|
||||||
|
if err != nil && os.IsTimeout(err) {
|
||||||
|
conn, ok := this.rawConn.(LingerConn)
|
||||||
|
if ok {
|
||||||
|
_ = conn.SetLinger(0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user