Seperate .waiting_send() and throttle logic
This commit is contained in:
parent
9a78dabcc2
commit
527d548743
2 changed files with 9 additions and 7 deletions
10
IRCBot.py
10
IRCBot.py
|
@ -76,11 +76,11 @@ class Bot(object):
|
||||||
timer.call()
|
timer.call()
|
||||||
if timer.done():
|
if timer.done():
|
||||||
self.timer_setting_remove(timer)
|
self.timer_setting_remove(timer)
|
||||||
def next_write(self):
|
def next_send(self):
|
||||||
next = None
|
next = None
|
||||||
for server in self.servers.values():
|
for server in self.servers.values():
|
||||||
timeout = server.send_timeout()
|
timeout = server.send_throttle_timeout()
|
||||||
if not next or timeout < next:
|
if server.waiting_send() and (not next or timeout < next):
|
||||||
next = timeout
|
next = timeout
|
||||||
if next == None:
|
if next == None:
|
||||||
return None
|
return None
|
||||||
|
@ -90,7 +90,7 @@ class Bot(object):
|
||||||
|
|
||||||
def get_poll_timeout(self):
|
def get_poll_timeout(self):
|
||||||
next_timer = self.next_timer() or 30
|
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)
|
return min(next_timer, next_write)
|
||||||
|
|
||||||
def register_read(self, server):
|
def register_read(self, server):
|
||||||
|
@ -171,6 +171,6 @@ class Bot(object):
|
||||||
|
|
||||||
print("disconnected from %s, reconnecting in %d seconds" % (
|
print("disconnected from %s, reconnecting in %d seconds" % (
|
||||||
str(server), reconnect_delay))
|
str(server), reconnect_delay))
|
||||||
elif server.waiting_send():
|
elif server.waiting_send() and server.throttle_done():
|
||||||
self.register_both(server)
|
self.register_both(server)
|
||||||
self.lock.release()
|
self.lock.release()
|
||||||
|
|
|
@ -222,8 +222,10 @@ class Server(object):
|
||||||
self.write_buffer[:512]):]
|
self.write_buffer[:512]):]
|
||||||
self.last_send = time.monotonic()
|
self.last_send = time.monotonic()
|
||||||
def waiting_send(self):
|
def waiting_send(self):
|
||||||
return bool(len(self.write_buffer)) and self.send_timeout() == 0
|
return bool(len(self.write_buffer))
|
||||||
def send_timeout(self):
|
def throttle_done(self):
|
||||||
|
return self.send_throttle_timeout() == 0
|
||||||
|
def send_throttle_timeout(self):
|
||||||
if self.last_send == None:
|
if self.last_send == None:
|
||||||
return 0
|
return 0
|
||||||
timeout = (self.last_send)+0.5
|
timeout = (self.last_send)+0.5
|
||||||
|
|
Loading…
Reference in a new issue