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. Network-distributed message passing<br />

Network-distributed message passing<br />

Suppose we want to change our example above to talk to a different node on the<br />

network. You might think that we’ll have to invoke special function calls to “get<br />

networked.” Here’s the network version’s code:<br />

#include <br />

#include <br />

int<br />

main (void)<br />

{<br />

int<br />

fd;<br />

fd = open ("/net/wintermute/home/rk/filename", O_WRONLY);<br />

write (fd, "This is message passing\n", 24);<br />

close (fd);<br />

return (EXIT_SUCCESS);<br />

What it means for you<br />

}<br />

You’re right if you think the code is almost the same in both versions. It is.<br />

In a traditional OS, the C library open() calls into the kernel, which looks at the<br />

filename and says “oops, this is on a different node.” The kernel then calls into the<br />

network filesystem (NFS) code, which figures out where<br />

/net/wintermute/home/rk/filename actually is. Then, NFS calls into the<br />

network driver and sends a message to the kernel on node wintermute, which then<br />

repeats the process that we described in our original example. Note that in this case,<br />

there are really two filesystems involved; one is the NFS client filesystem, and one is<br />

the remote filesystem. Unfortunately, depending on the implementation of the remote<br />

filesystem and NFS, certain operations may not work as expected (e.g., file locking)<br />

due to incompatibilities.<br />

Under <strong>Neutrino</strong>, the C library open() creates the same message that it would have sent<br />

to the local filesystem and sends it to the filesystem on node wintermute. In the local<br />

and remote cases, the exact same filesystem is used.<br />

This is another fundamental characteristic of <strong>Neutrino</strong>: network-distributed operations<br />

are essentially “free,” as the work to decouple the functionality requirements of the<br />

clients from the services provided by the servers is already done, by virtue of message<br />

passing.<br />

On a traditional kernel there’s a “double standard” where local services are<br />

implemented one way, and remote (network) services are implemented in a totally<br />

different way.<br />

Message passing is elegant and network-distributed. So what? What does it buy you,<br />

the programmer?<br />

Well, it means that your programs inherit those characteristics — they too can become<br />

network-distributed <strong>with</strong> far less work than on other systems. But the benefit that I<br />

find most useful is that they let you test software in a nice, modular manner.<br />

April 30, 2009 Chapter 2 • Message Passing 85

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

Saved successfully!

Ooh no, something went wrong!