ConnectAttach(), ConnectAttach_r()

Установить соединение между процессом и каналом

Прототип:

#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 );

Аргументы:

nd
The node descriptor of the node (e.g. ND_LOCAL_NODE for the local node) on which the process that owns the channel is running; see “Дескрипторы узлов” below.
pid
The process ID of the owner of the channel. If pid is zero, the calling process is assumed.
chid
The channel ID, returned by ChannelCreate(), of the channel to connect to the process.
index
The lowest acceptable connection ID.

Note: Treating a connection as a file descriptor can lead to unexpected behavior. Therefore, you should OR _NTO_SIDE_CHANNEL into index when you create a connection. If you do this, the connection ID is returned from a different space than file descriptors; the ID is greater than any valid file descriptor.

Once created there's no difference in the use of the messaging primitives on this ID. 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.

flags
If flags contains _NTO_COF_CLOEXEC, the connection is closed when your process calls an exec*() function to start a new process.

Библиотека:

libc

Описание:

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.

Данные функции идентичны за исключением способа возврата ошибок.


Note: If a process wants other processes to communicate with it, it typically uses name_attach() to create a channel and associate a name with it, and the sender process uses name_open() to locate that name and create a connection to it.

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 either MsgSendv() 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.

If you don't OR _NTO_SIDE_CHANNEL into index, this behavior might result:

If index has _NTO_SIDE_CHANNEL set, the index is ignored and the connection ID returned is the first available index in the _NTO_SIDE_CHANNEL space.

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(). If any threads are blocked on the channel (via MsgSendv()) at the time the connection is detached, the send fails and returns with an error.


Note: Connections and connection IDs persist until you call ConnectDetach(), even if the other process dies.

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.

Состояния блокировки:

These calls don't block.

Дескрипторы узлов

The nd (node descriptor) is a temporary numeric description of a remote node.

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()

Возвращаемое значение:

ConnectAttach()
A connection ID that's used by the message primitives. If an error occurs, the function returns -1 and sets errno.
ConnectAttach_r()
A connection ID that's used by the message primitives. This function does NOT set errno. If an error occurs, the function returns the negative of a value from the Errors section.

Коды ошибок:

EAGAIN
Insufficent resources.
EINVAL
One of the following:
EMFILE
The process has no unused file descriptors, or no file descriptors greater than or equal to index are available.
ENOREMOTE
The node indicated by nd doesn't exist.
ENXIO
The process indicated by pid is no longer valid. It's going away, has core dumped, or become a zombie.
ESRCH
The process indicated by pid, or the channel indicated by chid, doesn't exist.

Классификация:

ЗОСРВ «Нейтрино»

Точка остановки потока
Да
Обработчик прерываний
Нет
Обработчик сигналов
Да
В потоке
Да

Тематические ссылки:

ChannelCreate(), ConnectDetach(), execl(), execle(), execlp(), execlpe(), execv(), execve(), execvp(), execvpe(), MsgSendPulse(), MsgSendv(), name_attach(), name_open(), netmgr_remote_nd()




Предыдущий раздел: Описание API системной библиотеки