21 #ifndef XAPIAN_INCLUDED_REMOTECONNECTION_H
22 #define XAPIAN_INCLUDED_REMOTECONNECTION_H
49 struct WinsockInitializer {
50 WinsockInitializer() {
52 int wsaerror = WSAStartup(MAKEWORD(2, 2), &wsadata);
61 ~WinsockInitializer() {
75 int wsa_err = WSAGetLastError();
78 case WSAEADDRINUSE:
return EADDRINUSE;
81 case WSAETIMEDOUT:
return ETIMEDOUT;
84 case WSAEINPROGRESS:
return EINPROGRESS;
86 default:
return wsa_err;
94 # define EADDRINUSE WSAEADDRINUSE
97 # define ETIMEDOUT WSAETIMEDOUT
100 # define EINPROGRESS WSAEINPROGRESS
105 # define CLOSESOCKET(S) closesocket(S)
110 # define CLOSESOCKET(S) close(S)
120 #define C(X) ((X) < 0 ? 2 : 1)
134 #ifdef EAI_ADDRFAMILY
207 # if defined(SO_NOSIGPIPE) && !defined(__NetBSD__)
210 # define USE_SO_NOSIGPIPE
211 # elif defined MSG_NOSIGNAL
213 int send_flags = MSG_NOSIGNAL;
214 # define USE_MSG_NOSIGNAL
245 WSAOVERLAPPED overlapped;
251 DWORD calc_read_wait_msecs(
double end_time);
267 const std::string & context_ = std::string());
407 const std::string& context_ = std::string())
RemoteConnection which owns its own fd(s).
OwnedRemoteConnection(int fdin_, int fdout_, const std::string &context_=std::string())
Constructor.
~OwnedRemoteConnection()
Destructor.
A RemoteConnection object provides a bidirectional connection to another RemoteConnection object on a...
bool ready_to_read() const
See if there is data available to read.
int fdin
The file descriptor used for reading.
std::string buffer
Buffer to hold unprocessed input.
RemoteConnection(const RemoteConnection &)
Don't allow copying.
int get_message_chunk(std::string &result, size_t at_least, double end_time)
Read a chunk of a message from fdin.
void send_message(char type, const std::string &s, double end_time)
Send a message.
bool read_at_least(size_t min_len, double end_time)
Read until there are at least min_len bytes in buffer.
int fdout
The file descriptor used for writing.
int receive_file(const std::string &file, double end_time)
Save the contents of a message as a file.
off_t chunked_data_left
Remaining bytes of message data still to come over fdin for a chunked read.
void do_close()
Close the connection.
int get_message(std::string &result, double end_time)
Read one message from fdin.
void shutdown()
Shutdown the connection.
int sniff_next_message_type(double end_time)
Check what the next message type is.
int get_message_chunked(double end_time)
Prepare to read one message from fdin in chunks.
std::string context
The context to report with errors.
ssize_t send_or_write(const void *p, size_t n)
Helper which calls send() or write().
void operator=(const RemoteConnection &)
Don't allow assignment.
void send_file(char type, int fd, double end_time)
Send the contents of a file as a message.
Indicates a problem communicating with a remote database.
Hierarchy of classes which Xapian can throw as exceptions.
double end_time(double timeout)
Return the end time for a timeout in timeout seconds.
Remote protocol version and message numbers.
include <netdb.h>, with portability workarounds.
include <sys/socket.h> with portability workarounds.
<unistd.h>, but with compat.
include <winsock2.h> but working around problems.