Skip to content
Snippets Groups Projects
Commit e3b0c45b authored by Piotr Maślanka's avatar Piotr Maślanka
Browse files

Fixed a on_connected() bug

Socket's on_connected() would not always be called when it should. Bug
was fixed and an unit test added
parent cf8a960d
No related branches found
No related tags found
No related merge requests found
......@@ -144,9 +144,9 @@ class Socket(FileDescriptorChannel):
# successfully or not. Mark it.
if not self.connected:
self.connected = True
self.on_connected()
if len(self.tx_buffer) == 0:
return
self.on_connected()
try:
ki = self.socket.send(self.tx_buffer)
......
......@@ -10,6 +10,28 @@ import unittest
TESTING_PORT = 49999
class SelectHandlingLayerTest(unittest.TestCase):
"""This suite requires that www.yahoo.com is reachable and
connectable via port 80"""
def test_async_socket_onconnected_called(self):
"""Tests whether socket's on_connected() is called in async configuration"""
class CheckSocket(Socket):
def __init__(self, *args, **kwargs):
self.on_connected_called = False
Socket.__init__(self, *args, **kwargs)
def on_connected(self):
self.on_connected_called = True
mshl = SelectHandlingLayer()
sck = CheckSocket(socket(AF_INET, SOCK_STREAM))
mshl.register_channel(sck)
sck.connect(('www.yahoo.com', 80)) # that was just nonblocking
a = time()
while (time() - a < 30) and (not sck.on_connected_called):
mshl.select()
self.assertEquals(sck.on_connected_called, True)
def test_nonblocking_connect(self):
class MySelectHandlingLayer(SelectHandlingLayer):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment