Skip to content

Instantly share code, notes, and snippets.

@abserari
Created October 31, 2020 14:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abserari/0adbcb85a88f1772a75e9724c29a7243 to your computer and use it in GitHub Desktop.
Save abserari/0adbcb85a88f1772a75e9724c29a7243 to your computer and use it in GitHub Desktop.
func echo(wq *waiter.Queue, ep tcpip.Endpoint) {
defer ep.Close()
// Create wait queue entry that notifies a channel.
waitEntry, notifyCh := waiter.NewChannelEntry(nil)
wq.EventRegister(&waitEntry, waiter.EventIn)
defer wq.EventUnregister(&waitEntry)
for {
v, _, err := ep.Read(nil)
if err != nil {
if err == tcpip.ErrWouldBlock {
<-notifyCh
continue
}
return
}
ep.Write(tcpip.SlicePayload(v), tcpip.WriteOptions{})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment