xdrpp
RFC4506 XDR compiler and message library
Classes | Namespaces | Typedefs | Functions | Variables
socket.h File Reference

Simplified support for creating sockets. More...

#include <memory>
#include <system_error>
#include <netdb.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/uio.h>
#include <netinet/in.h>
Include dependency graph for socket.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  xdr::sock_t
 Abstract away the type of a socket (for windows). More...
 
struct  std::hash< xdr::sock_t >
 
struct  xdr::delete_addrinfo
 A deleter to use std::unique_ptr with addrinfo structures (which must be freed recursively). More...
 
class  xdr::unique_sock
 Self-closing socket. More...
 

Namespaces

 xdr
 Most of the xdrpp library is encapsulated in the xdr namespace.
 

Typedefs

using xdr::unique_addrinfo = std::unique_ptr< addrinfo, delete_addrinfo >
 Automatically garbage-collected addrinfo pointer.
 

Functions

bool xdr::sock_eagain ()
 Returns true if the most recent (socket) error is a temporary error, such as EAGAIN, EWOULDBLOCK, or EINTR. More...
 
const char * xdr::sock_errmsg ()
 Last socket error message (strerror(errno) on POSIX).
 
void xdr::throw_sockerr (const char *)
 Throw a system_error exception for the last socket error.
 
ssize_t xdr::read (sock_t s, void *buf, std::size_t count)
 
ssize_t xdr::write (sock_t s, const void *buf, std::size_t count)
 
ssize_t xdr::readv (sock_t s, const struct iovec *iov, int iovcnt)
 
ssize_t xdr::writev (sock_t s, const struct iovec *iov, int iovcnt)
 
void xdr::close (sock_t s)
 
void xdr::set_nonblock (sock_t s)
 Set the O_NONBLOCK flag on a socket. More...
 
void xdr::set_close_on_exec (sock_t s)
 Set the close-on-exec flag of a file descriptor. More...
 
sock_t xdr::accept (sock_t s, sockaddr *addr, socklen_t *addrlen)
 Wrapper around accept for sock_t.
 
void xdr::create_selfpipe (sock_t ss[2])
 Create a socket (or pipe on unix, where both are file descriptors) that is connected to itself. More...
 
const std::error_category & xdr::gai_category ()
 Category for system errors dealing with DNS (getaddrinfo, etc.).
 
unique_addrinfo xdr::get_addrinfo (const char *host, int socktype=SOCK_STREAM, const char *service=nullptr, int family=AF_UNSPEC)
 Wrapper around getaddrinfo that returns a garbage-collected xdr::unique_addrinfo. More...
 
void xdr::get_numinfo (const sockaddr *sa, socklen_t salen, std::string *host, std::string *serv)
 Return printable versions of numeric host and port number.
 
unique_sock xdr::tcp_connect1 (const addrinfo *ai, bool ndelay=false)
 Try connecting to the first addrinfo in a linked list.
 
unique_sock xdr::tcp_connect (const addrinfo *ai)
 Try connecting to every addrinfo in a list until one succeeds.
 
unique_sock xdr::tcp_connect (const unique_addrinfo &ai)
 
unique_sock xdr::tcp_connect (const char *host, const char *service, int family)
 
unique_sock xdr::tcp_listen (const char *service="0", int family=AF_UNSPEC, int backlog=5)
 Create bind a listening TCP socket.
 

Variables

constexpr sock_t xdr::invalid_sock {}
 

Detailed Description

Simplified support for creating sockets.

Definition in file socket.h.