Xenomai API
2.6.5
|
Files | |
file | pipe.c |
This file is part of the Xenomai project. | |
Functions | |
int | rt_pipe_create (RT_PIPE *pipe, const char *name, int minor, size_t poolsize) |
Create a message pipe. More... | |
int | rt_pipe_delete (RT_PIPE *pipe) |
Delete a message pipe. More... | |
ssize_t | rt_pipe_receive (RT_PIPE *pipe, RT_PIPE_MSG **msgp, RTIME timeout) |
Receive a message from a pipe. More... | |
ssize_t | rt_pipe_read (RT_PIPE *pipe, void *buf, size_t size, RTIME timeout) |
Read a message from a pipe. More... | |
ssize_t | rt_pipe_send (RT_PIPE *pipe, RT_PIPE_MSG *msg, size_t size, int mode) |
Send a message through a pipe. More... | |
ssize_t | rt_pipe_write (RT_PIPE *pipe, const void *buf, size_t size, int mode) |
Write a message to a pipe. More... | |
ssize_t | rt_pipe_stream (RT_PIPE *pipe, const void *buf, size_t size) |
Stream bytes to a pipe. More... | |
RT_PIPE_MSG * | rt_pipe_alloc (RT_PIPE *pipe, size_t size) |
Allocate a message pipe buffer. More... | |
int | rt_pipe_free (RT_PIPE *pipe, RT_PIPE_MSG *msg) |
Free a message pipe buffer. More... | |
int | rt_pipe_flush (RT_PIPE *pipe, int mode) |
Flush the i/o queues associated with the kernel endpoint of a message pipe. More... | |
int | rt_pipe_monitor (RT_PIPE *pipe, int(*fn)(RT_PIPE *pipe, int event, long arg)) |
Monitor a message pipe asynchronously. More... | |
Message pipe services.
A message pipe is a two-way communication channel between Xenomai tasks and standard Linux processes using regular file I/O operations on a pseudo-device. Pipes can be operated in a message-oriented fashion so that message boundaries are preserved, and also in byte streaming mode from real-time to standard Linux processes for optimal throughput.
Xenomai tasks open their side of the pipe using the rt_pipe_create() service; standard Linux processes do the same by opening one of the /dev/rtpN special devices, where N is the minor number agreed upon between both ends of each pipe. Additionally, named pipes are available through the registry support, which automatically creates a symbolic link from entries under /proc/xenomai/registry/native/pipes/ to the corresponding special device file.
RT_PIPE_MSG* rt_pipe_alloc | ( | RT_PIPE * | pipe, |
size_t | size | ||
) |
Allocate a message pipe buffer.
This service allocates a message buffer from the pipe's heap which can be subsequently filled by the caller then passed to rt_pipe_send() for sending. The beginning of the available data area of size contiguous bytes is accessible from P_MSGPTR(msg).
pipe | The descriptor address of the affected pipe. |
size | The requested size in bytes of the buffer. This value should represent the size of the payload data. |
Environments:
This service can be called from:
Rescheduling: never.
References xnheap_alloc().
Referenced by rt_pipe_write().
int rt_pipe_create | ( | RT_PIPE * | pipe, |
const char * | name, | ||
int | minor, | ||
size_t | poolsize | ||
) |
Create a message pipe.
This service opens a bi-directional communication channel allowing data exchange between Xenomai tasks and standard Linux processes. Pipes natively preserve message boundaries, but can also be used in byte stream mode from Xenomai tasks to standard Linux processes.
rt_pipe_create() always returns immediately, even if no Linux process has opened the associated special device file yet. On the contrary, the non real-time side could block upon attempt to open the special device file until rt_pipe_create() is issued on the same pipe from a Xenomai task, unless O_NONBLOCK has been specified to the open(2) system call.
pipe | The address of a pipe descriptor Xenomai will use to store the pipe-related data. This descriptor must always be valid while the pipe is active therefore it must be allocated in permanent memory. |
name | An ASCII string standing for the symbolic name of the message pipe. When non-NULL and non-empty, this string is copied to a safe place into the descriptor, and passed to the registry package if enabled for indexing the created pipe. |
Named pipes are supported through the use of the registry. When the registry support is enabled, passing a valid name parameter when creating a message pipe subsequently allows standard Linux processes to follow a symbolic link from /proc/xenomai/registry/pipes/name in order to reach the associated special device (i.e. /dev/rtp*), so that the specific minor information does not need to be known from those processes for opening the proper device file. In such a case, both sides of the pipe only need to agree upon a symbolic name to refer to the same data path, which is especially useful whenever the minor number is picked up dynamically using an adaptive algorithm, such as passing P_MINOR_AUTO as minor value.
minor | The minor number of the device associated with the pipe. Passing P_MINOR_AUTO causes the minor number to be auto-allocated. In such a case, the name parameter must be valid so that user-space processes may subsequently follow the symbolic link that will be automatically created from /proc/xenomai/registry/pipes/name to the allocated pipe device entry (i.e. /dev/rtp*). |
poolsize | Specifies the size of a dedicated buffer pool for the pipe. Passing 0 means that all message allocations for this pipe are performed on the system heap. |
Environments:
This service can be called from:
Rescheduling: possible.
References rt_pipe_delete(), xnheap_alloc(), xnheap_init(), xnheap_set_label(), and xnregistry_enter().
int rt_pipe_delete | ( | RT_PIPE * | pipe | ) |
Delete a message pipe.
This service deletes a pipe previously created by rt_pipe_create(). Data pending for transmission to non real-time processes are lost.
pipe | The descriptor address of the affected pipe. |
Environments:
This service can be called from:
Rescheduling: possible.
References xnregistry_remove().
Referenced by rt_pipe_create().
int rt_pipe_flush | ( | RT_PIPE * | pipe, |
int | mode | ||
) |
Flush the i/o queues associated with the kernel endpoint of a message pipe.
This service flushes all data pending for consumption by the remote side in user-space for the given message pipe. Upon success, no data remains to be read from the remote side of the connection.
pipe | The descriptor address of the pipe to flush. |
mode | A mask indicating which queues need to be flushed; the following flags may be combined in a single flush request: |
Environments:
This service can be called from:
Rescheduling: never.
int rt_pipe_free | ( | RT_PIPE * | pipe, |
RT_PIPE_MSG * | msg | ||
) |
Free a message pipe buffer.
This service releases a message buffer returned by rt_pipe_receive() to the pipe's heap.
pipe | The descriptor address of the affected pipe. |
msg | The address of the message buffer to free. |
Environments:
This service can be called from:
Rescheduling: never.
References xnheap_free().
Referenced by rt_pipe_read(), and rt_pipe_write().
int rt_pipe_monitor | ( | RT_PIPE * | pipe, |
int(*)(RT_PIPE *pipe, int event, long arg) | fn | ||
) |
Monitor a message pipe asynchronously.
This service registers a notifier callback that will be called upon specific events occurring on the channel. rt_pipe_monitor() is particularly useful to monitor a channel asynchronously while performing other tasks.
pipe | The descriptor address of the pipe to monitor. |
fn | The notification handler. This user-provided routine will be passed the address of the message pipe descriptor receiving the event, the event code, and an optional argument. Four events are currently defined: |
The P_EVENT_INPUT and P_EVENT_OUTPUT events are fired on behalf of a fully atomic context; therefore, care must be taken to keep their overhead low. In those cases, the Xenomai services that may be called from the handler are restricted to the set allowed to a real-time interrupt handler.
Environments:
This service can be called from:
Rescheduling: never.
ssize_t rt_pipe_read | ( | RT_PIPE * | pipe, |
void * | buf, | ||
size_t | size, | ||
RTIME | timeout | ||
) |
Read a message from a pipe.
This service retrieves the next message written to the associated special device in user-space. rt_pipe_read() always preserves message boundaries, which means that all data sent through the same write(2) operation to the special device will be gathered in a single message by this service. This services differs from rt_pipe_receive() in that it copies back the payload data to a user-defined memory area, instead of returning a pointer to the internal message buffer holding such data.
Unless otherwise specified, the caller is blocked for a given amount of time if no data is immediately available on entry.
pipe | The descriptor address of the pipe to read from. |
buf | A pointer to a memory location which will be written upon success with the read message contents. |
size | The count of bytes from the received message to read up into buf. If size is lower than the actual message size, -ENOBUFS is returned since the incompletely received message would be lost. If size is zero, this call returns immediately with no other action. |
timeout | The number of clock ticks to wait for some message to arrive (see note). Passing TM_INFINITE causes the caller to block indefinitely until some data is eventually available. Passing TM_NONBLOCK causes the service to return immediately without waiting if no data is available on entry. |
Environments:
This service can be called from:
Rescheduling: always unless the request is immediately satisfied or timeout specifies a non-blocking operation.
References rt_pipe_free(), and rt_pipe_receive().
ssize_t rt_pipe_receive | ( | RT_PIPE * | pipe, |
RT_PIPE_MSG ** | msgp, | ||
RTIME | timeout | ||
) |
Receive a message from a pipe.
This service retrieves the next message written to the associated special device in user-space. rt_pipe_receive() always preserves message boundaries, which means that all data sent through the same write(2) operation to the special device will be gathered in a single message by this service. This service differs from rt_pipe_read() in that it returns a pointer to the internal buffer holding the message, which improves performances by saving a data copy to a user-provided buffer, especially when large messages are involved.
Unless otherwise specified, the caller is blocked for a given amount of time if no data is immediately available on entry.
pipe | The descriptor address of the pipe to receive from. |
msgp | A pointer to a memory location which will be written upon success with the address of the received message. Once consumed, the message space should be freed using rt_pipe_free(). The application code can retrieve the actual data and size carried by the message by respectively using the P_MSGPTR() and P_MSGSIZE() macros. *msgp is set to NULL and zero is returned to the caller, in case the peer closed the channel while rt_pipe_receive() was reading from it. |
timeout | The number of clock ticks to wait for some message to arrive (see note). Passing TM_INFINITE causes the caller to block indefinitely until some data is eventually available. Passing TM_NONBLOCK causes the service to return immediately without waiting if no data is available on entry. |
Environments:
This service can be called from:
Rescheduling: always unless the request is immediately satisfied or timeout specifies a non-blocking operation.
Referenced by rt_pipe_read().
ssize_t rt_pipe_send | ( | RT_PIPE * | pipe, |
RT_PIPE_MSG * | msg, | ||
size_t | size, | ||
int | mode | ||
) |
Send a message through a pipe.
This service writes a complete message to be received from the associated special device. rt_pipe_send() always preserves message boundaries, which means that all data sent through a single call of this service will be gathered in a single read(2) operation from the special device. This service differs from rt_pipe_write() in that it accepts a canned message buffer, instead of a pointer to the raw data to be sent. This call is useful whenever the caller wants to prepare the message contents separately from its sending, which does not require to have all the data to be sent available at once but allows for incremental updates of the message, and also saves a message copy, since rt_pipe_send() deals internally with message buffers.
pipe | The descriptor address of the pipe to send to. |
msg | The address of the message to be sent. The message space must have been allocated using the rt_pipe_alloc() service. Once passed to rt_pipe_send(), the memory pointed to by msg is no more under the control of the application code and thus should not be referenced by it anymore; deallocation of this memory will be automatically handled as needed. As a special exception, msg can be NULL and will not be dereferenced if size is zero. |
size | The size in bytes of the message (payload data only). Zero is a valid value, in which case the service returns immediately without sending any message. This parameter allows you to actually send less data than you reserved using the rt_pipe_alloc() service, which may be the case if you did not know how much space you needed at the time of allocation. In all other cases it may be more convenient to just pass P_MSGSIZE(msg). |
mode | A set of flags affecting the operation: |
Environments:
This service can be called from:
Rescheduling: possible.
Referenced by rt_pipe_write().
ssize_t rt_pipe_stream | ( | RT_PIPE * | pipe, |
const void * | buf, | ||
size_t | size | ||
) |
Stream bytes to a pipe.
This service writes a sequence of bytes to be received from the associated special device. Unlike rt_pipe_send(), this service does not preserve message boundaries. Instead, an internal buffer is filled on the fly with the data, which will be consumed as soon as the receiver wakes up.
Data buffers sent by the rt_pipe_stream() service are always transmitted in FIFO order (i.e. P_NORMAL mode).
pipe | The descriptor address of the pipe to write to. |
buf | The address of the first data byte to send. The data will be copied to an internal buffer before transmission. |
size | The size in bytes of the buffer. Zero is a valid value, in which case the service returns immediately without buffering any data. |
Environments:
This service can be called from:
Rescheduling: possible.
ssize_t rt_pipe_write | ( | RT_PIPE * | pipe, |
const void * | buf, | ||
size_t | size, | ||
int | mode | ||
) |
Write a message to a pipe.
This service writes a complete message to be received from the associated special device. rt_pipe_write() always preserves message boundaries, which means that all data sent through a single call of this service will be gathered in a single read(2) operation from the special device. This service differs from rt_pipe_send() in that it accepts a pointer to the raw data to be sent, instead of a canned message buffer. This call is useful whenever the caller does not need to prepare the message contents separately from its sending.
pipe | The descriptor address of the pipe to write to. |
buf | The address of the first data byte to send. The data will be copied to an internal buffer before transmission. |
size | The size in bytes of the message (payload data only). Zero is a valid value, in which case the service returns immediately without sending any message. |
mode | A set of flags affecting the operation: |
Environments:
This service can be called from:
Rescheduling: possible.
References rt_pipe_alloc(), rt_pipe_free(), and rt_pipe_send().