Commit 9ce84ce0 authored by Taddeüs Kroes's avatar Taddeüs Kroes

Changed number picking such that a new chosen number is as small as possible

parent e23ed990
......@@ -7,7 +7,6 @@ from twspy import Connection
class Multiplexer(object):
def __init__(self, sock):
self.channels = []
self.number = 0
self.conn = MuxConnection(sock)
def __str__(self):
......@@ -21,9 +20,16 @@ class Multiplexer(object):
return 'closed connection'
def add_channel(self, channel):
self.channels.append(channel)
self.number += 1
return self.number
numbers = sorted(self.channels)
number = numbers[-1] + 1 is len(numbers) else 1
for i, nr in enumerate(numbers):
if self.channels[i + 1] > nr:
number = nr + 1
break
self.channels[number] = channel
return number
def send(self, message, channel):
raise NotImplementedError
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment