Using the Receive Buffer as a Reply Buffer
QNX SDP8.0Writing a Resource ManagerDeveloper
When building a response to a client request, you often need a temporary buffer in which to build this response.
Using the receive buffer, ctp->msg, can be a convenient choice because:
- It does not require allocating or freeing
- It is local to the thread doing the work
- Unlike a stack buffer, it is valid after a return from the function, which is important if the library replies on your behalf (e.g., by returning _RESMGR_PTR())
The ctp->msg buffer has ctp->msg_max_size bytes of space available in which to build
this response. The default value is a bit more than 2KiB. If you find you need more, you can configure a larger
receive buffer at initialization by setting the msg_max_size field in the resmgr_attr_t structure
given to resmgr_attach().
Note:
When you're handling parts of combine messages that are not the last part of the message (i.e., when
ctp->rcvid == 0
), you are not allowed to reply, and should not touch the receive buffer at all.
While using the receive buffer as your reply buffer, you should:
- Make sure to extract any information you need from the receive buffer before overwriting it. For example, if you need the client's number of bytes (msg->i.nbytes in several cases), store that value before you overwrite it. Some resource manager library helper functions (e.g., iofunc_stat() or resmgr_msgget()) also examine or extract data from the receive buffer, and should not be used after you have modified the contents of the buffer.
- Take care to not exceed your available space. Take special caution when assembling a response from multiple parts with variable size, such as when assembling a path for a symbolic link reply or when building a list of directory entries in response to a readdir() request.
- Remember that while many of the message types provide a msg->o entry in their union for building a response, you should always use ctp->msg to have the full receive buffer available. If you're handling later messages in a combine message, the msg->o may be pointing arbitrarily close to the end of your receive buffer, not giving you the space you expect.
Page updated: