Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

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. Windows uses AF_UNIX sockets when they are available. 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 UNIX domain socket should be created.

Tip

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_addr will 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 NUL byte. This is because legacy versions of nanomsg cannot express URLs longer than 128 bytes, including the ipc:// prefix.

UNIX Aliases

The unix:// scheme is an alias for ipc:// and can be used interchangeably wherever UNIX domain sockets are supported.

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, ipc:// and unix:// operations fail because WSASocket(AF_UNIX, ...) returns WSAEAFNOSUPPORT.

Windows Named Pipes

On Windows, the winpipe:// scheme selects the legacy named-pipe transport. Names are prefixed by \\.\pipe\ and do not reside in the normal file system. Use this scheme when compatibility with existing Windows ipc:// named-pipe users is required.

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.1

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.

OptionTypeDescription
NNG_OPT_IPC_PERMISSIONSintSettable on POSIX listeners before they start, this is the UNIX file mode used when creating the socket.
NNG_OPT_IPC_OWNERintSettable on POSIX listeners before they start, this requests the UNIX user ID for the socket. Elevated permission may be required; failure is ignored.
NNG_OPT_IPC_GROUPintSettable on POSIX listeners before they start, this requests the UNIX group ID for the socket. Elevated permission may be required; failure is ignored.
NNG_OPT_PEER_GIDintRead only option, returns the group ID of the process at the other end of the socket, if platform supports it.
NNG_OPT_PEER_PIDintRead only option, returns the process ID of the process at the other end of the socket, if platform supports it.
NNG_OPT_PEER_UIDintRead only option, returns the user ID of the process at the other end of the socket, if platform supports it.
NNG_OPT_PEER_ZONEIDintRead only option, returns the zone ID of the process at the other end of the socket, if platform supports it.
NNG_OPT_LISTEN_FDintWrite only for listeners before they start, use the named socket for accepting (for use with socket activation).

Other Configuration Parameters

On Windows, a winpipe:// named-pipe listener can use nng_listener_set_security_descriptor to control access.

The POSIX owner and group options are applied with chown(2) after binding. Because that operation generally requires elevated privilege, failure to apply either value does not prevent the listener from starting. They are ignored for abstract sockets, which have no file-system representation. On Windows, use a security descriptor to control access to winpipe:// named pipes. The Windows AF_UNIX (ipc:// or unix://) implementation uses its containing directory’s ACL; POSIX owner, group, and permission options are not supported.


  1. This property makes it important that names be chosen randomly to prevent unauthorized access, or that checks against the peer credentials are made, or ideally, both. ↩