PosixChannels.jl
Documentation for PosixChannels.jl
PosixChannels — ModulePosixChannels provides an AbstractChannel-compatible channel using POSIX message queues.
The high level API is available through PosixChannel.
For more informations on POSIX message queues, see man 7 mq_overview.
Table of contents
Public API
PosixChannel
PosixChannels.PosixChannel — TypeAn impementation of AbstractChannel that uses POSIX message queues.
PosixChannels.PosixChannel — MethodPosixChannel{T}(name, kwargs...)Create a PosixChannel that works with messages of type T.
Notes: T must be a plain data type (isbitstype must return true), and the message queue must allow for messages of at least sizeof(T).
Extended help
Arguments
See man 3 mq_open for details.
All usages
mode::Symbol=:rw: the opening mode of the POSIX queue, can be:r,:w, or:rw.cloexec::Bool=false: Activate theO_CLOEXECflag.create::Bool=true: Activate theO_CREATflag.excl::Bool=false: Activate theO_CREATflag.nonblock::Bool=false: Activate theO_NONBLOCKflag.
Creation specifics
When creating a new queue (flag O_CREAT activated), it is necessary to provide additional informations.
create_r_user::Bool=true: Make queue readable for user.create_w_user::Bool=true: Make queue writable for user.create_r_group::Bool=true: Make queue readable for the group of the user.create_w_group::Bool=true: Make queue writable for the group of the user.create_r_other::Bool=false: Make queue readable for other users.create_w_other::Bool=false: Make queue writable for other users.create_len::Int=systemmsgdefault(): Maximum number of messages in the queue.create_msg_size::Int=sizeof(T): Maximum size of a message.
Examples
Start two julia REPL (a sender and a receiver).
sender.jl:
using PosixChannels
chan = PosixChannel{Int}("posix_channels_are_fun", mode=:w)
print("Press [Enter] when you are ready to send data.")
readline()
for i in 1:10
put!(chan, i)
end
println("Done!")
println("Closing the channel.")
close(chan)
receiver.jl
using PosixChannels
chan = PosixChannel{Int}("posix_channels_are_fun", mode=:r)
println("Listening for 10 incoming Int, you may start sending")
for _ in 1:10
while !isready(chan)
wait(chan)
end
msg = take!(chan)
println("Received $msg")
end
println("Done!")
println("Closing the channel.")
close(chan)
println("Deleting the channel.")
unlink(chan)You can then launch each script, and press return in the sender's window.
$ julia --project sender.jl
Press [Enter] when you are ready to send data.
Done!
Closing the channel.$ julia --project receiver.jl
Listening for 10 incoming Int, you may start sending
Received 1
Received 2
Received 3
Received 4
Received 5
Received 6
Received 7
Received 8
Received 9
Received 10
Done!
Closing the channel.
Deleting the channel.This example uses integers, but any type that verifies isbitstype could be used. See StaticStrings for example.
See also wait, put!, take!, unlink, isnonblocking.
PosixChannels.unlink — Functionunlink(chan)POSIX messages queues are persistent. This allows destroying a queue.
PosixChannels.isnonblocking — FunctionBase.length — MethodBase.close — MethodAbstractChannel interface
Base.put! — Functionput!(chan::PosixChannel, v[, prio=0])Add a message to a PosixChannel, with priority prio.
See man 3 mq_send for details.
See also send_posix_mqueue.
Base.take! — Methodtake!(chan::PosixChannel [, prio])Take a message from a PosixChannel. If a priority is set, the oldest message with priority prio is taken.
See man 3 mq_receive for details.
See also receive_posix_mqueue.
Base.isready — MethodBase.fetch — MethodYou cannot fetch from a PosixChannel.
Base.wait — Method/proc utilities
The system-wide defaults for POSIX message queues can be set through a /proc interface. See man 7 mq_overview for details.
PosixChannels.systemmsgdefault — Functionsystemmsgdefault()Return the system's default number of messages in a message queue.
See also systemmsgdefault!.
PosixChannels.systemmsgdefault! — Functionsystemmsgdefault!(val)Set the system's default number of messages in a message queue.
Root privileges are likely needed.
See also systemmsgdefault.
PosixChannels.systemmsgmax — FunctionPosixChannels.systemmsgmax! — Functionsystemmsgmax!(val)Set the system's max number of messages in a message queue.
Root privileges are likely needed.
See also systemmsgmax.
PosixChannels.systemmsgsizedefault — Functionsystemmsgsizedefault()Return the system's default size of messages in a message queue.
See also systemmsgdefault!.
PosixChannels.systemmsgsizedefault! — Functionsystemmsgsizedefault!(val)Set the system's default size of messages in a message queue.
Root privileges are likely needed.
See also systemmsgsizedefault.
PosixChannels.systemmsgsizemax — Functionsystemmsgsizemax()Return the system's max size of messages in a message queue.
See also systemmsgsizemax!.
PosixChannels.systemmsgsizemax! — Functionsystemmsgsizemax!(val)Set the system's max size of messages in a message queue.
Root privileges are likely needed.
See also systemmsgsizemax.
PosixChannels.systemqueuesmax — FunctionPosixChannels.systemqueuesmax! — Functionsystemqueuesmax!(val)Set the system's max number of message queue.
Root privileges are likely needed.
See also systemqueuesmax.
Internal API
PosixChannels.correct_name — Functioncorrect_name(name)Prepend the string name with a "/" if it does not start with "/".
PosixChannels.mq_attr — TypeMirror of the mq_attr structure used in C to configure a message queue.
See also open_posix_mqueue, getattr_posix_mqueue.
PosixChannels.open_posix_mqueue — Functionopen_posix_mqueue(name, flags[, perm, attr])Call the C function mq_open with the given name and flags. Checks for errors using Base.systemerror. name is corrected using correct_name.
When O_CREAT flag is on, perm and attr are required.
See man 3 mq_open for details.
See also close_posix_mqueue.
open_posix_mqueue(name; kwargs...)Call mq_open by explicitely constructing the various flags beforehand.
Arguments
See man 3 mq_open for details.
All usages
mode::Symbol=:rw: the opening mode of the POSIX queue, can be:r,:w, or:rw.cloexec::Bool=false: Activate theO_CLOEXECflag.create::Bool=true: Activate theO_CREATflag.excl::Bool=false: Activate theO_CREATflag.nonblock::Bool=false: Activate theO_NONBLOCKflag.
Creation specifics
When creating a new queue (flag O_CREAT activated), it is necessary to provide additional informations.
create_r_user::Bool=true: Make queue readable for user.create_w_user::Bool=true: Make queue writable for user.create_r_group::Bool=true: Make queue readable for the group of the user.create_w_group::Bool=true: Make queue writable for the group of the user.create_r_other::Bool=false: Make queue readable for other users.create_w_other::Bool=false: Make queue writable for other users.create_len::Int=systemmsgdefault(): Maximum number of messages in the queue.create_msg_size::Int=systemmsgsizedefault(): Maximum size of a message.
PosixChannels.close_posix_mqueue — Functionclose_posix_mqueue(key)Call the C function mq_close with the given key. Checks for errors using Base.systemerror.
See man 3 mq_close for details.
See also open_posix_mqueue, unlink_posix_mqueue.
PosixChannels.unlink_posix_mqueue — Functionunlink_posix_mqueue(name)Call the C function mq_close with the given name. Checks for errors using Base.systemerror.
See man 3 mq_unlink for details.
See also open_posix_mqueue, close_posix_mqueue.
PosixChannels.send_posix_mqueue — Functionsend_posix_mqueue(key, val, prio=0)
Call the C function `mq_send` with the given key, value, and priority. Checks for errors using [`Base.systemerror`](https://docs.julialang.org/en/v1/base/c/#Base.systemerror).See man 3 mq_send for details.
See also open_posix_mqueue, close_posix_mqueue, receive_posix_mqueue.
PosixChannels.receive_posix_mqueue — Functionreceive_posix_mqueue(key, type[, prio])Call the C function mq_receive with the given key, and priority. Checks for errors using Base.systemerror. An element of type type is retreived. If the priority is given, only messages with priority prio are fetched. Else, the oldest message is fetched.
See man 3 mq_receive for details.
See also open_posix_mqueue, close_posix_mqueue, send_posix_mqueue.
PosixChannels.getattr_posix_mqueue — Functiongetattr_posix_mqueue(key)Call the C function mq_getattr with the given key. Checks for errors using Base.systemerror.
See man 3 mq_getattr for details.
See also mq_attr.
PosixChannels.sigevent — TypeMirror of the sigevent structure used in C to configure signal events. See /usr/include/bits/types/sigevent_t.h.
See also notify_channel, register_notifier_cfunction.
PosixChannels.notify_channel — Functionnotify_channel(handle)Callback for the C function mq_notify. It only @ccall uv_async_send with the handle of the AsyncCondition from the channel.
See the manual for an explanation.
See also register_notifier_cfunction.
PosixChannels.register_notifier_cfunction — Functionregister_notifier_cfunction(chan)Call the C function mq_notify for the message queue. Checks for errors using Base.systemerror.
mq_notify is called with the SIGEV_THREAD flag and configured to call notify_channel with the channel's condition handle as a parameter. This is done so the OS will start a thread that will unlock the condition when a new message is posted to the empty queue. This function is used by wait before it starts waiting for the channel's condition.
See man 3 mq_notify for details.
See also notify_channel