1

I have an aysnc threadpool model for my network connection management. A single dispatcher thread that keeps calling poll() and a worker thread pool that either read/write once poll() indicates so.

Consider a case where poll() indicates a socket is read-ready. But the worker thread hasn't processed the read yet. I disable read-poll while the worker thread hasn't processed the read. Now the remote side disconnects and poll() returns with POLLERR/POLLHUP. What happens when the worker thread does the read() call after this?

Does read() return <0 even though there is some data that hasn't been read yet? Or

Does read() read data from the network even though the socket had a POLLERR/POLLHUP?

siri
  • 123
  • 1
  • 13

1 Answers1

0

All the pending data will be delivered before read() returns zero. However if read() returns -1, pending data may have been lost.

user207421
  • 305,947
  • 44
  • 307
  • 483