Fix GSMTAP capture restart: recreate UDP socket on start after stop
GsmtapListener.stop() closed the UDP socket permanently, but start() only set _running=True without recreating it. Second capture session would silently spin on the dead socket (OSError → None → continue). - Add _closed flag to GsmtapReceiver, set in close() - Store bind_port in GsmtapListener for socket recreation - start() recreates GsmtapReceiver only if previous one was closed - Uses getattr for backward compat with test fakes
This commit is contained in:
1 parent
78c255464e
commit
7d8dca1ffd
2 files changed
+5
No files matched your search
@@ -79,6 +79,7 @@ class GsmtapReceiver:
|
||||
self._sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||
self._sock.bind((bind_ip, bind_port))
|
||||
self._sock.settimeout(1.0)
|
||||
self._closed = False
|
||||
|
||||
def read_packet(self):
|
||||
"""Block until a GSMTAP-SIM packet arrives.
|
||||
@@ -109,3 +110,4 @@ class GsmtapReceiver:
|
||||
|
||||
def close(self):
|
||||
self._sock.close()
|
||||
self._closed = True
|
||||
@@ -34,11 +34,14 @@ def gsmtap_msg_type(sub_type):
|
||||
|
||||
class GsmtapListener:
|
||||
def __init__(self, bind_port=4729):
|
||||
self._bind_port = bind_port
|
||||
self._receiver = GsmtapReceiver(bind_port=bind_port)
|
||||
self._running = False
|
||||
self._dropped = 0
|
||||
|
||||
def start(self):
|
||||
if getattr(self._receiver, '_closed', False):
|
||||
self._receiver = GsmtapReceiver(bind_port=self._bind_port)
|
||||
self._running = True
|
||||
self._dropped = 0
|
||||
|
||||
|
||||
Reference in new issue
Block a user