21 #ifndef XAPIAN_INCLUDED_SAFESYSSOCKET_H 22 #define XAPIAN_INCLUDED_SAFESYSSOCKET_H 26 # include <sys/types.h> 27 # include <sys/socket.h> 33 # include <type_traits> 35 # if defined SOCK_CLOEXEC 36 static_assert(!
SOCK_CLOEXEC,
"__WIN32__ doesn't support SOCK_CLOEXEC");
38 # define SOCK_CLOEXEC 0 40 static_assert(std::is_unsigned<SOCKET>::value,
"SOCKET is unsigned");
42 inline int socket_(
int domain,
int type,
int protocol) {
55 SOCKET sock = socket(domain, type, protocol);
56 if (
rare(sock > SOCKET(0x7fffffff) && sock != INVALID_SOCKET)) {
65 # define socket(D,T,P) socket_(D,T,P) 67 inline int accept_(
int sockfd,
struct sockaddr* addr,
SOCKLEN_T* addrlen) {
80 SOCKET sock = accept(sockfd, addr, addrlen);
81 if (
rare(sock > SOCKET(0x7fffffff) && sock != INVALID_SOCKET)) {
90 # define accept(S,A,L) accept_(S,A,L) 92 #elif !defined SOCK_CLOEXEC 93 # define SOCK_CLOEXEC 0 100 inline int socket_(
int domain,
int type,
int protocol) {
104 int save_errno = errno;
105 int r = socket(domain, type, protocol);
106 if (r < 0 && errno == EINVAL) {
108 r = socket(domain, type &~ SOCK_CLOEXEC, protocol);
112 return socket(domain, type, protocol);
116 inline int socketpair_(
int domain,
int type,
int protocol,
int *sv) {
120 int save_errno = errno;
121 int r = socketpair(domain, type, protocol, sv);
122 if (r != 0 && errno == EINVAL) {
124 r = socketpair(domain, type &~ SOCK_CLOEXEC, protocol, sv);
128 return socketpair(domain, type, protocol, sv);
135 # define socket(D,T,P) socket_(D,T,P) 139 # define socketpair(D,T,P,S) socketpair_(D,T,P,S) 142 #endif // XAPIAN_INCLUDED_SAFESYSSOCKET_H
Hierarchy of classes which Xapian can throw as exceptions.
include <winsock2.h> but working around problems.
Indicates a problem communicating with a remote database.