Browse Source

_scan_tcp: Set the timeout *before* attempting to connect.

This prevents us from hanging forever if the connection cannot be established.
Cyril Roelandt 8 years ago
parent
commit
7790574d70
1 changed files with 1 additions and 1 deletions
  1. 1 1
      vpneverywhere/port_scanner.py

+ 1 - 1
vpneverywhere/port_scanner.py

@@ -92,8 +92,8 @@ class Scanner(object):
         """Return True if PORT is opened in TCP."""
         try:
             s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
-            s.connect((self.host, port))
             s.settimeout(TIMEOUT)
+            s.connect((self.host, port))
             s.send(b'x')
             s.recvfrom(1)
         except (ConnectionRefusedError, socket.timeout):