chickadee » posix-mq

posix-mq

POSIX Message Queues API.

Documentation

The posix-mq library allows the creation and access of POSIX shared memory objects. POSIX message queues allow for priority-driven IPC mechanism with multiple readers and writers.

posix-mq?procedure

#t if the current platform supports POSIX message queues, #f otherwise.

mq-create:procedure

mq-create is a wrapper around mq_open, which opens message queue referred to by name, and returns a message-queue descriptor by which the queue can be referenced in the future.

Argument PATH specifies the shared memory object to be created or opened. For portable use, name should have an initial slash (/) and contain no embedded slashes.

OFLAGS is a list of bit masks from the chicken file posix module which will be ORed together and passed to shm_open. It must contains exactly one of open/rdonly or open/rdwr and any of the other flags listed here:

open/excl
If open/create was also specified, and a message queue with the given name already exists, returns an error.
open/nonblock
open the message queue in nonblocking mode. In circumstances where mq_receive and mq_send would normally block, these functions instead fail with the error EAGAIN.

On successful completion mq-crate returns a new file descriptor referring to the message queue object.

mq-unlink removes a memory queue name, and, once all processes have unmapped the object, de-allocates and destroys the contents of the associated memory region.

mq-send:procedure

Sends a message to a message queue. MSG can currently only be a byte blob.

mq-recv:procedure

Receives a message from a message queue. Returns a byte blob containing the message.

Examples

(print posix-mq?)
(let* ((str "Hello, world!")
       (path (sprintf "/mqtest~A" (pseudo-random-integer 100)))
       (fd (mq-create path  10 1000 oflags: (list open/rdwr)))
       (msg (string->blob str)))
    (print "sending " msg)
    (mq-send path msg)
    (print "received " (mq-recv path))
    (mq-unlink path)
  )

Author

Ivan Raikov

Repository

https://github.com/iraikov/chicken-posix-mq

Version history

1.0
Initial release

License

Copyright 2021 Ivan Raikov

 
 Redistribution and use in source and binary forms, with or without
 modification, are permitted provided that the following conditions are
 met:
 
 Redistributions of source code must retain the above copyright
 notice, this list of conditions and the following disclaimer.
 
 Redistributions in binary form must reproduce the above copyright
 notice, this list of conditions and the following disclaimer in the
 documentation and/or other materials provided with the distribution.
 
 Neither the name of the author nor the names of its contributors may
 be used to endorse or promote products derived from this software
 without specific prior written permission.
 
 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
 FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 OF THE POSSIBILITY OF SUCH DAMAGE.

Contents »