mailru / easygo

Tools for building go apps.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

EventErr

damanloox opened this issue · comments

c, err := l.Accept()
desc := netpoll.Must(netpoll.HandleRead(c))
poller.Start(desc, func(ev netpoll.Event) {
  if ev&netpoll.EventHup != 0 || ev&netpoll.EventErr != 0 {
    // close etc
  }
  go doSomething(c)
}

Why the code above doesn't "catch" connection error (eg. timeout)?
Also - when I close connection c inside doSomething(c) - the poller doesn't seem to catch that either - which leads me to a question - how to stop poller on error inside doSomething()?

The file descriptor of the *Desc instance returned by HandleRead is a copy of the connection file descriptor (see net.TCPConn File() method doc). If you close the connection itself, the file description it represents still exists and is not automatically removed from the poller instance. Instead you should either close connection and the *Desc instance or explicitly use the Poller Stop method to detach the FD from the Poller then close connection.