From: <am...@us...> - 2009-01-05 19:58:55
|
Revision: 5855 http://jython.svn.sourceforge.net/jython/?rev=5855&view=rev Author: amak Date: 2009-01-05 19:58:51 +0000 (Mon, 05 Jan 2009) Log Message: ----------- Fixed a bug where connect timeouts were not being honoured when set through socket.setdefaulttimeout() http://bugs.jython.org/issue1218 Modified Paths: -------------- branches/Release_2_2maint/jython/Lib/socket.py branches/Release_2_2maint/jython/Lib/test/test_socket.py Modified: branches/Release_2_2maint/jython/Lib/socket.py =================================================================== --- branches/Release_2_2maint/jython/Lib/socket.py 2009-01-05 19:47:25 UTC (rev 5854) +++ branches/Release_2_2maint/jython/Lib/socket.py 2009-01-05 19:58:51 UTC (rev 5855) @@ -617,12 +617,14 @@ class _nonblocking_api_mixin: - timeout = _defaulttimeout mode = MODE_BLOCKING reference_count = 0 close_lock = threading.Lock() def __init__(self): + self.timeout = _defaulttimeout + if self.timeout is not None: + self.mode = MODE_TIMEOUT self.pending_options = { SO_REUSEADDR: 0, } Modified: branches/Release_2_2maint/jython/Lib/test/test_socket.py =================================================================== --- branches/Release_2_2maint/jython/Lib/test/test_socket.py 2009-01-05 19:47:25 UTC (rev 5854) +++ branches/Release_2_2maint/jython/Lib/test/test_socket.py 2009-01-05 19:58:51 UTC (rev 5855) @@ -1295,6 +1295,23 @@ socket.timeout. This tries to connect to %s in the assumption that it isn't used, but if it is on your network this failure is bogus.''' % host) + def testConnectDefaultTimeout(self): + _saved_timeout = socket.getdefaulttimeout() + socket.setdefaulttimeout(0.1) + cli = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + host = '192.168.192.168' + try: + cli.connect((host, 5000)) + except socket.timeout, st: + pass + except Exception, x: + self.fail("Client socket timeout should have raised socket.timeout, not %s" % str(x)) + else: + self.fail('''Client socket timeout should have raised +socket.timeout. This tries to connect to %s in the assumption that it isn't +used, but if it is on your network this failure is bogus.''' % host) + socket.setdefaulttimeout(_saved_timeout) + def testRecvTimeout(self): def raise_timeout(*args, **kwargs): cli_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |