Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cffi_builder_posix.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
...;
};

PosixMqResult posixmq_open(const char * const name, int * const mq,
PosixMqResult posixmq_open(const char * const name, int oflag, int * const mq,
const size_t maxmsgsize, const size_t maxsize);

PosixMqResult posixmq_close(const int mq);
Expand Down
4 changes: 2 additions & 2 deletions ipcqueue/posixmq.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ static void inline timeout_to_timespec(const double timeout,
}
}

PosixMqResult posixmq_open(const char * const name, int * const mq,
PosixMqResult posixmq_open(const char * const name, int oflag, int * const mq,
const size_t maxmsgsize, const size_t maxsize) {
struct mq_attr attrs = {.mq_maxmsg = maxsize, .mq_msgsize = maxmsgsize};

mqd_t mqdes = mq_open(name, O_CREAT | O_RDWR, 0644, &attrs);
mqd_t mqdes = mq_open(name, O_CREAT | oflag, 0644, &attrs);

if (mqdes < 0) {
switch (errno) {
Expand Down
2 changes: 1 addition & 1 deletion ipcqueue/posixmq.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ typedef enum {
POSIXMQ_E_DOESNT_EXIST
} PosixMqResult;

PosixMqResult posixmq_open(const char * const name, int * const mq,
PosixMqResult posixmq_open(const char * const name, int oflag, int * const mq,
const size_t maxmsgsize, const size_t maxsize);

PosixMqResult posixmq_close(const int mq);
Expand Down
9 changes: 6 additions & 3 deletions ipcqueue/posixmq.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Interprocess POSIX message queue implementation.
"""
import os

from .serializers import PickleSerializer

Expand Down Expand Up @@ -73,18 +74,20 @@ class Queue(object):
POSIX message queue.
"""

def __init__(self, name, maxsize=10, maxmsgsize=1024, serializer=PickleSerializer):
def __init__(self, name, oflag=os.O_RDWR, maxsize=10, maxmsgsize=1024, serializer=PickleSerializer):
"""
Constructor for message queue. *name* is an unique identifier of the
queue, must starts with ``/``. *maxsize* is an integer that sets
queue, must starts with ``/``. *oflag* should be the read/write mode,
defaults to `os.O_RDWR`. *maxsize* is an integer that sets
the upperbound limit on the number of items that can be placed in
the queue (maximum value depends on system limit). *maxmsgsize*
is a maximum size of the message in bytes (maximum value depends
on hard system limit).
"""
queue_name = ffi.new('char[]', name.encode('utf-8'))
queue_id = ffi.new('int *')
res = lib.posixmq_open(queue_name, queue_id, maxmsgsize, maxsize)
#queue_oflag = ffi.new('int', oflag)
res = lib.posixmq_open(queue_name, oflag, queue_id, maxmsgsize, maxsize)
if res != lib.POSIXMQ_OK:
raise QueueError(res)
self._queue_id = queue_id[0]
Expand Down