add traffic control for each TCP connection

This commit is contained in:
破娃酱
2017-02-12 22:35:26 +08:00
parent 2750af4a2e
commit 72ca31dad9
5 changed files with 75 additions and 18 deletions
+4 -1
View File
@@ -208,12 +208,13 @@ class EventLoop(object):
traceback.print_exc()
continue
handle = False
for sock, fd, event in events:
handler = self._fdmap.get(fd, None)
if handler is not None:
handler = handler[1]
try:
handler.handle_event(sock, fd, event)
handle = handle or handler.handle_event(sock, fd, event)
except (OSError, IOError) as e:
shell.print_exception(e)
now = time.time()
@@ -221,6 +222,8 @@ class EventLoop(object):
for callback in self._periodic_callbacks:
callback()
self._last_time = now
if events and (handle is False):
time.sleep(0.01)
def __del__(self):
self._impl.close()