26.02.2014 Views

Getting Started with QNX Neutrino - QNX Software Systems

Getting Started with QNX Neutrino - QNX Software Systems

Getting Started with QNX Neutrino - QNX Software Systems

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

© 2009, <strong>QNX</strong> <strong>Software</strong> <strong>Systems</strong> GmbH & Co. KG. Using message passing<br />

Notice that the message transfer has specified an offset of sizeof<br />

(header.io_write) in order to skip the write header that was added by the client’s<br />

C library. We’re assuming here that cache_buffer [index].size is actually 4096<br />

(or more) bytes.<br />

Similarly, for writing data to the client’s address space, we have:<br />

#include <br />

int MsgWrite (int rcvid,<br />

const void *msg,<br />

int nbytes,<br />

int offset);<br />

MsgWrite() lets your server write data to the client’s address space, starting offset<br />

bytes from the beginning of the client-specified “receive” buffer. This function is most<br />

useful in cases where the server has limited space but the client wishes to get a lot of<br />

information from the server.<br />

For example, <strong>with</strong> a data acquisition driver, the client may specify a 4-megabyte data<br />

area and tell the driver to grab 4 megabytes of data. The driver really shouldn’t need to<br />

have a big area like this lying around just in case someone asks for a huge data<br />

transfer.<br />

The driver might have a 128 KB area for DMA data transfers, and then message-pass<br />

it piecemeal into the client’s address space using MsgWrite() (incrementing the offset<br />

by 128 KB each time, of course). Then, when the last piece of data has been written,<br />

the driver will MsgReply() to the client.<br />

128 KB chunk<br />

128 KB chunk<br />

128 KB chunk<br />

1<br />

2<br />

3<br />

128 KB chunk<br />

Client's address space<br />

Driver's address space<br />

Transferring several chunks <strong>with</strong> MsgWrite().<br />

Note that MsgWrite() lets you write the data components at various places, and then<br />

either just wake up the client using MsgReply():<br />

MsgReply (rcvid, EOK, NULL, 0);<br />

or wake up the client after writing a header at the start of the client’s buffer:<br />

MsgReply (rcvid, EOK, &header, sizeof (header));<br />

This is a fairly elegant trick for writing unknown quantities of data, where you know<br />

how much data you wrote only when you’re done writing it. If you’re using this<br />

method of writing the header after the data’s been transferred, you must remember to<br />

leave room for the header at the beginning of the client’s data area!<br />

April 30, 2009 Chapter 2 • Message Passing 107

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!