resmgr_msgreplyv()

Reply to a client with a message, endian-swapping if required

Synopsis:

#include <sys/iofunc.h>
#include <sys/resmgr.h>

int resmgr_msgreplyv( resmgr_context_t *ctp,
                      struct iovec *iov,
                      int parts );

Arguments:

ctp
A pointer to a resmgr_context_t structure that the resource-manager library uses to pass context information between functions. This function extracts the rcvid from this structure.
iov
An array of buffers that contains the message that you want to reply with.
parts
The number of elements in the array.

Library:

libc

Use the -l c option to qcc to link against this library. This library is usually included automatically.

Description:

The resmgr_msgreplyv() function replies with a message to the thread identified by ctp->rcvid. It's a wrapper over MsgReplyv() that endian-swaps standard I/O message types for use over Qnet. If Qnet isn't in use, or no endian-swapping is necessary, it simply invokes MsgReplyv(). The resmgr_msgreply() function is similar to resmgr_msgreplyv() but takes a single message buffer.

This function is called by the server to reply back to the client. The client thread must already be in the REPLY state, and the thread being replied to must be in the REPLY-blocked state. Any thread in the receiving process is free to reply to the message; however, it may be replied to only once for each receive.

Note: You can fill the client's reply buffer as data becomes available by using resmgr_msgwrite() and resmgr_msgwritev(); however, you'll need to call resmgr_msgreply() or resmgr_msgreplyv() at some point to unblock the client.

The data is taken from the array of message buffers pointed to by iov. The number of elements in this array is given by parts. The size of the message is the sum of the sizes of each buffer.

If the function succeeds, the number of bytes transferred is the minimum of that specified by both the replier and the sender. The reply data isn't allowed to overflow the reply buffer area provided by the sender.

The data transfer occurs immediately, and the replying thread doesn't block. There's no need to reply to received messages in any particular order, but you must eventually reply to each message to allow the sending thread(s) to continue execution.

It's quite common to reply with two-part messages consisting of a fixed header and a buffer of data. The resmgr_msgreplyv() function gathers the data from the buffer list into a logical contiguous message and transfers it to the sender's reply buffer(s). The sender doesn't need to specify the same number or size of buffers. The data is laid down filling each buffer as required. The filesystem, for example, builds a reply list pointing into its cache, in order to reply with what appears to be one contiguous piece of data.

Returns:

If an error occurs, -1 is returned and errno is set.

Errors:

EDEADLK
A deadlock occurred. You can avoid a deadlock by setting the _NTO_CHF_MSG_PAUSING flag when you create a channel; for more information, see ChannelCreate() and MsgPause().
EENDIAN
The message type wasn't recognized and therefore couldn't be endian-swapped.
EFAULT
A fault occurred in the sender's address space when a server tried to access the sender's return message buffers.
ENOREMOTE
The reply has to go across the network, and Qnet isn't running.
EOVERFLOW
The sum of the IOV lengths exceeds INT_MAX, or the number of parts exceeds 524288.
ESRCH
The thread indicated by rcvid doesn't exist, or is no longer REPLY-blocked on the channel, or the connection was detached.
ESRVRFAULT
A fault occurred when the kernel tried to access the buffers provided.

Classification:

QNX Neutrino

Safety:  
Cancellation point No
Interrupt handler No
Signal handler Yes
Thread Yes