[PATCH] osmo-gsm-tester[master]: ms: Create a simple epoll (or kqueue) based event loop

Holger Freyther gerrit-no-reply at lists.osmocom.org
Wed Feb 28 22:12:32 UTC 2018

Hello Pau Espin Pedrol, Jenkins Builder,

I'd like you to reexamine a change.  Please visit


to look at the new patch set (#4).

ms: Create a simple epoll (or kqueue) based event loop

Create a C-like single process event loop. It could be powered by
select/epoll or kqueue. It should scale to many open fds but we
will not have that many.

Change-Id: Iea06f33870cab9f21e9a1a1feb9758467343dd29
A src/osmo_ms_driver/simple_loop.py
1 file changed, 63 insertions(+), 0 deletions(-)

  git pull ssh://gerrit.osmocom.org:29418/osmo-gsm-tester refs/changes/13/6913/4

diff --git a/src/osmo_ms_driver/simple_loop.py b/src/osmo_ms_driver/simple_loop.py
new file mode 100644
index 0000000..f4b3e05
--- /dev/null
+++ b/src/osmo_ms_driver/simple_loop.py
@@ -0,0 +1,63 @@
+# osmo_ms_driver: Event loop because asyncio is not up to the job
+# Copyright (C) 2018 by Holger Hans Peter Freyther
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# GNU General Public License for more details.
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+from osmo_gsm_tester import log
+from functools import partial
+import os
+import selectors
+import socket
+class SimpleLoop(log.Origin):
+    def __init__(self):
+        super().__init__(log.C_RUN, "SimpleLoop")
+        self._loop = selectors.DefaultSelector()
+        self._timeout = None
+    def register_fd(self, fd, event, callback):
+        self._loop.register(fd, event, callback)
+    def schedule_timeout(self, timeout):
+        assert self._timeout == None
+        self._timeout = timeout
+    def create_unix_server(self, cb, path):
+        sock = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
+        if len(path.encode()) > 107:
+            raise log.Error('Path for unix socket is longer than max allowed len for unix socket path (107):', path)
+        # If not a special Linux namespace...
+        if path[0] != '\0':
+            try:
+                os.unlink(path)
+            except FileNotFoundError:
+                pass
+        # Now bind+listen+NONBLOCK
+        sock.bind(path)
+        sock.setblocking(False)
+        self.register_fd(sock.fileno(), selectors.EVENT_READ, cb)
+        return sock
+    def select(self):
+        events = self._loop.select(timeout=self._timeout)
+        self._timeout = None
+        for key, mask in events:
+            key.data(key.fileobj, mask)

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

Gerrit-MessageType: newpatchset
Gerrit-Change-Id: Iea06f33870cab9f21e9a1a1feb9758467343dd29
Gerrit-PatchSet: 4
Gerrit-Project: osmo-gsm-tester
Gerrit-Branch: master
Gerrit-Owner: Holger Freyther <holger at freyther.de>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Holger Freyther <holger at freyther.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Pau Espin Pedrol <pespin at sysmocom.de>
Gerrit-Reviewer: neels <nhofmeyr at sysmocom.de>

More information about the gerrit-log mailing list