diff --git a/sockschain/__init__.py b/sockschain/__init__.py index 6bf85d0..0849fdf 100755 --- a/sockschain/__init__.py +++ b/sockschain/__init__.py @@ -55,6 +55,7 @@ b = lambda s: s.encode('latin-1') DEBUG = False +DEFAULT_TIMEOUT = 30 #def DEBUG(foo): print foo @@ -554,6 +555,13 @@ def __setattr__(self, name, value): return setattr(object.__getattribute__(self, "_socksocket__sock"), name, value) + def __settimeout(self, timeout): + try: + self.__sock.settimeout(timeout) + except: + # Python 2.2 compatibility hacks. + pass + def __recvall(self, count): """__recvall(count) -> data Receive EXACTLY the number of bytes requested from the socket. @@ -561,11 +569,7 @@ def __recvall(self, count): timeout occurs. """ self.__sock.setblocking(1) - try: - self.__sock.settimeout(20) - except: - # Python 2.2 compatibility hacks. - pass + self.__settimeout(DEFAULT_TIMEOUT) data = self.recv(count) while len(data) < count: @@ -982,15 +986,18 @@ def __do_connect(self, addrspec): if ':' in addrspec[0]: self.__sock = _orgsocket(socket.AF_INET6, self.__type, self.__proto, *self.__args, **self.__kwargs) + self.__settimeout(DEFAULT_TIMEOUT) return self.__sock.connect(addrspec) else: try: self.__sock = _orgsocket(socket.AF_INET, self.__type, self.__proto, *self.__args, **self.__kwargs) + self.__settimeout(DEFAULT_TIMEOUT) return self.__sock.connect(addrspec) except socket.gaierror: self.__sock = _orgsocket(socket.AF_INET6, self.__type, self.__proto, *self.__args, **self.__kwargs) + self.__settimeout(DEFAULT_TIMEOUT) return self.__sock.connect(addrspec) def connect(self, destpair):