summaryrefslogtreecommitdiff
path: root/portato/ipc.pyx
diff options
context:
space:
mode:
authorRené 'Necoro' Neumann <necoro@necoro.net>2009-08-15 16:19:08 +0200
committerRené 'Necoro' Neumann <necoro@necoro.net>2009-08-15 16:19:08 +0200
commitb528cde68b09e037f3cb905b91cbbb168622d7dd (patch)
treee03466d4bdd3cc7366e793efeb863dd37dcbc458 /portato/ipc.pyx
parentedb012736afad95e069674fbe8ce9db192d39c25 (diff)
downloadportato-b528cde68b09e037f3cb905b91cbbb168622d7dd.tar.gz
portato-b528cde68b09e037f3cb905b91cbbb168622d7dd.tar.bz2
portato-b528cde68b09e037f3cb905b91cbbb168622d7dd.zip
Use boolean flags instead of obscure C flags for ipc.MessageQueue
Diffstat (limited to 'portato/ipc.pyx')
-rw-r--r--portato/ipc.pyx24
1 files changed, 12 insertions, 12 deletions
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: