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 ...@@ -7,7 +7,6 @@ from twspy import Connection
class Multiplexer(object): class Multiplexer(object):
def __init__(self, sock): def __init__(self, sock):
self.channels = [] self.channels = []
self.number = 0
self.conn = MuxConnection(sock) self.conn = MuxConnection(sock)
def __str__(self): def __str__(self):
...@@ -21,9 +20,16 @@ class Multiplexer(object): ...@@ -21,9 +20,16 @@ class Multiplexer(object):
return 'closed connection' return 'closed connection'
def add_channel(self, channel): def add_channel(self, channel):
self.channels.append(channel) numbers = sorted(self.channels)
self.number += 1 number = numbers[-1] + 1 is len(numbers) else 1
return self.number
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): def send(self, message, channel):
raise NotImplementedError 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