How to handle the Linux socket revents POLLERR, POLLHUP and POLLNVAL?

后端 未结 4 775
栀梦
栀梦 2020-12-05 18:58

I\'m wondering what should be done when poll set these bits? Close socket, ignore it or what?

4条回答
  •  旧巷少年郎
    2020-12-05 19:21

    A POLLHUP means the socket is no longer connected. In TCP, this means FIN has been received and sent.

    A POLLERR means the socket got an asynchronous error. In TCP, this typically means a RST has been received or sent. If the file descriptor is not a socket, POLLERR might mean the device does not support polling.

    For both of the conditions above, the socket file descriptor is still open, and has not yet been closed (but shutdown() may have already been called). A close() on the file descriptor will release resources that are still being reserved on behalf of the socket. In theory, it should be possible to reuse the socket immediately (e.g., with another connect() call).

    A POLLNVAL means the socket file descriptor is not open. It would be an error to close() it.

提交回复
热议问题