[PATCH] osmo-gsm-tester[master]: ms: Create an event server to handle Unix datagram messages

Holger Freyther gerrit-no-reply at lists.osmocom.org
Sun Feb 25 21:52:18 UTC 2018


Review at  https://gerrit.osmocom.org/6914

ms: Create an event server to handle Unix datagram messages

Create an EventServer that will create a unix domain socket and
dispatch incoming datagram messages. The lua remotes are not
passing credentials so this is a one way communication channel
for now. Tests can register to handle the message.

Change-Id: Ida97c570e8e741410f2dba4a231a8058ca96da25
---
A src/osmo_ms_driver/event_server.py
1 file changed, 33 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-gsm-tester refs/changes/14/6914/1

diff --git a/src/osmo_ms_driver/event_server.py b/src/osmo_ms_driver/event_server.py
new file mode 100644
index 0000000..6b0232b
--- /dev/null
+++ b/src/osmo_ms_driver/event_server.py
@@ -0,0 +1,33 @@
+
+from osmo_gsm_tester import log
+from functools import partial
+
+import time
+
+
+class EventServer(log.Origin):
+    """
+    Listen for AF_UNIX/SOCK_DGRAM messages from test apps and
+    forward them.
+    """
+    def __init__(self, name, path):
+        super().__init__(log.C_RUN, name)
+        self._path = path
+        self._handlers = []
+
+    def register(self, cb):
+        self._handlers.append(cb)
+
+    def server_path(self):
+        return self._path
+
+    def listen(self, loop):
+        self._server = loop.create_unix_server(self.read_cb, self._path)
+
+    def read_cb(self, obj, mask):
+        # addresss doesn't give us the remote but currently we don't
+        # need it.
+        (data, address) = self._server.recvfrom(4096)
+        now = time.clock_gettime(time.CLOCK_MONOTONIC)
+        for handler in self._handlers:
+            handler(data, now)

-- 
To view, visit https://gerrit.osmocom.org/6914
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ida97c570e8e741410f2dba4a231a8058ca96da25
Gerrit-PatchSet: 1
Gerrit-Project: osmo-gsm-tester
Gerrit-Branch: master
Gerrit-Owner: Holger Freyther <holger at freyther.de>


More information about the gerrit-log mailing list