Effective use of other messaging functions

As you'll recall from the Message Passing chapter, we discussed a few other message-passing functions—namely MsgWrite(), MsgWritev(), and MsgReplyv(). The reason I'm mentioning them here again is because your io_read() function may be in an excellent position to use these functions. In the simple example shown above, we were returning a contiguous array of bytes from one memory location. In the real world, you may need to return multiple pieces of data from various buffers that you've allocated.

A classical example of this is a ring buffer, as might be found in a serial device driver. Part of the data may be near the end of the buffer, with the rest of it "wrapped" to the top of the buffer. In this case, you'll want to use a two-part IOV with MsgReplyv() to return both parts. The first part of the IOV would contain the address (and length) of the bottom part of the data, and the second part of the IOV would contain the address (and length) of the top part of the data. Or, if the data is going to arrive in pieces, you may instead choose to use MsgWrite() or MsgWritev() to place the data into the client's address space as it arrives and then specify a final MsgReply() or MsgReplyv() to unblock the client. As we've seen above, there's no requirement to actually transfer data with the MsgReply() function—you can use it to simply unblock the client.