Show More
@@ -25,6 +25,7 b' import tempfile' | |||
|
25 | 25 | import traceback |
|
26 | 26 | import threading |
|
27 | 27 | import socket |
|
28 | import random | |
|
28 | 29 | |
|
29 | 30 | from BaseHTTPServer import BaseHTTPRequestHandler |
|
30 | 31 | from SocketServer import TCPServer |
@@ -156,13 +157,19 b' class HttpHooksCallbackDaemon(ThreadedHo' | |||
|
156 | 157 | def get_hostname(self): |
|
157 | 158 | return socket.gethostname() or '127.0.0.1' |
|
158 | 159 | |
|
159 | def get_available_port(self): | |
|
160 |
|
|
|
161 |
|
|
|
162 | port = mysocket.getsockname()[1] | |
|
163 | mysocket.close() | |
|
164 | del mysocket | |
|
165 | return port | |
|
160 | def get_available_port(self, min_port=20000, max_port=65535): | |
|
161 | sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
|
162 | hostname = self.get_hostname() | |
|
163 | ||
|
164 | for _ in range(min_port, max_port): | |
|
165 | pick_port = random.randint(min_port, max_port) | |
|
166 | try: | |
|
167 | sock.bind((hostname, pick_port)) | |
|
168 | sock.close() | |
|
169 | del sock | |
|
170 | return pick_port | |
|
171 | except OSError: | |
|
172 | pass | |
|
166 | 173 | |
|
167 | 174 | def _prepare(self, txn_id=None, host=None, port=None): |
|
168 | 175 | if not host or host == "*": |
General Comments 0
You need to be logged in to leave comments.
Login now