如何处理 Linux socket revents POLLERR、POLLHUP 和 POLLNVAL? [英] How to handle the Linux socket revents POLLERR, POLLHUP and POLLNVAL?

查看:34
本文介绍了如何处理 Linux socket revents POLLERR、POLLHUP 和 POLLNVAL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道轮询设置这些位时应该做什么?关闭套接字,忽略它还是什么?

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

推荐答案

A POLLHUP 表示套接字不再连接.在 TCP 中,这意味着 FIN 已被接收和发送.

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

A POLLERR 表示套接字出现异步错误.在 TCP 中,这通常意味着已接收或发送 RST.如果文件描述符不是套接字,POLLERR 可能意味着设备不支持轮询.

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.

对于上述两种情况,套接字文件描述符仍处于打开状态,尚未关闭(但 shutdown() 可能已被调用).文件描述符上的 close() 将释放仍代表套接字保留的资源.理论上,应该可以立即重用套接字(例如,使用另一个 connect() 调用).

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 表示套接字文件描述符未打开.close() 它会出错.

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

这篇关于如何处理 Linux socket revents POLLERR、POLLHUP 和 POLLNVAL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆