请问epoll不触发hup是什么问题,请问epoll触发hup,一个简单的例子,当我te
请问epoll不触发hup是什么问题,请问epoll触发hup,一个简单的例子,当我te
一个简单的例子,当我telnet 127.0.0.1 1234后,我关掉打开telnet的那个终端窗口,为什么不会触发event & select.EPOLLHUP。求解。
import socketimport selectserver=socket.socket(socket.AF_INET,socket.SOCK_STREAM)server.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1)server.bind(('0.0.0.0',1234))server.listen(10)server.setblocking(0)epoll=select.epoll()epoll.register(server.fileno(),select.EPOLLIN)print 'server filno:',server.fileno()try: connections={};requests={};responses={} while True: events=epoll.poll(1) for fileno,event in events: print 'event', event if fileno == server.fileno(): connection,addr=server.accept() connFd=connection.fileno() connection.setblocking(0) epoll.register(connFd,select.EPOLLIN) connections[connFd]=connection elif event & select.EPOLLIN: requests[fileno]=connections[fileno].recv(1024).strip() epoll.modify(fileno,select.EPOLLOUT) elif event & select.EPOLLOUT: connections[fileno].send(requests[fileno]+'\n') epoll.modify(fileno,select.EPOLLIN) elif event & select.EPOLLHUP: print('close') epoll.unregister(fileno) connections[fileno].close() del connections[fileno]finally: pass
当对端正常关闭连接时,会同时触发EPOLLIN和EPOLLHUP:
EPOLLIN:0b1
EPOLLOUT:0b100
EPOLLHUP:0b10000
我稍微改动了你的代码打印了event的二进制值,发现当对端关闭连接时,event的二进制值是:event 0b11001,即 EPOLLIN | EPOLLHUP | 1000,这其实与预期是符合的,EPOLLIN和EPOLLHUP确实是同时触发了,但你的处理代码里用的是elif这样的组合,如果两个分支同时满足,是会被跳过的,恰好你的EPOLLIN写在EPOLLHUP前,所以EPOLLHUP完全被忽略掉了。
编橙之家文章,
相关内容
- 为什么msys生成exe后被python subprocess调用却没有得不到返
- Python bottle分页实现求指点,pythonbottle,第一次使用Bott
- Python爬虫实现网易博客发表评论思路大神指导下,pyt
- 请问Python生md5与shell生成不同原因,pythonmd5,python 代码:
- 想学习Python sqlmap源码剖析有好的书籍推荐吗,pythonsq
- Python环境保存操作思路问题求助,python问题求助,我想做
- Django mock模拟数据行为http response该如何设置,djangomoc
- svn完成自动部署有哪些注意事项,svn部署注意事项,公司
- 求教simditor富文本编辑提交后显示在页面上的方法,s
- Python哪个库适合处理git log,pythongitlog,想写个轮子先探
评论关闭