Establish a connection between a process and a channel
#include <sys/neutrino.h> #include <sys/netmgr.h> int ConnectAttach( uint32_t nd, pid_t pid, int chid, unsigned index, int flags ); int ConnectAttach_r( uint32_t nd, pid_t pid, int chid, unsigned index, int flags );
Having a connection ID in the file descriptor range can lead to unexpected behavior. Therefore, you should pass in _NTO_SIDE_CHANNEL for index when you create a connection. The C library creates connections at various times without _NTO_SIDE_CHANNEL (e.g., during open()); however, it's unlikely that any applications would want to call it this way.
Once the ID is created, there's no difference in the use of the messaging primitives on it.
In QNX Neutrino 7.0 and later, the server or client can set this flag if it doesn't trust the program at the other end of the connection, but only the kernel can clear it. Currently the flag stays set until the connection is detached.
libc
Use the -l c option to qcc to link against this library. This library is usually included automatically.
The ConnectAttach() and ConnectAttach_r() kernel calls establish a connection between the calling process and the channel specified by chid owned by the process specified by pid on the node specified by nd. Any function that passes a node descriptor can use either the value 0 or the constant ND_LOCAL_NODE to refer to the local node.
These functions are identical except in the way they indicate errors. See the Returns section for details.
The return value is a connection ID, which is a small int representing the connection. The system returns the first available connection ID starting at the value specified by the index argument. Any thread in the calling process can use the MsgSend*() or MsgSendv*() functions to send messages or MsgSendPulse() to send pulses over the connection. The connection ID is used directly as a POSIX file descriptor (fd) when communicating with I/O Resource managers such as a filesystem manager.
We recommend that you OR _NTO_SIDE_CHANNEL into index, to create the connection as a side channel. In this case, the index argument is ignored, and the connection ID returned is the first available index in the _NTO_SIDE_CHANNEL space, which is different than the file descriptor space.
If you don't OR _NTO_SIDE_CHANNEL into index, this behavior might result:
File descriptor 1 (i.e., connection ID 1) is used as stdout, which is what printf() writes to. If your process makes any calls to printf(), NULL-terminated character strings are sent to the channel that you've connected to. Similar situations can happen with connection IDs 0 (stdin) and 2 (stderr).
Since connections are treated like file descriptors, a connection created by the parent without _NTO_SIDE_CHANNEL in index and without _NTO_COF_CLOEXEC in flags, causes a child process to inherit that connection during process creation. This inheritance is done during process creation by duplicating file descriptors.
During duplication, an _IO_DUP message (with 0x115 as the first 2 bytes) is sent to the receiver on the other side of the connection. The receiver won't be expecting this message.
Connections created with _NTO_SIDE_CHANNEL are never inherited by child processes created by a fork() call or new process images executed by an exec*() call. This means the receiver won't get an unexpected _IO_DUP message.
If a process creates multiple connections to the same channel, the system maintains a link count and shares internal kernel object resources for efficiency.
Connections are owned by the process and may be used simultaneously by any thread in the process. You can detach a connection by calling ConnectDetach().
The connection is strictly local (i.e., it doesn't resolve across the network) and is resolved on the first use of the connection ID.
Blocking states
These calls don't block.
Node descriptors
The nd (node descriptor) is a temporary numeric description of a remote node. For more information, see the Qnet Networking chapter of the System Architecture guide.
To: | Use this function: |
---|---|
Compare two nd objects | ND_NODE_CMP() |
Convert a nd to text | netmgr_ndtostr() |
Convert text to a nd | netmgr_strtond() |
A connection ID (coid) that's used by the message primitives. If an error occurs:
Safety: | |
---|---|
Cancellation point | No |
Interrupt handler | No |
Signal handler | Yes |
Thread | Yes |