Fix a lock problem in pkg/tcpip/sample/tun_tcp_echo

This commit is contained in:
xyz
2023-11-08 04:31:19 +00:00
parent 42b69d0151
commit 97ee5cb6ab
+6 -2
View File
@@ -87,8 +87,8 @@ func echo(wq *waiter.Queue, ep tcpip.Endpoint) {
}
for {
_, err := ep.Read(&w, tcpip.ReadOptions{})
if err != nil {
var buf bytes.Buffer
if _, err := ep.Read(&buf, tcpip.ReadOptions{}); err != nil {
if _, ok := err.(*tcpip.ErrWouldBlock); ok {
<-notifyCh
continue
@@ -96,6 +96,10 @@ func echo(wq *waiter.Queue, ep tcpip.Endpoint) {
return
}
if _, err := w.Write(buf.Bytes()); err != nil {
return
}
}
}