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. Message passing over a network<br />

2 Node descriptors are not to be cached — if you get one, you’re supposed to use<br />

it immediately and then forget about it.<br />

3 There are library calls to convert a pathname (like /net/magenta) to a node<br />

descriptor.<br />

To work <strong>with</strong> node descriptors, you’ll want to include the file <br />

because it includes a bunch of netmgr_*() functions.<br />

You’d use the function netmgr_strtond() to convert a string into a node descriptor.<br />

Once you have this node descriptor, you’d use it immediately in the ConnectAttach()<br />

function call. Specifically, you shouldn’t ever cache it in a data structure! The reason<br />

is that the native networking manager may decide to reuse it once all connections to<br />

that particular node are disconnected. So, if you got a node descriptor of “7” for<br />

/net/magenta, and you connected to it, sent a message, and then disconnected,<br />

there’s a possibility that the native networking manager will return a node descriptor<br />

of “7” again for a different node.<br />

Since node descriptors aren’t unique per network, the question that arises is, “How do<br />

you pass these things around the network?” Obviously, magenta’s view of what node<br />

descriptor “7” is will be radically different from wintermute’s. There are two<br />

solutions here:<br />

• Don’t pass around node descriptors; use the symbolic names (e.g.,<br />

/net/wintermute) instead.<br />

• Use the netmgr_remote_nd() function.<br />

The first is a good general-purpose solution. The second solution is reasonably simple<br />

to use:<br />

int<br />

netmgr_remote_nd (int remote_nd, int local_nd);<br />

This function takes two parameters: the remote_nd is the node descriptor of the target<br />

machine, and local_nd is the node descriptor (from the local machine’s point of view)<br />

to be translated to the remote machine’s point of view. The result is the node<br />

descriptor that is valid from the remote machine’s point of view.<br />

For example, let’s say wintermute is our local machine. We have a node descriptor<br />

of “7” that is valid on our local machine and points to magenta. What we’d like to<br />

find out is what node descriptor magenta uses to talk to us:<br />

int<br />

int<br />

remote_nd;<br />

magenta_nd;<br />

magenta_nd = netmgr_strtond ("/net/magenta", NULL);<br />

printf ("Magenta’s ND is %d\n", magenta_nd);<br />

remote_nd = netmgr_remote_nd (magenta_nd, ND_LOCAL_NODE);<br />

printf ("From magenta’s point of view, we’re ND %d\n",<br />

remote_nd);<br />

This might print something similar to:<br />

April 30, 2009 Chapter 2 • Message Passing 129

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

Saved successfully!

Ooh no, something went wrong!