IPC Transport
DESCRIPTION
The ipc transport provides communication support between
sockets within different processes on the same host.
For POSIX platforms, this is implemented using UNIX domain sockets.
For Windows, this is implemented using Windows named pipes. Windows
also supports the related unix:// scheme, which uses Windows
AF_UNIX sockets.
Other platforms may have different implementation strategies.
URI Formats
Traditional Names
This transport uses URIs using the scheme ipc://, followed by a path
name in the file system where the socket or named pipe should be created.
Tip
On Windows, all names are prefixed by
\\.\pipe\and do not reside in the normal file system. On POSIX platforms, the path is taken literally, and is relative to the current directory, unless it begins with/, in which case it is relative to the root directory.
Note
When using relative paths on POSIX systems, the address used and returned in functions such as
nng_pipe_peer_addrwill also be relative. Consequently, they will only be interpreted the same by processes that have the same working directory. To ensure maximum portability and safety, absolute paths are recommended whenever possible.
Note
If compatibility with legacy nanomsg applications is required, then path names must not be longer than 122 bytes, including the final
NULbyte. This is because legacy versions of nanomsg cannot express URLs longer than 128 bytes, including theipc://prefix.
UNIX Aliases
On POSIX systems, the unix:// scheme is an alias for ipc:// and can
be used interchangeably. On Windows, it instead selects the AF_UNIX transport;
ipc:// continues to select named pipes.1
On Windows, the unix:// path is a UTF-8 Win32 pathname (for example,
unix://C:\Temp\nng.sock) and is limited to 107 bytes plus its final NUL.
Windows AF_UNIX streams support NNG_OPT_PEER_PID, but do not provide
POSIX user or group credentials.
AF_UNIX requires Windows build 17063 or later; on older builds, unix://
operations fail because WSASocket(AF_UNIX, ...) returns WSAEAFNOSUPPORT.
Abstract Names
On Linux, this transport also can support abstract sockets.
Abstract sockets use a URI-encoded name after the abstract:// scheme, which allows arbitrary values to be conveyed
in the path, including embedded NUL bytes.
For example, the name "a\0b" would be represented as abstract://a%00b.
Note
NNG no longer supports “auto binding” where the kernel allocates a random unused name. A simple solution to this is to allocate a large random number, such as a random UUID or a concatenation of four random values from
nng_random. The chance of a collision can be made arbitrarily small by appending additional random values.
Abstract names do not include the leading NUL byte used in the low-level socket address.
Abstract sockets do not have any representation in the file system, and are automatically freed by the system when no longer in use.
Abstract sockets ignore socket permissions, but it is still possible to determine the credentials
of the peer with NNG_OPT_PEER_UID, and similar options.2
Socket Address
When using an nng_sockaddr structure,
the actual structure is of type nng_sockaddr_ipc,
except for abstract sockets, which use nng_sockaddr_abstract.
Transport Options
The following transport options are supported by this transport, where supported by the underlying platform.
| Option | Type | Description |
|---|---|---|
NNG_OPT_IPC_PERMISSIONS | int | Settable on listeners before they start, this is the UNIX file mode used when creating the socket. |
NNG_OPT_PEER_GID | int | Read only option, returns the group ID of the process at the other end of the socket, if platform supports it. |
NNG_OPT_PEER_PID | int | Read only option, returns the processed ID of the process at the other end of the socket, if platform supports it. |
NNG_OPT_PEER_UID | int | Read only option, returns the user ID of the process at the other end of the socket, if platform supports it. |
NNG_OPT_PEER_ZONEID | int | Read only option, returns the zone ID of the process at the other end of the socket, if platform supports it. |
NNG_OPT_LISTEN_FD | int | Write only for listeners before they start, use the named socket for accepting (for use with socket activation). |
Other Configuration Parameters
On Windows systems, the security descriptor for the listener,
which can be used to control access, can be set using the function
nng_listener_set_security_descriptor.