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

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

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


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

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, 60 insertions(+), 0 deletions(-)


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

diff --git a/src/osmo_ms_driver/simple_loop.py b/src/osmo_ms_driver/simple_loop.py
new file mode 100644
index 0000000..65417a3
--- /dev/null
+++ b/src/osmo_ms_driver/simple_loop.py
@@ -0,0 +1,60 @@
+# 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
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# 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 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: newchange
Gerrit-Change-Id: Iea06f33870cab9f21e9a1a1feb9758467343dd29
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