Nix 2.36.0
Nix, the purely functional package manager; unstable internal interfaces
Loading...
Searching...
No Matches
unix-domain-socket.hh File Reference
#include "nix/util/types.hh"
#include "nix/util/file-descriptor.hh"
#include "nix/util/socket.hh"
#include <filesystem>
#include <span>
#include <vector>
#include <unistd.h>

Go to the source code of this file.

Classes

struct  nix::unix::ReceivedMessage

Functions

AutoCloseFD nix::createUnixDomainSocket ()
AutoCloseFD nix::createUnixDomainSocket (const std::filesystem::path &path, mode_t mode)
void nix::bind (Socket fd, const std::filesystem::path &path)
void nix::connect (Socket fd, const std::filesystem::path &path)
AutoCloseFD nix::connect (const std::filesystem::path &path)
void nix::unix::sendMessageWithFds (Descriptor sockfd, std::span< const std::byte > data, std::span< const Descriptor > fds)
ReceivedMessage nix::unix::receiveMessageWithFds (Descriptor sockfd, std::span< std::byte > data)

Function Documentation

◆ bind()

void nix::bind ( Socket fd,
const std::filesystem::path & path )

Bind a Unix domain socket to a path.

◆ connect() [1/2]

AutoCloseFD nix::connect ( const std::filesystem::path & path)

Connect to a Unix domain socket.

◆ connect() [2/2]

void nix::connect ( Socket fd,
const std::filesystem::path & path )

Connect to a Unix domain socket.

◆ createUnixDomainSocket() [1/2]

AutoCloseFD nix::createUnixDomainSocket ( )

Create a Unix domain socket.

◆ createUnixDomainSocket() [2/2]

AutoCloseFD nix::createUnixDomainSocket ( const std::filesystem::path & path,
mode_t mode )

Create a Unix domain socket in listen mode.

◆ receiveMessageWithFds()

unix::ReceivedMessage nix::unix::receiveMessageWithFds ( Descriptor sockfd,
std::span< std::byte > data )

Receive a message with file descriptors over a Unix domain socket using recvmsg with SCM_RIGHTS.

All file descriptors associated with the message will be returned. This avoids unrecoverably dropping file descriptors with a messages. This is why a vector is returned, as opposed to the caller passing in a std::span with length of their choosing, as that may not be long enough.

Parameters
sockfdThe socket file descriptor to receive the message on
dataBuffer to receive data into
Returns
A ReceivedMessage containing the bytes received count and file descriptors
Exceptions
SysErroron failure
EndOfFileif the connection is closed

◆ sendMessageWithFds()

void nix::unix::sendMessageWithFds ( Descriptor sockfd,
std::span< const std::byte > data,
std::span< const Descriptor > fds )

Send a message with file descriptors over a Unix domain socket using sendmsg with SCM_RIGHTS.

On SOCK_STREAM sockets, data must be non-empty when fds is non-empty, because the kernel silently drops ancillary data on zero-length stream sends.

Parameters
sockfdThe socket file descriptor to send the message on
dataThe data to send
fdsA span of file descriptors to pass via SCM_RIGHTS
Exceptions
SysErroron failure