]> www.average.org Git - loctrkd.git/blobdiff - gps303/termconfig.py
Multiprotocol support in zmq messages and storage
[loctrkd.git] / gps303 / termconfig.py
index 953e6aec75f67ae380732d7f80dcfcc4cfa845ed..6ec43fdc1c25f5063096121b459008d6fc3c5511 100644 (file)
@@ -19,9 +19,9 @@ def runserver(conf: ConfigParser) -> None:
     zsub = zctx.socket(zmq.SUB)  # type: ignore
     zsub.connect(conf.get("collector", "publishurl"))
     for proto in (
-        STATUS.PROTO,
-        SETUP.PROTO,
-        POSITION_UPLOAD_INTERVAL.PROTO,
+        proto_name(STATUS),
+        proto_name(SETUP),
+        proto_name(POSITION_UPLOAD_INTERVAL),
     ):
         zsub.setsockopt(zmq.SUBSCRIBE, topic(proto))
     zpush = zctx.socket(zmq.PUSH)  # type: ignore
@@ -44,8 +44,10 @@ def runserver(conf: ConfigParser) -> None:
                 )
             if zmsg.imei is not None and conf.has_section(zmsg.imei):
                 termconfig = common.normconf(conf[zmsg.imei])
-            else:
+            elif conf.has_section("termconfig"):
                 termconfig = common.normconf(conf["termconfig"])
+            else:
+                termconfig = {}
             kwargs = {}
             if isinstance(msg, STATUS):
                 kwargs = {
@@ -74,7 +76,9 @@ def runserver(conf: ConfigParser) -> None:
             zpush.send(resp.packed)
 
     except KeyboardInterrupt:
-        pass
+        zsub.close()
+        zpush.close()
+        zctx.destroy()  # type: ignore
 
 
 if __name__.endswith("__main__"):