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.

The client’s view<br />

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

The process manager receives the request and looks through its tree structure to see if<br />

there’s a match (let’s assume for now that we need an exact match). Sure enough, the<br />

pathname “/dev/ser1” matches the request, and the process manager is able to reply<br />

to the client: “I found /dev/ser1. It’s being handled by node descriptor 0, process<br />

ID 44, channel ID 1, handle 1. Send them your request!”<br />

Remember, we’re still in the client’s open() code!<br />

So, the open() function creates another message, and a connection to the specified<br />

node descriptor (0, meaning our node), process ID (44), channel ID (1), stuffing the<br />

handle into the message itself. This message is really the “connect” message — it’s<br />

the message that the client’s open() library uses to establish a connection to a resource<br />

manager (step 3 in the picture below). When the resource manager gets the connect<br />

message, it looks at it and performs validation. For example, you may have tried to<br />

open-for-write a resource manager that implements a read-only filesystem, in which<br />

case you’d get back an error (in this case, EROFS). In our example, however, the serial<br />

port resource manager looks at the request (we specified O_WRONLY; perfectly legal<br />

for a serial port) and replies back <strong>with</strong> an EOK (step 4 in the picture below).<br />

(3) Connect<br />

Client<br />

(4) Reply<br />

Process<br />

Manager<br />

The _IO_CONNECT message.<br />

Finding the process manager<br />

Finally, the client’s open() returns to the client <strong>with</strong> a valid file descriptor.<br />

Really, this file descriptor is the connection ID we just used to send a connect message<br />

to the resource manager! Had the resource manager not givenusanEOK, we would<br />

have passed this error back to the client (via errno and a -1 return from open()).<br />

(It’s worthwhile to note that the process manager can return the node ID, process ID<br />

and channel ID of more than one resource manager in response to a name resolution<br />

request. In that case, the client will try each of them in turn until one succeeds, returns<br />

an error that’s not ENOSYS, ENOENT, orEROFS, or the client exhausts the list, in<br />

which case the open() fails. We’ll discuss this further when we look at the “before”<br />

and “after” flags, later on.)<br />

Now that we understand the basic steps used to find a particular resource manager, we<br />

need to solve the mystery of, “How did we find the process manager to begin <strong>with</strong>?”<br />

Actually, this one’s easy. By definition, the process manager has a node descriptor of 0<br />

(meaning this node), a process ID of 1, and a channel ID of 1. So, the ND/PID/CHID<br />

triplet 0/1/1 always identifies the process manager.<br />

194 Chapter 5 • Resource Managers April 30, 2009

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

Saved successfully!

Ooh no, something went wrong!