aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVadim Yanitskiy <axilirator@gmail.com>2018-09-30 15:23:12 +0700
committerVadim Yanitskiy <axilirator@gmail.com>2018-09-30 15:23:12 +0700
commit1e3f0aaf6bf237a8ef6d4a5b99d5c8b36755dab4 (patch)
treea8896c33a8d6a15f04c37108c9e83060c7d13afe
parentc43f321e6e586a371e547ec23e77ddf0cdb8f3d2 (diff)
mncc_sock.py: throw / raise exceptions from MnccSocket
Calling sys.exit() from MnccSocket's constructor could lead to a situation when the main thread becomes "dead", while its child threads are still working. Let's throw the exceptions towards the caller, so it would be possible to handle them there. Change-Id: I485eb86c69e74693eeae89723de27e376585f1da
-rw-r--r--mncc_sock.py16
1 files changed, 4 insertions, 12 deletions
diff --git a/mncc_sock.py b/mncc_sock.py
index e71a39a..0a64a81 100644
--- a/mncc_sock.py
+++ b/mncc_sock.py
@@ -10,7 +10,6 @@
# option, any later version.
import socket
-import sys
import os
import mncc
import ctypes
@@ -122,11 +121,7 @@ class MnccSocket(MnccSocketBase):
super(MnccSocketBase, self).__init__()
self.sock = socket.socket(socket.AF_UNIX, socket.SOCK_SEQPACKET)
print('connecting to %s' % address)
- try:
- self.sock.connect(address)
- except socket.error as errmsg:
- sys.stderr.write("%s\n" % errmsg)
- sys.exit(1)
+ self.sock.connect(address)
# Check the HELLO message
self.check_hello()
@@ -137,15 +132,13 @@ class MnccSocket(MnccSocketBase):
# Match expected message type
if msg.msg_type != mncc.MNCC_SOCKET_HELLO:
- sys.stderr.write('Received an unknown (!= MNCC_SOCKET_HELLO) '
+ raise AssertionError('Received an unknown (!= MNCC_SOCKET_HELLO) '
'message: %s\n' % msg)
- sys.exit(1)
# Match expected protocol version
if msg.version != mncc.MNCC_SOCK_VERSION:
- sys.stderr.write('MNCC protocol version mismatch '
+ raise AssertionError('MNCC protocol version mismatch '
'(0x%04x vs 0x%04x)\n' % (msg.version, mncc.MNCC_SOCK_VERSION))
- sys.exit(1)
# Match expected message sizes / offsets
if (msg.mncc_size != ctypes.sizeof(mncc.gsm_mncc) or
@@ -154,8 +147,7 @@ class MnccSocket(MnccSocketBase):
msg.signal_offset != mncc.gsm_mncc.signal.offset or
msg.emergency_offset != mncc.gsm_mncc.emergency.offset or
msg.lchan_type_offset != mncc.gsm_mncc.lchan_type.offset):
- sys.stderr.write('MNCC message alignment mismatch\n')
- sys.exit(1)
+ raise AssertionError('MNCC message alignment mismatch\n')
print('Received %s' % msg)