aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar jesopo2018-08-28 15:32:50 +0100
committerGravatar jesopo2018-08-28 15:32:50 +0100
commit527d548743a48934465da355a110b4a71079cbba (patch)
tree649ad9ffd00839e0c350258540f6177c56ccb04d
parent80 cols! (diff)
signature
Seperate .waiting_send() and throttle logic
-rw-r--r--IRCBot.py10
-rw-r--r--IRCServer.py6
2 files changed, 9 insertions, 7 deletions
diff --git a/IRCBot.py b/IRCBot.py
index df8dce83..58e1a604 100644
--- a/IRCBot.py
+++ b/IRCBot.py
@@ -76,11 +76,11 @@ class Bot(object):
timer.call()
if timer.done():
self.timer_setting_remove(timer)
- def next_write(self):
+ def next_send(self):
next = None
for server in self.servers.values():
- timeout = server.send_timeout()
- if not next or timeout < next:
+ timeout = server.send_throttle_timeout()
+ if server.waiting_send() and (not next or timeout < next):
next = timeout
if next == None:
return None
@@ -90,7 +90,7 @@ class Bot(object):
def get_poll_timeout(self):
next_timer = self.next_timer() or 30
- next_write = self.next_write() or 30
+ next_write = self.next_send() or 30
return min(next_timer, next_write)
def register_read(self, server):
@@ -171,6 +171,6 @@ class Bot(object):
print("disconnected from %s, reconnecting in %d seconds" % (
str(server), reconnect_delay))
- elif server.waiting_send():
+ elif server.waiting_send() and server.throttle_done():
self.register_both(server)
self.lock.release()
diff --git a/IRCServer.py b/IRCServer.py
index 0908dc76..e38f664e 100644
--- a/IRCServer.py
+++ b/IRCServer.py
@@ -222,8 +222,10 @@ class Server(object):
self.write_buffer[:512]):]
self.last_send = time.monotonic()
def waiting_send(self):
- return bool(len(self.write_buffer)) and self.send_timeout() == 0
- def send_timeout(self):
+ return bool(len(self.write_buffer))
+ def throttle_done(self):
+ return self.send_throttle_timeout() == 0
+ def send_throttle_timeout(self):
if self.last_send == None:
return 0
timeout = (self.last_send)+0.5