xapian-core  2.0.0
Macros | Functions | Variables
socket_utils.h File Reference

Socket handling utilities. More...

#include "safenetdb.h"
#include "safeunistd.h"
#include <cerrno>
#include <arpa/inet.h>
+ Include dependency graph for socket_utils.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define CLOSESOCKET(S)   close(S)
 

Functions

void close_fd_or_socket (int fd)
 
int socket_errno ()
 
void set_socket_timeouts (int fd, double timeout)
 Attempt to set socket-level timeouts. More...
 
int pretty_ip6 (const void *p, char *buf)
 

Variables

constexpr size_t PRETTY_IP6_LEN
 

Detailed Description

Socket handling utilities.

Definition in file socket_utils.h.

Macro Definition Documentation

◆ CLOSESOCKET

#define CLOSESOCKET (   S)    close(S)

Definition at line 123 of file socket_utils.h.

Function Documentation

◆ close_fd_or_socket()

void close_fd_or_socket ( int  fd)
inline

Definition at line 119 of file socket_utils.h.

References close().

Referenced by RemoteConnection::do_close().

◆ pretty_ip6()

int pretty_ip6 ( const void *  p,
char *  buf 
)

Definition at line 113 of file socket_utils.cc.

References if(), p, PRETTY_IP6_LEN, and startswith().

◆ set_socket_timeouts()

void set_socket_timeouts ( int  fd,
double  timeout 
)

Attempt to set socket-level timeouts.

These aren't supported by all platforms, and some platforms allow them to set but ignore them, so we can't easily report failure.

Also sets SO_KEEPALIVE (if supported), which should ensure a stuck connection will eventually time out, though it may take up to ~2 hours.

Definition at line 69 of file socket_utils.cc.

References RealTime::to_timeval(), and usual.

◆ socket_errno()

int socket_errno ( )
inline

Variable Documentation

◆ PRETTY_IP6_LEN

constexpr size_t PRETTY_IP6_LEN
constexpr
Initial value:
=
(INET6_ADDRSTRLEN > INET_ADDRSTRLEN ? INET6_ADDRSTRLEN : INET_ADDRSTRLEN)

Definition at line 137 of file socket_utils.h.

Referenced by pretty_ip6().