1
lcdtyph 2019-05-27 02:01:00 +08:00 via iPhone
对端 close 的话 epoll 返回 EPOLLRDHUP
EPOLLHUP 是对端 reset 了连接(假设 tcp ) |
2
moxiaowei 2019-05-27 07:58:09 +08:00 via iPhone
epoll 主动 modify 触发
|
5
mythmgn 2019-05-29 13:50:59 +08:00
没写过 3 的, 但是处理过 py2.7 的, 估计大同小异 可以参考下我的连接池实现代码:
github.com/baidu/CUP/blob/master/cup/net/async/conn.py 重点是 poll 方法那一块 |
6
mythmgn 2019-05-29 13:51:43 +08:00
@fghjghf
while not self._stopsign: try: events = self._epoll.poll(1) except IOError as err: if err.errno == errno.EINTR: return raise err # log.debug('start to poll') for fileno, event in events: # if it comes from the listen port, new conn if fileno == self._bind_sock.fileno(): newsock, addr = self._bind_sock.accept() self._handle_new_conn(newsock, addr) elif event & select.EPOLLIN: try: self._handle_new_recv(self._fileno2context[fileno]) except KeyError: log.info('socket already closed') elif event & select.EPOLLOUT: try: self._handle_new_send(self._fileno2context[fileno]) except KeyError: log.info('socket already closed') elif (event & select.EPOLLHUP) or (event & select.EPOLLERR): # FIXME: consider if we need to release net msg resources if event & select.EPOLLHUP: log.info('--EPOLLHUP--') else: log.info('--EPOLLERR--') try: self.cleanup_error_context( self._fileno2context[fileno] ) except KeyError: log.info('socket already closed') |