diff options
author | René 'Necoro' Neumann <necoro@necoro.net> | 2009-08-15 16:19:08 +0200 |
---|---|---|
committer | René 'Necoro' Neumann <necoro@necoro.net> | 2009-08-15 16:19:08 +0200 |
commit | b528cde68b09e037f3cb905b91cbbb168622d7dd (patch) | |
tree | e03466d4bdd3cc7366e793efeb863dd37dcbc458 | |
parent | edb012736afad95e069674fbe8ce9db192d39c25 (diff) | |
download | portato-b528cde68b09e037f3cb905b91cbbb168622d7dd.tar.gz portato-b528cde68b09e037f3cb905b91cbbb168622d7dd.tar.bz2 portato-b528cde68b09e037f3cb905b91cbbb168622d7dd.zip |
Use boolean flags instead of obscure C flags for ipc.MessageQueue
-rw-r--r-- | portato/__init__.py | 2 | ||||
-rw-r--r-- | portato/ipc.pyx | 24 | ||||
-rw-r--r-- | test.py | 2 |
3 files changed, 15 insertions, 13 deletions
diff --git a/portato/__init__.py b/portato/__init__.py index 74145e7..7363429 100644 --- a/portato/__init__.py +++ b/portato/__init__.py @@ -91,7 +91,7 @@ def start(): from . import ipc - mq = ipc.MessageQueue(None, ipc.MessageQueue.CREAT | ipc.MessageQueue.EXCL) + mq = ipc.MessageQueue(None, create = True, exclusive = True) # start listener lt = threading.Thread(target=get_listener().set_recv, args = (mq,)) diff --git a/portato/ipc.pyx b/portato/ipc.pyx index 13743bc..f3fb4af 100644 --- a/portato/ipc.pyx +++ b/portato/ipc.pyx @@ -27,13 +27,10 @@ cdef class MessageQueue (object): A simple interface to the SysV message queues. """ - CREAT = IPC_CREAT - EXCL = IPC_EXCL - cdef int msgid cdef readonly key_t key - def __init__ (self, key = None, int flags = 0): + def __init__ (self, key = None, create = False, exclusive = False): """ Create a new MessageQueue instance. Depending on the passed in flags, different behavior occurs. See man msgget for the details. @@ -41,17 +38,20 @@ cdef class MessageQueue (object): If key is None, a random key is created. """ - if (flags & IPC_EXCL) and not (flags & IPC_CREAT): - raise ValueError("EXCL must be combined with CREAT.") + cdef int flags = 0600 # start mode - if key is None and not (flags & IPC_EXCL): - raise ValueError("The key can only be None if EXCL is set.") + if exclusive and not create: + raise ValueError("'exclusive' must be combined with 'create'.") - # make sure there is nothing ... obscure - flags &= (IPC_CREAT | IPC_EXCL) + if key is None and not exclusive: + raise ValueError("The key can only be None if 'exclusive' is set.") - flags |= 0600 # mode + if create: + flags |= IPC_CREAT + if exclusive: + flags |= IPC_EXCL + if key is None: check = True while check: @@ -68,7 +68,7 @@ cdef class MessageQueue (object): elif errno == EEXIST: raise MessageQueueError("Queue already exists.") elif errno == ENOENT: - raise MessageQueueError("Queue does not exist and CREAT is not set.") + raise MessageQueueError("Queue does not exist and 'create' is not set.") elif errno == ENOMEM or errno == ENOSPC: raise MemoryError("Insufficient ressources.") else: @@ -1,3 +1,5 @@ +from __future__ import with_statement + from portato import _sub_start _sub_start() |