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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

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

Not replying to the client<br />

Replying <strong>with</strong> no data, or an errno<br />

There’s absolutely no requirement that you reply to a client before accepting new<br />

messages from other clients via MsgReceive()! This can be used in a number of<br />

different scenarios.<br />

In a typical device driver, a client may make a request that won’t be serviced for a long<br />

time. For example, the client may ask an Analog-to-Digital Converter (ADC) device<br />

driver to “Go out and collect 45 seconds worth of samples.” In the meantime, the ADC<br />

driver shouldn’t just close up shop for 45 seconds! Other clients might wish to have<br />

requests serviced (for example, there might be multiple analog channels, or there<br />

might be status information that should be available immediately, etc.).<br />

Architecturally, the ADC driver will simply queue the receive ID that it got from the<br />

MsgReceive(), start up the 45-second accumulation process, and go off and handle<br />

other requests. When the 45 seconds are up and the samples have been accumulated,<br />

the ADC driver can find the receive ID associated <strong>with</strong> the request and then reply to<br />

the client.<br />

You’d also want to hold off replying to a client in the case of the reply-driven<br />

server/subserver model (where some of the “clients” are the subservers). Since the<br />

subservers are looking for work, you’d simply make a note of their receive IDs and<br />

store those away. When actual work arrived, then and only then would you reply to the<br />

subserver, thus indicating that it should do some work.<br />

When you finally reply to the client, there’s no requirement that you transfer any data.<br />

This is used in two scenarios.<br />

You may choose to reply <strong>with</strong> no data if the sole purpose of the reply is to unblock the<br />

client. Let’s say the client just wants to be blocked until some particular event occurs,<br />

but it doesn’t need to know which event. In this case, no data is required by the<br />

MsgReply() function; the receive ID is sufficient:<br />

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

This unblocks the client (but doesn’t return any data) and returns the EOK “success”<br />

indication.<br />

As a slight modification of that, you may wish to return an error status to the client. In<br />

this case, you can’t do that <strong>with</strong> MsgReply(), but instead must use MsgError():<br />

MsgError (rcvid, EROFS);<br />

In the above example, the server detects that the client is attempting to write to a<br />

read-only filesystem, and, instead of returning any actual data, simply returns an errno<br />

of EROFS back to the client.<br />

Alternatively (and we’ll look at the calls shortly), you may have already transferred<br />

the data (via MsgWrite()), and there’s no additional data to transfer.<br />

Why the two calls? They’re subtly different. While both MsgError() and MsgReply()<br />

will unblock the client, MsgError() will not transfer any additional data, will cause the<br />

April 30, 2009 Chapter 2 • Message Passing 101

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

Saved successfully!

Ooh no, something went wrong!