def poll(self):
time.sleep(0.0000000001) # give epoll.modify a chance
if not self._connections:
time.sleep(1)
return
for fileno in self._connections:
if fileno not in self._servers:
if self._connections[fileno].outbuffer:
self._epoll.modify(fileno, self._rw)
else:
self._epoll.modify(fileno, self._ro)
for fileno, event in self._epoll.poll(timeout=1):
if fileno in self._servers:
server = self._servers[fileno]
server.handle_connection()
else:
if event & select.EPOLLIN:
try:
con = self._connections[fileno]
con._in()
except Exception as e: # noqa
# logger.exception("{}: {}".format(self._name, e))
con.close()
continue
if event & select.EPOLLOUT:
try:
con = self._connections[fileno]
con._out()
except Exception as e: # noqa
con.close()
continue
if event & (select.EPOLLHUP | select.EPOLLERR):
try:
con = self._connections[fileno]
con.close()
continue
except:
pass
评论列表
文章目录