next up previous contents
Next: Other Operations Up: Message Library Previous: Fragmenting and Reassembling

Traversing Messages

So as to avoid the unnecessary copying of data from one buffer to another, the message object is implemented by a tree of buffers. (See [2] for a description of this data structure.) Because the data contained in a message object is scattered over multiple, non-contiguous memory buffers, the x-kernel provides a set of operations for walking the tree and extracting the actual data.

void msgWalkInit(MsgWalk cxt, Msg *message)

char *msgWalkNext(MsgWalk cxt, int *len)

void msgWalkDone(MsgWalk cxt)

Operation msgWalkNext traverses the message tree, and returns a pointer to the next chunk of data in the message; it also sets len to the number of bytes in that chunk. Argument cxt maintains the context for the message traversal, so that msgWalkNext knows how far through the tree it got on the last invocation. The other two operations--- msgWalkInit and msgWalkDone---initialize and destroy this context, respectively.

As a simple example of how one might use msgWalkNext, device drivers often create an array of pointers to the various pieces of the message (along with each piece's length). Arrays of buffer/length pairs are commonly accepted by network devices, so this might be something that is done by a network device driver to prepare an x-kernel message for transmission over a physical link.



Larry Peterson
Wed Feb 21 13:58:06 MST 1996