Closed AlexStocks closed 2 years ago
as internal/poll/fd_posix.go fd.eofError shows, when got eof error, the tcp stream buffer length is zero. So this issue is not valid.
What's more, even if the return value "len != 0, error == eof", we will get "len == 0, error == eof" if we continue to read the closed socket as the following examples.
nc -lk 127.0.0.1 20000
package main
import (
"log"
"net"
"os"
"time"
)
func main() {
conn, err := net.Dial("tcp", "127.0.0.1:20000")
if err != nil {
log.Println("dial failed:", err)
os.Exit(1)
}
defer conn.Close()
buffer := make([]byte, 512)
for {
conn.SetReadDeadline(time.Now().Add(1 * time.Second))
n, err := conn.Read(buffer)
if err != nil {
log.Println("Read failed, error:", err, ", count: ", n)
// return
} else {
log.Println("count:", n, "msg:", string(buffer))
}
time.Sleep(3e9)
}
}
What happened:
when read the last tcp package,the return value of Read is "pkgLen, eof". So we should process the last package before considering the error.
However, getty just handle the error and then exit without processing the last package.
What you expected to happen:
Getty processes the last the package before handling the error.