mailru / easygo

Tools for building go apps.
MIT License
673 stars 123 forks source link

EventErr #9

Open damanloox opened 5 years ago

damanloox commented 5 years ago
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()?

wI2L commented 5 years ago

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.