From: <am...@us...> - 2009-01-05 19:47:31
|
Revision: 5854 http://jython.svn.sourceforge.net/jython/?rev=5854&view=rev Author: amak Date: 2009-01-05 19:47:25 +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: -------------- trunk/jython/Lib/socket.py trunk/jython/Lib/test/test_socket.py Modified: trunk/jython/Lib/socket.py =================================================================== --- trunk/jython/Lib/socket.py 2009-01-05 19:06:58 UTC (rev 5853) +++ trunk/jython/Lib/socket.py 2009-01-05 19:47:25 UTC (rev 5854) @@ -632,12 +632,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, } @@ -791,7 +793,7 @@ self.sock_impl.bind(bind_host, bind_port, self.pending_options[SO_REUSEADDR]) self._config() # Configure timeouts, etc, now that the socket exists self.sock_impl.connect(host, port) - except java.lang.Exception, jlx: + except java.lang.Exception, jlx: raise _map_exception(jlx) def connect(self, addr): Modified: trunk/jython/Lib/test/test_socket.py =================================================================== --- trunk/jython/Lib/test/test_socket.py 2009-01-05 19:06:58 UTC (rev 5853) +++ trunk/jython/Lib/test/test_socket.py 2009-01-05 19:47:25 UTC (rev 5854) @@ -1320,6 +1320,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. |