Skip to content
This repository was archived by the owner on Aug 28, 2020. It is now read-only.

Commit a4f9507

Browse files
committed
split connecting to the server and listening to new connections into 2 methods
1 parent e88b7a0 commit a4f9507

File tree

3 files changed

+23
-13
lines changed

3 files changed

+23
-13
lines changed

pugdebug/debugger.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,12 +159,10 @@ def has_pending_connections(self):
159159
"""
160160
return len(self.connections) > 0
161161

162-
def start_debug(self):
163-
"""Start a debugging session
164-
165-
If the server is not connected, connect it.
162+
def start_listening(self):
163+
"""Start listening to new connections
166164
"""
167-
self.server.connect()
165+
self.server.start_listening()
168166

169167
def handle_server_connected(self, connection):
170168
"""Handle when the server establishes a new connection

pugdebug/pugdebug.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ def start_listening(self):
467467

468468
self.document_viewer.remove_line_highlights()
469469

470-
self.debugger.start_debug()
470+
self.debugger.start_listening()
471471
self.main_window.set_debugging_status(1)
472472

473473
def handle_debugging_started(self):

pugdebug/server.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,29 +36,41 @@ def __init__(self):
3636
def run(self):
3737
self.mutex.lock()
3838

39-
self.__connect()
39+
socket_server = self.__connect()
40+
41+
if socket_server is not None:
42+
self.__listen(socket_server)
4043

4144
self.mutex.unlock()
4245

43-
def connect(self):
46+
def start_listening(self):
4447
self.wait_for_accept = True
4548
self.start()
4649

4750
def stop(self):
4851
self.wait_for_accept = False
4952

5053
def __connect(self):
51-
"""Connect to the server and listen to new incomming connections
54+
"""Connect to the socket server
55+
"""
56+
try:
57+
socket_server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
58+
socket_server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
59+
socket_server.settimeout(1)
60+
except OSError as e:
61+
socket_server = None
62+
self.server_error_signal.emit(e.strerror)
63+
64+
return socket_server
65+
66+
def __listen(self, socket_server):
67+
"""Listen to new incomming connections
5268
5369
For every accepted connection, see if it is valid and emit a signal
5470
with that new connection.
5571
5672
Otherwise silently disregard that connection.
5773
"""
58-
socket_server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
59-
socket_server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
60-
socket_server.settimeout(1)
61-
6274
host = get_setting('debugger/host')
6375
port_number = int(get_setting('debugger/port_number'))
6476

0 commit comments

Comments
 (0)