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

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

问题描述

我想知道当民意调查设置这些位时应该怎么做?关闭套接字,忽略它还是什么?

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

推荐答案

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套接口POLLERR,POLLHUP和POLLNVAL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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