aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/bus.py12
-rw-r--r--src/native_bus.pyx10
2 files changed, 17 insertions, 5 deletions
diff --git a/src/bus.py b/src/bus.py
index 4b3f9fd..7146e83 100644
--- a/src/bus.py
+++ b/src/bus.py
@@ -55,6 +55,12 @@ class Bus:
Fail if interrupted
'''
+ NOWAIT = 1
+ '''
+ Function shall fail with errno set to `EAGAIN`
+ if the it would block and this flag is used
+ '''
+
def __init__(self, pathname : str = None):
'''
@@ -131,14 +137,16 @@ class Bus:
self.bus = None
- def write(self, message : str):
+ def write(self, message : str, flags : int = 0):
'''
Broadcast a message a bus
@param message:str The message to write, may not be longer than 2047 bytes after UTF-8 encoding
+ @param flags:int `Bus.NOWAIT` if the function shall fail if there is another process attempting
+ to broadcast on the bus
'''
from native_bus import bus_write_wrapped
- if bus_write_wrapped(self.bus, message) == -1:
+ if bus_write_wrapped(self.bus, message, flags) == -1:
raise self.__oserror()
diff --git a/src/native_bus.pyx b/src/native_bus.pyx
index de33e91..fdcf341 100644
--- a/src/native_bus.pyx
+++ b/src/native_bus.pyx
@@ -68,13 +68,15 @@ Close a bus
@return 0 on success, -1 on error
'''
-cdef extern int bus_write(long, const char *)
+cdef extern int bus_write(long, const char *, int)
'''
Broadcast a message a bus
@param bus Bus information
@param message The message to write, may not be longer than
`BUS_MEMORY_SIZE` including the NUL-termination
+@param flags `BUS_NOWAIT` fail if other process is attempting
+ to write
@return 0 on success, -1 on error
'''
@@ -184,20 +186,22 @@ def bus_close_wrapped(bus : int) -> int:
return bus_close(<long>bus)
-def bus_write_wrapped(bus : int, message : str) -> int:
+def bus_write_wrapped(bus : int, message : str, flags : int) -> int:
'''
Broadcast a message a bus
@param bus Bus information
@param message The message to write, may not be longer than
`BUS_MEMORY_SIZE` including the NUL-termination
+ @param flags `BUS_NOWAIT` fail if other process is attempting
+ to write
@return 0 on success, -1 on error
'''
cdef const char* cmessage
cdef bytes bs
bs = message.encode('utf-8') + bytes([0])
cmessage = bs
- return bus_write(<long>bus, cmessage)
+ return bus_write(<long>bus, cmessage, <int>flags)
cdef int bus_callback_wrapper(const char *message, user_data):