libcppwrap
A collection of C++ wrappers for native APIs
Loading...
Searching...
No Matches
Classes | Typedefs | Functions
w Namespace Reference

Classes

struct  const_list_iterator
 A forward iterator for linked lists. More...
 
class  handle
 An RAII handle type which owns an opaque resource of a specified type, and calls a designated function to close the resource upon destruction. More...
 
struct  ipv4_address
 Wraps struct sockaddr_in, adding constructors for convenient initialization. More...
 
struct  ipv6_address
 Wraps struct sockaddr_in6, adding constructors for convenient initialization. More...
 
struct  memory_region
 A structure holding details about a memory-mapped file or device. More...
 
struct  unix_domain_address
 Wraps struct sockaddr_in, adding constructors for convenient initialization. More...
 

Typedefs

typedef w::handle< int, -1, ::close > fd
 An RAII util::handle type for POSIX file descriptors. More...
 

Functions

template<typename T >
throw_if_eq (T value, T x, const char *message)
 Throw a std::system_error with errno if value == x, otherwise return value. More...
 
template<typename T >
throw_if_lt (T value, T x, const char *message)
 Throw a std::system_error with errno if value < x, otherwise return value. More...
 
template<typename T >
throw_if_ne (T value, T x, const char *message)
 Throw a std::system_error with errno if value != x, otherwise return value. More...
 
template<typename T >
throw_if_nz (T value, const char *message)
 Throw a std::system_error with errno if value != 0, otherwise return value. More...
 
template<typename T >
throw_if_z (T value, const char *message)
 Throw a std::system_error with errno if value == 0, otherwise return value. More...
 
w::fd epoll_create (int size=sizeof(nullptr))
 Creates an epoll instance. More...
 
void epoll_ctl (int epfd, int op, int fd, struct epoll_event *event=nullptr)
 Manipulates an epoll instance. More...
 
void epoll_ctl (int epfd, int op, int fd, std::uint32_t events, void *user_data=nullptr)
 Manipulates an epoll instance. More...
 
void epoll_ctl (int epfd, int op, int fd, std::uint32_t events, int user_data)
 Manipulates an epoll instance. More...
 
void epoll_ctl (int epfd, int op, int fd, std::uint32_t events, std::uint32_t user_data)
 Manipulates an epoll instance. More...
 
void epoll_ctl (int epfd, int op, int fd, std::uint32_t events, std::uint64_t user_data)
 Manipulates an epoll instance. More...
 
unsigned epoll_wait (int epfd, struct epoll_event *events, int maxevents, std::chrono::milliseconds timeout=std::chrono::milliseconds(-1))
 Waits for events to occur on an epoll instance. More...
 
w::fd eventfd (unsigned initval=0, int flags=0)
 Creates an event file descriptor. More...
 
std::uint64_t eventfd_read (int evfd)
 Reads the current counter value of an event file descriptor; see the man page of eventfd() for a description of the counter and blocking semantics. More...
 
void eventfd_write (int evfd, std::uint64_t value)
 Modifies the counter value of an event file descriptor; see the man page of eventfd() for a description of the counter semantics. More...
 
w::fd timerfd_create (int clockid, int flags=0)
 Creates a timer file descriptor. More...
 
void timerfd_settime (int fd, int flags, const struct itimerspec *new_value, struct itimerspec *old_value)
 Sets the timeout and repetition interval of a timer file descriptor. More...
 
std::pair< std::chrono::nanoseconds, std::chrono::nanosecondstimerfd_settime (int fd, int flags, std::chrono::nanoseconds interval, std::chrono::nanoseconds initial)
 Sets the timeout and repetition interval of a timer file descriptor. More...
 
int fcntl (int fd, int cmd)
 Controls a file descriptor. More...
 
template<typename Argument >
int fcntl (int fd, int cmd, const Argument &arg)
 Controls a file descriptor. More...
 
int ioctl (int fd, unsigned long request, void *arg)
 Controls a device. More...
 
int ioctl (int fd, unsigned long request, const void *arg)
 Controls a device. More...
 
template<typename Argument >
int ioctl (int fd, unsigned long request, Argument &arg)
 Controls a device. More...
 
template<typename Argument >
int ioctl (int fd, unsigned long request, const Argument &arg)
 Controls a device. More...
 
template<typename Argument >
Argument ioctl (int fd, unsigned long request)
 Controls a device. More...
 
std::size_t lseek (int fd, off_t offset, int whence)
 Sets the position of a file pointer for a file descriptor. More...
 
w::fd open (const char *pathname, int flags)
 Opens and possibly creates a file. More...
 
w::fd open (const char *pathname, int flags, mode_t mode)
 Opens and possibly creates a file. More...
 
std::pair< w::fd, w::fdpipe ()
 Creates a pipe. More...
 
std::size_t read (int fd, void *buf, std::size_t count)
 Reads data from a file descriptor. More...
 
std::size_t readv (int fd, const struct iovec *iov, int iovcnt)
 Reads data from a file descriptor. More...
 
std::size_t write (int fd, const void *buf, std::size_t count)
 Writes data to a file descriptor. More...
 
std::size_t writev (int fd, const struct iovec *iov, int iovcnt)
 Writes data to a file descriptor. More...
 
w::fd accept (int sockfd, struct sockaddr *addr, socklen_t *addrlen)
 Accepts a connection on a socket. More...
 
template<typename Address >
w::fd accept (int sockfd, Address &addr)
 Accepts a connection on a socket. More...
 
void bind (int sockfd, const struct sockaddr *addr, socklen_t addrlen)
 Binds a socket to an address. More...
 
template<typename Address >
void bind (int sockfd, const Address &addr)
 Binds a socket. More...
 
void connect (int sockfd, const struct sockaddr *addr, socklen_t addrlen)
 Connects a socket. More...
 
template<typename Address >
void connect (int sockfd, const Address &addr)
 Connects a socket. More...
 
w::handle< struct ifaddrs *, nullptr, ::freeifaddrs > getifaddrs ()
 Gets a pointer to the head of a linked list of the system's network interfaces. More...
 
int getsockopt (int sockfd, int level, int optname, void *optval=nullptr, socklen_t *optlen=nullptr)
 Gets an option on a socket. More...
 
template<typename Value >
Value getsockopt (int sockfd, int level, int optname)
 Gets an option on a socket. More...
 
unsigned if_nametoindex (const char *ifname)
 Returns the index of the specified network interface. More...
 
char * inet_ntop (int af, const void *src, char *dst, socklen_t size)
 Converts an IPv4 or IPv6 address to a string. More...
 
void * inet_pton (int af, const char *src, void *dst)
 Converts an IPv4 or IPv6 address from a string to a binary value. More...
 
template<typename Address >
Address & inet_pton (int af, const char *src, Address &dst)
 Converts an IPv4 or IPv6 address from a string to a binary value. More...
 
void listen (int sockfd, int backlog)
 Puts a socket in a listening state. More...
 
std::size_t recv (int sockfd, void *buf, std::size_t len, int flags=0)
 Receives a message from a socket. More...
 
std::size_t recvmsg (int sockfd, struct msghdr *msg, int flags=0)
 Receives a message from a socket. More...
 
std::size_t recvfrom (int sockfd, void *buf, std::size_t len, int flags, struct sockaddr *src_addr=nullptr, socklen_t *addrlen=nullptr)
 Receives a message from a socket. More...
 
template<typename Address >
std::size_t recvfrom (int sockfd, void *buf, std::size_t len, int flags, Address &src_addr)
 Receives a message from a socket. More...
 
std::size_t send (int sockfd, const void *buf, std::size_t len, int flags=0)
 Sends a message on a socket. More...
 
std::size_t sendmsg (int sockfd, const struct msghdr *msg, int flags=0)
 Sends a message on a socket. More...
 
std::size_t sendto (int sockfd, const void *buf, std::size_t len, int flags, const struct sockaddr *dest_addr, socklen_t addrlen)
 Sends a message on a socket. More...
 
template<typename Address >
std::size_t sendto (int sockfd, const void *buf, std::size_t len, int flags, const Address &dest_addr)
 Sends a message on a socket. More...
 
int setsockopt (int sockfd, int level, int optname, const void *optval=nullptr, socklen_t optlen=0)
 Sets an option on a socket. More...
 
template<typename Value >
void setsockopt (int sockfd, int level, int optname, const Value &optval)
 Sets an option on a socket. More...
 
void shutdown (int sockfd, int how)
 Shuts down part of a full-duplex connection. More...
 
w::fd socket (int domain, int type, int protocol=0)
 Creates a socket. More...
 

Typedef Documentation

◆ fd

typedef w::handle<int, -1, ::close> w::fd

An RAII util::handle type for POSIX file descriptors.

Function Documentation

◆ accept() [1/2]

template<typename Address >
w::fd w::accept ( int  sockfd,
Address &  addr 
)

Accepts a connection on a socket.

Template Parameters
AddressThe type of addr.
Parameters
sockfdThe socket on which to accept a connection.
addrA reference to the address of the remote endpoint.
Exceptions
std::system_errorAn error occurred.
std::runtime_errorThe structure referenced by addr is not the correct size to hold the remote address.

◆ accept() [2/2]

w::fd w::accept ( int  sockfd,
struct sockaddr *  addr,
socklen_t *  addrlen 
)

Accepts a connection on a socket.

Parameters
sockfdThe socket on which to accept a connection.
addrA pointer to the address of the remote endpoint.
addrlenA pointer to the size of the structure pointed to by addr, in bytes. On return, the value holds the actual size of the source address. This might be larger than the input value, in which case the address was truncated.
Returns
The socket file descriptor of the new connection.
Exceptions
std::system_errorAn error occurred.

◆ bind() [1/2]

template<typename Address >
void w::bind ( int  sockfd,
const Address &  addr 
)

Binds a socket.

Template Parameters
AddressThe type of addr.
Parameters
sockfdThe socket to bind.
addrA reference to the address to bind to.
Exceptions
std::system_errorAn error occurred.

◆ bind() [2/2]

void w::bind ( int  sockfd,
const struct sockaddr *  addr,
socklen_t  addrlen 
)

Binds a socket to an address.

Parameters
sockfdThe socket to bind.
addrA pointer to the address to bind to.
addrlenThe size of the structure pointed to by addr, in bytes.
Exceptions
std::system_errorAn error occurred.

◆ connect() [1/2]

template<typename Address >
void w::connect ( int  sockfd,
const Address &  addr 
)

Connects a socket.

Template Parameters
AddressThe type of addr.
Parameters
sockfdThe socket to connect.
addrA reference to the address to connect to.
Exceptions
std::system_errorAn error occurred.

◆ connect() [2/2]

void w::connect ( int  sockfd,
const struct sockaddr *  addr,
socklen_t  addrlen 
)

Connects a socket.

Parameters
sockfdThe socket to connect.
addrA pointer to the address to connect to.
addrlenThe size of the structure pointed to by addr, in bytes.
Exceptions
std::system_errorAn error occurred.

◆ epoll_create()

w::fd w::epoll_create ( int  size = sizeof(nullptr))

Creates an epoll instance.

Parameters
sizeThis value is ignored, but must be nonzero (see the man page).
Returns
The file descriptor for the epoll instance.
Exceptions
std::system_errorAn error occurred.

◆ epoll_ctl() [1/5]

void w::epoll_ctl ( int  epfd,
int  op,
int  fd,
std::uint32_t  events,
int  user_data 
)

Manipulates an epoll instance.

Parameters
epfdThe epoll instance file descriptor.
opThe operation to perform.
fdThe file descriptor to add, modify or remove from the poll instance.
eventsA bitwise combination of events of interest.
user_dataAn opaque user data value.
Exceptions
std::system_errorAn error occurred.

◆ epoll_ctl() [2/5]

void w::epoll_ctl ( int  epfd,
int  op,
int  fd,
std::uint32_t  events,
std::uint32_t  user_data 
)

Manipulates an epoll instance.

Parameters
epfdThe epoll instance file descriptor.
opThe operation to perform.
fdThe file descriptor to add, modify or remove from the poll instance.
eventsA bitwise combination of events of interest.
user_dataAn opaque user data value.
Exceptions
std::system_errorAn error occurred.

◆ epoll_ctl() [3/5]

void w::epoll_ctl ( int  epfd,
int  op,
int  fd,
std::uint32_t  events,
std::uint64_t  user_data 
)

Manipulates an epoll instance.

Parameters
epfdThe epoll instance file descriptor.
opThe operation to perform.
fdThe file descriptor to add, modify or remove from the poll instance.
eventsA bitwise combination of events of interest.
user_dataAn opaque user data value.
Exceptions
std::system_errorAn error occurred.

◆ epoll_ctl() [4/5]

void w::epoll_ctl ( int  epfd,
int  op,
int  fd,
std::uint32_t  events,
void *  user_data = nullptr 
)

Manipulates an epoll instance.

Parameters
epfdThe epoll instance file descriptor.
opThe operation to perform.
fdThe file descriptor to add, modify or remove from the poll instance.
eventsA bitwise combination of events of interest.
user_dataAn opaque user data value.
Exceptions
std::system_errorAn error occurred.

◆ epoll_ctl() [5/5]

void w::epoll_ctl ( int  epfd,
int  op,
int  fd,
struct epoll_event *  event = nullptr 
)

Manipulates an epoll instance.

Parameters
epfdThe epoll instance file descriptor.
opThe operation to perform.
fdThe file descriptor to add, modify or remove from the poll instance.
eventA pointer to a structure specifying the events of interest.
Exceptions
std::system_errorAn error occurred.

◆ epoll_wait()

unsigned w::epoll_wait ( int  epfd,
struct epoll_event *  events,
int  maxevents,
std::chrono::milliseconds  timeout = std::chrono::milliseconds(-1) 
)

Waits for events to occur on an epoll instance.

Parameters
epfdThe epoll instance file descriptor.
eventsA pointer to an array of structures to receive information about events.
maxeventsThe number of elements in the events array.
timeoutThe number of milliseconds
Returns
The number of events that occurred, which may be zero.
Exceptions
std::invalid_argumenttimeout is out of range.
std::system_errorAn error occurred.

◆ eventfd()

w::fd w::eventfd ( unsigned  initval = 0,
int  flags = 0 
)

Creates an event file descriptor.

Parameters
initvalThe initial value of the eventfd counter.
flagsFlags that affect the created event file descriptor.

◆ eventfd_read()

std::uint64_t w::eventfd_read ( int  evfd)

Reads the current counter value of an event file descriptor; see the man page of eventfd() for a description of the counter and blocking semantics.

Parameters
evfdThe event file descriptor.
Returns
The event counter value.
Exceptions
std::system_errorAn error occurred.

◆ eventfd_write()

void w::eventfd_write ( int  evfd,
std::uint64_t  value 
)

Modifies the counter value of an event file descriptor; see the man page of eventfd() for a description of the counter semantics.

Parameters
evfdThe event file descriptor.
valueThe event counter value.
Exceptions
std::system_errorAn error occurred.

◆ fcntl() [1/2]

int w::fcntl ( int  fd,
int  cmd 
)

Controls a file descriptor.

Parameters
fdThe file descriptor to control.
cmdThe control command code.
Returns
A result code from the command.
Exceptions
std:system_errorAn error occurred.

◆ fcntl() [2/2]

template<typename Argument >
int w::fcntl ( int  fd,
int  cmd,
const Argument &  arg 
)

Controls a file descriptor.

Template Parameters
ArgumentThe type of the command-specific argument.
Parameters
fdThe file descriptor to control.
cmdThe control command code.
argA reference to a command-specific input argument.
Returns
A result code from the command.
Exceptions
std:system_errorAn error occurred.

◆ getifaddrs()

w::handle< struct ifaddrs *, nullptr,::freeifaddrs > w::getifaddrs ( )

Gets a pointer to the head of a linked list of the system's network interfaces.

Returns
A pointer to the head of a linked list of the system's network interfaces.
Exceptions
std::system_errorAn error occurred.

◆ getsockopt() [1/2]

template<typename Value >
Value w::getsockopt ( int  sockfd,
int  level,
int  optname 
)

Gets an option on a socket.

Parameters
sockfdThe socket on which to get the option.
levelThe option level.
optnameThe option to get.
Returns
The value returned for the option.
Exceptions
std::system_errorAn error occurred.
std::runtime_errorValue has the wrong size for this option.

◆ getsockopt() [2/2]

int w::getsockopt ( int  sockfd,
int  level,
int  optname,
void *  optval = nullptr,
socklen_t *  optlen = nullptr 
)

Gets an option on a socket.

Parameters
sockfdThe socket on which to get the option.
levelThe option level.
optnameThe option to get.
optvalA pointer to the value to be filled in.
optlenA pointer to the size of the value pointed to by optval. On return, the value holds the actual size of the value. This might be larger than the input value, in which case the value was truncated.
Returns
The return value of the option (which cannot be -1).
Exceptions
std::system_errorAn error occurred.

◆ if_nametoindex()

unsigned w::if_nametoindex ( const char *  ifname)

Returns the index of the specified network interface.

Parameters
ifnameThe name of the network interface.
Returns
The nonzero index of the network interface.
Exceptions
std::system_errorAn error occurred.

◆ inet_ntop()

char * w::inet_ntop ( int  af,
const void *  src,
char *  dst,
socklen_t  size 
)

Converts an IPv4 or IPv6 address to a string.

Parameters
afThe address family.
srcA pointer to the address.
dstA pointer to a character buffer to be filled.
sizeThe size of the buffer pointed to by dst, in bytes.
Returns
dst.
Exceptions
std::system_errorAn error occurred.

◆ inet_pton() [1/2]

template<typename Address >
Address & w::inet_pton ( int  af,
const char *  src,
Address &  dst 
)

Converts an IPv4 or IPv6 address from a string to a binary value.

Parameters
afThe address family.
srcA pointer to the address string.
dstA reference to a socket address structure to be filled.
Returns
dst.
Exceptions
std::system_errorAn error occurred.

◆ inet_pton() [2/2]

void * w::inet_pton ( int  af,
const char *  src,
void *  dst 
)

Converts an IPv4 or IPv6 address from a string to a binary value.

Parameters
afThe address family.
srcA pointer to the address string.
dstA pointer to a socket address structure to be filled.
Returns
dst.
Exceptions
std::system_errorAn error occurred.

◆ ioctl() [1/5]

template<typename Argument >
Argument w::ioctl ( int  fd,
unsigned long  request 
)

Controls a device.

Template Parameters
ArgumentThe type of the request's output value.
Parameters
fdThe file descriptor of the device to control.
requestThe control request code.
Returns
The output value.
Exceptions
std:system_errorAn error occurred.

◆ ioctl() [2/5]

template<typename Argument >
int w::ioctl ( int  fd,
unsigned long  request,
Argument &  arg 
)

Controls a device.

Template Parameters
ArgumentThe type of arg.
Parameters
fdThe file descriptor of the device to control.
requestThe control request code.
argA pointer to a request-specific input argument.
Returns
A nonnegative result code from the control request.
Exceptions
std:system_errorAn error occurred.

◆ ioctl() [3/5]

template<typename Argument >
int w::ioctl ( int  fd,
unsigned long  request,
const Argument &  arg 
)

Controls a device.

Note that the library cannot guarantee the underlying ioctl call will not modify its argument. Therefore, when using this overload, it is the caller's responsibility to somehow ensure the ioctl does not modify its argument, or the behavior is undefined.

Template Parameters
ArgumentThe type of arg.
Parameters
fdThe file descriptor of the device to control.
requestThe control request code.
argA pointer to a request-specific input argument.
Returns
A nonnegative result code from the control request.
Exceptions
std:system_errorAn error occurred.

◆ ioctl() [4/5]

int w::ioctl ( int  fd,
unsigned long  request,
const void *  arg 
)

Controls a device.

Note that the library cannot guarantee the underlying ioctl call will not modify its argument. Therefore, when using this overload, it is the caller's responsibility to somehow ensure the ioctl does not modify its argument, or the behavior is undefined.

Parameters
fdThe file descriptor of the device to control.
requestThe control request code.
argA pointer to a request-specific input argument.
Returns
A nonnegative result code from the control request.
Exceptions
std:system_errorAn error occurred.

◆ ioctl() [5/5]

int w::ioctl ( int  fd,
unsigned long  request,
void *  arg 
)

Controls a device.

Parameters
fdThe file descriptor of the device to control.
requestThe control request code.
argA pointer to a request-specific output argument.
Returns
A nonnegative result code from the control request.
Exceptions
std:system_errorAn error occurred.

◆ listen()

void w::listen ( int  sockfd,
int  backlog 
)

Puts a socket in a listening state.

Parameters
sockfdThe socket to listen on.
backlogThe maximum number of pending connections to allow.
Exceptions
std::system_errorAn error occurred.

◆ lseek()

std::size_t w::lseek ( int  fd,
off_t  offset,
int  whence 
)

Sets the position of a file pointer for a file descriptor.

Parameters
fdThe file descriptor to seek in.
offsetThe offset to seek to.
whenceSEEK_SET, SEEK_CUR or SEEK_END.
Returns
The new offset relative to the beginning of the file.
Exceptions
std::system_errorAn error occurred.

◆ open() [1/2]

w::fd w::open ( const char *  pathname,
int  flags 
)

Opens and possibly creates a file.

Parameters
pathnameThe path of the file to open and/or create.
flagsA bitwise combination of flags.
Returns
A file descriptor for the opened file.
Exceptions
std:system_errorAn error occurred.

◆ open() [2/2]

w::fd w::open ( const char *  pathname,
int  flags,
mode_t  mode 
)

Opens and possibly creates a file.

Parameters
pathnameThe path of the file to open and/or create.
flagsA bitwise combination of flags.
modeThe access mode for the file.
Returns
A file descriptor for the opened file.
Exceptions
std:system_errorAn error occurred.

◆ pipe()

std::pair< w::fd, w::fd > w::pipe ( )

Creates a pipe.

Returns
A pair of file descriptors for the read and write ends of the pipe, respectively.
Exceptions
std:system_errorAn error occurred.

◆ read()

std::size_t w::read ( int  fd,
void *  buf,
std::size_t  count 
)

Reads data from a file descriptor.

Parameters
fdThe file descriptor to read from.
bufA pointer to an array where read data should be stored.
countThe maximum number of bytes to read.
Returns
The number of bytes actually read, which may be zero.
Exceptions
std::system_errorAn error occurred. This includes EAGAIN on non-blocking files.

◆ readv()

std::size_t w::readv ( int  fd,
const struct iovec *  iov,
int  iovcnt 
)

Reads data from a file descriptor.

Parameters
fdThe file descriptor to read from.
iovA pointer to an array of iovec scatter-gather structures.
iovcntThe number of structures in the array pointed to by iov.
Returns
The number of bytes actually read, which may be zero.
Exceptions
std::system_errorAn error occurred. This includes EAGAIN on non-blocking files.

◆ recv()

std::size_t w::recv ( int  sockfd,
void *  buf,
std::size_t  len,
int  flags = 0 
)

Receives a message from a socket.

Parameters
sockfdThe socket to receive from.
bufA pointer to an array where received data should be stored.
lenThe maximum number of bytes to receive.
flagsA bitwise combination of flags.
Returns
The number of bytes successfully received (which may be zero).
Exceptions
std::system_errorAn error occurred. This includes EAGAIN on non-blocking sockets.

◆ recvfrom() [1/2]

template<typename Address >
std::size_t w::recvfrom ( int  sockfd,
void *  buf,
std::size_t  len,
int  flags,
Address &  src_addr 
)

Receives a message from a socket.

Template Parameters
AddressThe type of src_addr.
Parameters
sockfdThe socket to receive from.
bufA pointer to an array where received data should be stored.
lenThe maximum number of bytes to receive.
flagsA bitwise combination of flags.
src_addrA reference to the source address.
Returns
The number of bytes successfully received (which may be zero).
Exceptions
std::system_errorAn error occurred. This includes EAGAIN on non-blocking sockets.
std::runtime_errorThe structure referenced by src_addr is not the correct size to hold the source address.

◆ recvfrom() [2/2]

std::size_t w::recvfrom ( int  sockfd,
void *  buf,
std::size_t  len,
int  flags,
struct sockaddr *  src_addr = nullptr,
socklen_t *  addrlen = nullptr 
)

Receives a message from a socket.

Parameters
sockfdThe socket to receive from.
bufA pointer to an array where received data should be stored.
lenThe maximum number of bytes to receive.
flagsA bitwise combination of flags.
src_addrA pointer to the source address.
addrlenA pointer to the size of the structure pointed to by src_addr, in bytes. On return, the value holds the actual size of the source address. This might be larger than the input value, in which case the address was truncated.
Returns
The number of bytes successfully received (which may be zero).
Exceptions
std::system_errorAn error occurred. This includes EAGAIN on non-blocking sockets.
std::runtime_errorThe structure pointed to by src_addr is too small to hold the source address.

◆ recvmsg()

std::size_t w::recvmsg ( int  sockfd,
struct msghdr *  msg,
int  flags = 0 
)

Receives a message from a socket.

Parameters
sockfdThe socket to receive from.
msgA pointer to a message structure to be filled in.
flagsA bitwise combination of flags.
Returns
The number of bytes successfully received (which may be zero).
Exceptions
std::system_errorAn error occurred. This includes EAGAIN on non-blocking sockets.

◆ send()

std::size_t w::send ( int  sockfd,
const void *  buf,
std::size_t  len,
int  flags = 0 
)

Sends a message on a socket.

Parameters
sockfdThe socket to send from.
bufA pointer to the data to send.
lenThe maximum number of bytes to send.
flagsA bitwise combination of flags.
Returns
The number of bytes successfully accepted for transmission (which may be zero).
Exceptions
std::system_errorAn error occurred. This includes EAGAIN on non-blocking sockets.

◆ sendmsg()

std::size_t w::sendmsg ( int  sockfd,
const struct msghdr *  msg,
int  flags = 0 
)

Sends a message on a socket.

Parameters
sockfdThe socket to send from.
msgA pointer to a message structure describing the message to send.
flagsA bitwise combination of flags.
Returns
The number of bytes successfully accepted for transmission (which may be zero).
Exceptions
std::system_errorAn error occurred. This includes EAGAIN on non-blocking sockets.

◆ sendto() [1/2]

template<typename Address >
std::size_t w::sendto ( int  sockfd,
const void *  buf,
std::size_t  len,
int  flags,
const Address &  dest_addr 
)

Sends a message on a socket.

Template Parameters
AddressThe type of dest_addr.
Parameters
sockfdThe socket to send from.
bufA pointer to the data to send.
lenThe number of bytes to send.
flagsA bitwise combination of flags.
dest_addrA reference to the destination address.
Returns
The number of bytes successfully accepted for transmission (which may be zero).
Exceptions
std::system_errorAn error occurred. This includes EAGAIN on non-blocking sockets.

◆ sendto() [2/2]

std::size_t w::sendto ( int  sockfd,
const void *  buf,
std::size_t  len,
int  flags,
const struct sockaddr *  dest_addr,
socklen_t  addrlen 
)

Sends a message on a socket.

Parameters
sockfdThe socket to send from.
bufA pointer to the data to send.
lenThe maximum number of bytes to send.
flagsA bitwise combination of flags.
dest_addrA pointer to the destination address.
addrlenThe size of the structure pointed to by dest_addr, in bytes.
Returns
The number of bytes successfully accepted for transmission (which may be zero).
Exceptions
std::system_errorAn error occurred. This includes EAGAIN on non-blocking sockets.

◆ setsockopt() [1/2]

template<typename Value >
void w::setsockopt ( int  sockfd,
int  level,
int  optname,
const Value &  optval 
)

Sets an option on a socket.

Template Parameters
ValueThe type of optval.
Parameters
sockfdThe socket on which to set the option.
levelThe option level.
optnameThe option to set.
optvalA reference to the value to set.
Exceptions
std::system_errorAn error occurred.

◆ setsockopt() [2/2]

int w::setsockopt ( int  sockfd,
int  level,
int  optname,
const void *  optval = nullptr,
socklen_t  optlen = 0 
)

Sets an option on a socket.

Parameters
sockfdThe socket on which to set the option.
levelThe option level.
optnameThe option to set.
optvalA pointer to the value to set.
optlenThe size of the value pointed to by optval, in bytes.
Returns
The return value of the option (which cannot be -1).
Exceptions
std::system_errorAn error occurred.

◆ shutdown()

void w::shutdown ( int  sockfd,
int  how 
)

Shuts down part of a full-duplex connection.

Parameters
sockfdThe socket to shut down.
howA flag specifying what to shut down.
Exceptions
std::system_errorAn error occurred.

◆ socket()

w::fd w::socket ( int  domain,
int  type,
int  protocol = 0 
)

Creates a socket.

Parameters
domainThe communication domain.
typeThe type of socket.
protocolThe protocol on which to communicate.
Returns
The created socket.
Exceptions
std::system_errorAn error occurred.

◆ throw_if_eq()

template<typename T >
T w::throw_if_eq ( value,
x,
const char *  message 
)

Throw a std::system_error with errno if value == x, otherwise return value.

Template Parameters
TThe type of value and x.
Parameters
valueThe value to check.
xThe value to test for.
messageThe message to include in the exception.
Returns
value.
Exceptions
std::system_errorvalue == x. The error code is set to errno.

◆ throw_if_lt()

template<typename T >
T w::throw_if_lt ( value,
x,
const char *  message 
)

Throw a std::system_error with errno if value < x, otherwise return value.

Template Parameters
TThe type of value and x.
Parameters
valueThe value to check.
xThe value to test for.
messageThe message to include in the exception.
Returns
value.
Exceptions
std::system_errorvalue < x. The error code is set to errno.

◆ throw_if_ne()

template<typename T >
T w::throw_if_ne ( value,
x,
const char *  message 
)

Throw a std::system_error with errno if value != x, otherwise return value.

Template Parameters
TThe type of value and x.
Parameters
valueThe value to check.
xThe value to test for.
messageThe message to include in the exception.
Returns
value.
Exceptions
std::system_errorvalue != x. The error code is set to errno.

◆ throw_if_nz()

template<typename T >
T w::throw_if_nz ( value,
const char *  message 
)

Throw a std::system_error with errno if value != 0, otherwise return value.

Template Parameters
TThe type of value.
Parameters
valueThe value to check.
messageThe message to include in the exception.
Returns
value.
Exceptions
std::system_errorvalue != 0. The error code is set to errno.

◆ throw_if_z()

template<typename T >
T w::throw_if_z ( value,
const char *  message 
)

Throw a std::system_error with errno if value == 0, otherwise return value.

Template Parameters
TThe type of value.
Parameters
valueThe value to check.
messageThe message to include in the exception.
Returns
value.
Exceptions
std::system_errorvalue == 0. The error code is set to errno.

◆ timerfd_create()

w::fd w::timerfd_create ( int  clockid,
int  flags = 0 
)

Creates a timer file descriptor.

Parameters
clockidThe identifier of the clock on which the timer should be based.
flagsA bitwise combination of flags.
Returns
The file descriptor for the created timer.
Exceptions
std::system_errorAn error occurred.

◆ timerfd_settime() [1/2]

void w::timerfd_settime ( int  fd,
int  flags,
const struct itimerspec *  new_value,
struct itimerspec *  old_value 
)

Sets the timeout and repetition interval of a timer file descriptor.

Parameters
fdThe timer file descriptor to adjust.
flagsA bitwise combination of flags.
new_valueA pointer to a structure containing the repetition interval and initial expiration time.
old_valueA pointer to a structure to be filled in with the previous repetition interval and expiration time.
Exceptions
std::system_errorAn error occurred.

◆ timerfd_settime() [2/2]

std::pair< std::chrono::nanoseconds, std::chrono::nanoseconds > w::timerfd_settime ( int  fd,
int  flags,
std::chrono::nanoseconds  interval,
std::chrono::nanoseconds  initial 
)

Sets the timeout and repetition interval of a timer file descriptor.

Parameters
fdThe timer file descriptor to adjust.
flagsA bitwise combination of flags.
intervalThe repetition interval.
initialThe initial expiration time.
Returns
A pair consisting of the previous repetition interval and initial expiration time, in that order.
Exceptions
std::system_errorAn error occurred.

◆ write()

std::size_t w::write ( int  fd,
const void *  buf,
std::size_t  count 
)

Writes data to a file descriptor.

Parameters
fdThe file descriptor to write to.
bufA pointer to an array of data to write.
countThe maximum number of bytes to write.
Returns
The number of bytes actually written, which may be zero.
Exceptions
std::system_errorAn error occurred. This includes EAGAIN on non-blocking files.

◆ writev()

std::size_t w::writev ( int  fd,
const struct iovec *  iov,
int  iovcnt 
)

Writes data to a file descriptor.

Parameters
fdThe file descriptor to write to.
iovA pointer to an array of iovec scatter-gather structures.
iovcntThe number of structures in the array pointed to by iov.
Returns
The number of bytes actually written, which may be zero.
Exceptions
std::system_errorAn error occurred. This includes EAGAIN on non-blocking files.