[MERGED] openbsc[master]: bsc_control.py: fix blocking

Harald Welte gerrit-no-reply at lists.osmocom.org
Mon Jan 23 12:31:45 UTC 2017


Harald Welte has submitted this change and it was merged.

Change subject: bsc_control.py: fix blocking
......................................................................


bsc_control.py: fix blocking

Previously reading from socket would block if no data were sent by
the server. Use non-blocking read for set and get operations.

Change-Id: I706d54a4a7ceef62683bf9a2fe63fc9ab331c24e
---
M openbsc/contrib/bsc_control.py
1 file changed, 11 insertions(+), 5 deletions(-)

Approvals:
  Harald Welte: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/openbsc/contrib/bsc_control.py b/openbsc/contrib/bsc_control.py
index 66a41eb..3a7964d 100755
--- a/openbsc/contrib/bsc_control.py
+++ b/openbsc/contrib/bsc_control.py
@@ -30,8 +30,14 @@
         (_, _, v) = do_set_get(sck, var)
         return v
 
-def _leftovers(sck):
-        data = sck.recv(1024)
+def _leftovers(sck, fl):
+        """
+        Read outstanding data if any according to flags
+        """
+        try:
+                data = sck.recv(1024, fl)
+        except socket.error as (s_errno, strerror):
+                return False
         if len(data) != 0:
                 tail = data
                 while True:
@@ -75,19 +81,19 @@
         if options.cmd_set:
                 if len(args) < 2:
                         parser.error("Set requires var and value arguments")
-                _leftovers(sock)
+                _leftovers(sock, socket.MSG_DONTWAIT)
                 print "Got message:", set_var(sock, args[0], ' '.join(args[1:]))
 
         if options.cmd_get:
                 if len(args) != 1:
                         parser.error("Get requires the var argument")
-                _leftovers(sock)
+                _leftovers(sock, socket.MSG_DONTWAIT)
                 (a, _, _) = do_set_get(sock, args[0])
                 print "Got message:", a
 
         if options.monitor:
                 while True:
-                        if not _leftovers(sock):
+                        if not _leftovers(sock, 0):
                                 print "Connection is gone."
                                 break
         sock.close()

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I706d54a4a7ceef62683bf9a2fe63fc9ab331c24e
Gerrit-PatchSet: 2
Gerrit-Project: openbsc
Gerrit-Branch: master
Gerrit-Owner: Max <msuraev at sysmocom.de>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Jenkins Builder


More information about the gerrit-log mailing list