Skip to content

Commit 8feb49d

Browse files
author
Reckhou
committed
修正示例代码中当客户端已关闭TCP连接时,服务端未及时关闭连接的问题
1 parent 17fdc43 commit 8feb49d

File tree

1 file changed

+3
-11
lines changed

1 file changed

+3
-11
lines changed

ebook/08.1.md

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -261,20 +261,12 @@ Go语言中通过net包中的`DialTCP`函数来建立一个TCP连接,并返回
261261
read_len, err := conn.Read(request)
262262

263263
if err != nil {
264-
if err != io.EOF { // ignore EOF since client might send nothing for the moment
265-
fmt.Println(err)
266-
break
267-
}
268-
269-
neterr, ok := err.(net.Error)
270-
if ok && neterr.Timeout() {
271-
fmt.Println(neterr)
272-
break
273-
}
264+
fmt.Println(err)
265+
break
274266
}
275267

276268
if read_len == 0 {
277-
continue
269+
break // connection already closed by client
278270
} else if string(request) == "timestamp" {
279271
daytime := strconv.FormatInt(time.Now().Unix(), 10)
280272
conn.Write([]byte(daytime))

0 commit comments

Comments
 (0)