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.

Using message passing<br />

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

What about the other versions?<br />

// allocate / find cache buffer entries<br />

// fill 3-part IOV <strong>with</strong> cache buffers<br />

MsgReadv (rcvid, iov, 3, sizeof (header.io_write));<br />

This does the initial MsgReceive() (note that we didn’t use the IOV form for this —<br />

there’s really no need to do that <strong>with</strong> a one-part message), figures out what kind of<br />

message it is, and then continues reading the data out of the client’s address space<br />

(starting at offset sizeof (header.io_write)) into the cache buffers specified by<br />

the 3-part IOV.<br />

Notice that we switched from using a 4-part IOV (in the first example) to a 3-part IOV.<br />

That’s because in the first example, the first part of the 4-part IOV was the header,<br />

which we read directly using MsgReceive(), and the last three parts of the 4-part IOV<br />

are the same as the 3-part IOV — they specify where we’d like the data to go.<br />

You can imagine how we’d perform the reply for a read request:<br />

1 Find the cache entries that correspond to the requested data.<br />

2 Fill an IOV structure <strong>with</strong> those entries.<br />

3 Use MsgWritev() (or MsgReplyv()) to transfer the data to the client.<br />

Note that if the data doesn’t start right at the beginning of a cache block (or other data<br />

structure), this isn’t a problem. Simply offset the first IOV to point to where the data<br />

does start, and modify the size.<br />

All the message-passing functions except the MsgSend*() family have the same<br />

general form: if the function has a “v” at the end of it, it takes an IOV and a<br />

number-of-parts; otherwise, it takes a pointer and a length.<br />

The MsgSend*() family has four major variations in terms of the source and<br />

destinations for the message buffers, combined <strong>with</strong> two variations of the kernel call<br />

itself.<br />

Look at the following table:<br />

Function Send buffer Receive buffer<br />

MsgSend() Linear Linear<br />

MsgSendnc() Linear Linear<br />

MsgSendsv() Linear IOV<br />

MsgSendsvnc() Linear IOV<br />

MsgSendvs() IOV Linear<br />

MsgSendvsnc() IOV Linear<br />

continued. . .<br />

112 Chapter 2 • Message Passing April 30, 2009

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

Saved successfully!

Ooh no, something went wrong!