xapian-core  2.0.0
Public Member Functions | Private Member Functions | Private Attributes | List of all members
RemoteServer Class Reference

Remote backend server base class. More...

#include <remoteserver.h>

+ Inheritance diagram for RemoteServer:
+ Collaboration diagram for RemoteServer:

Public Member Functions

 RemoteServer (const std::vector< std::string > &dbpaths, int fdin, int fdout, double active_timeout_, double idle_timeout_, bool writable=false)
 Construct a RemoteServer. More...
 
 ~RemoteServer ()
 Destructor. More...
 
void run ()
 Repeatedly accept messages from the client and process them. More...
 
void set_registry (const Xapian::Registry &reg_)
 Set the registry used for (un)serialisation. More...
 

Private Member Functions

void operator= (const RemoteServer &)
 Don't allow assignment. More...
 
 RemoteServer (const RemoteServer &)
 Don't allow copying. More...
 
message_type get_message (double timeout, std::string &result, message_type required_type=MSG_MAX)
 Accept a message from the client. More...
 
void send_message (reply_type type, std::string_view message)
 Send a message to the client. More...
 
void send_message (reply_type type, std::string_view message, double end_time)
 Send a message to the client, with specific end_time. More...
 
void msg_allterms (const std::string &message)
 
void msg_document (const std::string &message)
 
void msg_termexists (const std::string &message)
 
void msg_collfreq (const std::string &message)
 
void msg_termfreq (const std::string &message)
 
void msg_freqs (const std::string &message)
 
void msg_valuestats (const std::string &message)
 
void msg_keepalive (const std::string &message)
 
void msg_doclength (const std::string &message)
 
void msg_query (const std::string &message)
 
void msg_termlist (const std::string &message)
 
void msg_postlist (const std::string &message)
 
void msg_positionlist (const std::string &message)
 
void msg_positionlistcount (const std::string &message)
 
void msg_writeaccess (const std::string &message)
 
void msg_reopen (const std::string &message)
 
void msg_update (const std::string &message)
 
void msg_commit (const std::string &message)
 
void msg_cancel (const std::string &message)
 
void msg_adddocument (const std::string &message)
 
void msg_deletedocument (const std::string &message)
 
void msg_deletedocumentterm (const std::string &message)
 
void msg_replacedocument (const std::string &message)
 
void msg_replacedocumentterm (const std::string &message)
 
void msg_getmetadata (const std::string &message)
 
void msg_metadatakeylist (const std::string &message)
 
void msg_setmetadata (const std::string &message)
 
void msg_requestdocument (const std::string &message)
 
void msg_addspelling (const std::string &message)
 
void msg_removespelling (const std::string &message)
 
void msg_uniqueterms (const std::string &message)
 
void msg_wdfdocmax (const std::string &message)
 
void msg_reconstructtext (const std::string &message)
 
void msg_synonymtermlist (const std::string &message)
 
void msg_synonymkeylist (const std::string &message)
 
void msg_addsynonym (const std::string &message)
 
void msg_removesynonym (const std::string &message)
 
void msg_clearsynonyms (const std::string &message)
 
- Private Member Functions inherited from RemoteConnection
 RemoteConnection (int fdin_, int fdout_, const std::string &context_=std::string())
 Constructor. More...
 
int get_read_fd () const
 Return the underlying fd this remote connection reads from. More...
 
int sniff_next_message_type (double end_time)
 Check what the next message type is. More...
 
int get_message (std::string &result, double end_time)
 Read one message from fdin. More...
 
int get_message_chunked (double end_time)
 Prepare to read one message from fdin in chunks. More...
 
int get_message_chunk (std::string &result, size_t at_least, double end_time)
 Read a chunk of a message from fdin. More...
 
int receive_file (const std::string &file, double end_time)
 Save the contents of a message as a file. More...
 
void send_message (char type, std::string_view s, double end_time)
 Send a message. More...
 
void send_file (char type, int fd, double end_time)
 Send the contents of a file as a message. More...
 
void shutdown ()
 Shutdown the connection. More...
 
void do_close ()
 Close the connection. More...
 
const std::string & get_context () const
 Return the context to report with errors. More...
 

Private Attributes

Xapian::Databasedb = nullptr
 The database we're using. More...
 
Xapian::WritableDatabasewdb = nullptr
 The WritableDatabase we're using, or NULL if we're read-only. More...
 
bool writable
 Do we support writing? More...
 
double active_timeout
 Timeout for actions during a conversation. More...
 
double idle_timeout
 Timeout while waiting for a new action from the client. More...
 
Xapian::Registry reg
 The registry, which allows unserialisation of user subclasses. More...
 
- Private Attributes inherited from RemoteConnection
std::string context
 The context to report with errors. More...
 

Detailed Description

Remote backend server base class.

Definition at line 36 of file remoteserver.h.

Constructor & Destructor Documentation

◆ RemoteServer() [1/2]

RemoteServer::RemoteServer ( const RemoteServer )
private

Don't allow copying.

◆ RemoteServer() [2/2]

RemoteServer::RemoteServer ( const std::vector< std::string > &  dbpaths,
int  fdin,
int  fdout,
double  active_timeout_,
double  idle_timeout_,
bool  writable = false 
)

Construct a RemoteServer.

Parameters
dbpathsThe paths to the Xapian databases to use.
fdinThe file descriptor to read from.
fdoutThe file descriptor to write to (fdin and fdout may be the same).
active_timeout_Timeout for actions during a conversation (specified in seconds).
idle_timeout_Timeout while waiting for a new action from the client (specified in seconds).
writableShould the database be opened for writing?

Definition at line 64 of file remoteserver.cc.

References Xapian::Database::add_database(), Assert, RemoteConnection::context, db, msg_update(), REPLY_EXCEPTION, send_message(), and serialise_error().

◆ ~RemoteServer()

RemoteServer::~RemoteServer ( )

Destructor.

Definition at line 113 of file remoteserver.cc.

References db.

Member Function Documentation

◆ get_message()

message_type RemoteServer::get_message ( double  timeout,
std::string &  result,
message_type  required_type = MSG_MAX 
)
private

Accept a message from the client.

Definition at line 120 of file remoteserver.cc.

References RealTime::end_time(), RemoteConnection::get_message(), MSG_MAX, MSG_SHUTDOWN, Xapian::Internal::str(), and wdb.

Referenced by msg_query(), and run().

◆ msg_adddocument()

void RemoteServer::msg_adddocument ( const std::string &  message)
private

◆ msg_addspelling()

void RemoteServer::msg_addspelling ( const std::string &  message)
private

◆ msg_addsynonym()

void RemoteServer::msg_addsynonym ( const std::string &  message)
private

◆ msg_allterms()

void RemoteServer::msg_allterms ( const std::string &  message)
private

◆ msg_cancel()

void RemoteServer::msg_cancel ( const std::string &  message)
private

◆ msg_clearsynonyms()

void RemoteServer::msg_clearsynonyms ( const std::string &  message)
private

◆ msg_collfreq()

void RemoteServer::msg_collfreq ( const std::string &  message)
private

◆ msg_commit()

void RemoteServer::msg_commit ( const std::string &  message)
private

Definition at line 819 of file remoteserver.cc.

References Xapian::WritableDatabase::commit(), REPLY_DONE, send_message(), throw_read_only(), and wdb.

Referenced by run().

◆ msg_deletedocument()

void RemoteServer::msg_deletedocument ( const std::string &  message)
private

◆ msg_deletedocumentterm()

void RemoteServer::msg_deletedocumentterm ( const std::string &  message)
private

◆ msg_doclength()

void RemoteServer::msg_doclength ( const std::string &  message)
private

◆ msg_document()

void RemoteServer::msg_document ( const std::string &  message)
private

◆ msg_freqs()

void RemoteServer::msg_freqs ( const std::string &  message)
private

◆ msg_getmetadata()

void RemoteServer::msg_getmetadata ( const std::string &  message)
private

Definition at line 923 of file remoteserver.cc.

References db, Xapian::Database::get_metadata(), REPLY_METADATA, and send_message().

Referenced by run().

◆ msg_keepalive()

void RemoteServer::msg_keepalive ( const std::string &  message)
private

Definition at line 701 of file remoteserver.cc.

References db, Xapian::Database::keep_alive(), REPLY_DONE, and send_message().

Referenced by run().

◆ msg_metadatakeylist()

void RemoteServer::msg_metadatakeylist ( const std::string &  message)
private

◆ msg_positionlist()

void RemoteServer::msg_positionlist ( const std::string &  message)
private

◆ msg_positionlistcount()

void RemoteServer::msg_positionlistcount ( const std::string &  message)
private

◆ msg_postlist()

void RemoteServer::msg_postlist ( const std::string &  message)
private

◆ msg_query()

void RemoteServer::msg_query ( const std::string &  message)
private

◆ msg_reconstructtext()

void RemoteServer::msg_reconstructtext ( const std::string &  message)
private

Definition at line 800 of file remoteserver.cc.

References db, p, Xapian::Database::reconstruct_text(), REPLY_RECONSTRUCTTEXT, send_message(), and unpack_uint().

Referenced by run().

◆ msg_removespelling()

void RemoteServer::msg_removespelling ( const std::string &  message)
private

◆ msg_removesynonym()

void RemoteServer::msg_removesynonym ( const std::string &  message)
private

◆ msg_reopen()

void RemoteServer::msg_reopen ( const std::string &  message)
private

Definition at line 473 of file remoteserver.cc.

References db, msg_update(), Xapian::Database::reopen(), REPLY_DONE, and send_message().

Referenced by run().

◆ msg_replacedocument()

void RemoteServer::msg_replacedocument ( const std::string &  message)
private

◆ msg_replacedocumentterm()

void RemoteServer::msg_replacedocumentterm ( const std::string &  message)
private

◆ msg_requestdocument()

void RemoteServer::msg_requestdocument ( const std::string &  message)
private

Definition at line 965 of file remoteserver.cc.

References db, Xapian::Database::internal, p, REPLY_DONE, send_message(), and unpack_uint_last().

Referenced by run().

◆ msg_setmetadata()

void RemoteServer::msg_setmetadata ( const std::string &  message)
private

◆ msg_synonymkeylist()

void RemoteServer::msg_synonymkeylist ( const std::string &  message)
private

◆ msg_synonymtermlist()

void RemoteServer::msg_synonymtermlist ( const std::string &  message)
private

◆ msg_termexists()

void RemoteServer::msg_termexists ( const std::string &  message)
private

Definition at line 709 of file remoteserver.cc.

References db, REPLY_TERMDOESNTEXIST, REPLY_TERMEXISTS, send_message(), term, and Xapian::Database::term_exists().

Referenced by run().

◆ msg_termfreq()

void RemoteServer::msg_termfreq ( const std::string &  message)
private

Definition at line 724 of file remoteserver.cc.

References db, Xapian::Database::get_termfreq(), pack_uint_last(), REPLY_TERMFREQ, send_message(), and term.

Referenced by run().

◆ msg_termlist()

void RemoteServer::msg_termlist ( const std::string &  message)
private

◆ msg_uniqueterms()

void RemoteServer::msg_uniqueterms ( const std::string &  message)
private

◆ msg_update()

void RemoteServer::msg_update ( const std::string &  message)
private

◆ msg_valuestats()

void RemoteServer::msg_valuestats ( const std::string &  message)
private

◆ msg_wdfdocmax()

void RemoteServer::msg_wdfdocmax ( const std::string &  message)
private

◆ msg_writeaccess()

void RemoteServer::msg_writeaccess ( const std::string &  message)
private

Definition at line 450 of file remoteserver.cc.

References db, Xapian::Database::lock(), msg_update(), p, throw_read_only(), unpack_uint_last(), wdb, and writable.

Referenced by run().

◆ operator=()

void RemoteServer::operator= ( const RemoteServer )
private

Don't allow assignment.

◆ run()

void RemoteServer::run ( )

Repeatedly accept messages from the client and process them.

The loop continues until either the connection is closed, or a non-Xapian exception is thrown.

Definition at line 159 of file remoteserver.cc.

References get_message(), idle_timeout, MSG_ADDDOCUMENT, msg_adddocument(), MSG_ADDSPELLING, msg_addspelling(), MSG_ADDSYNONYM, msg_addsynonym(), MSG_ALLTERMS, msg_allterms(), MSG_CANCEL, msg_cancel(), MSG_CLEARSYNONYMS, msg_clearsynonyms(), MSG_COLLFREQ, msg_collfreq(), MSG_COMMIT, msg_commit(), MSG_DELETEDOCUMENT, msg_deletedocument(), MSG_DELETEDOCUMENTTERM, msg_deletedocumentterm(), MSG_DOCLENGTH, msg_doclength(), MSG_DOCUMENT, msg_document(), MSG_FREQS, msg_freqs(), MSG_GETMETADATA, msg_getmetadata(), MSG_KEEPALIVE, msg_keepalive(), MSG_METADATAKEYLIST, msg_metadatakeylist(), MSG_POSITIONLIST, msg_positionlist(), MSG_POSITIONLISTCOUNT, msg_positionlistcount(), MSG_POSTLIST, msg_postlist(), MSG_QUERY, msg_query(), MSG_RECONSTRUCTTEXT, msg_reconstructtext(), MSG_REMOVESPELLING, msg_removespelling(), MSG_REMOVESYNONYM, msg_removesynonym(), MSG_REOPEN, msg_reopen(), MSG_REPLACEDOCUMENT, msg_replacedocument(), MSG_REPLACEDOCUMENTTERM, msg_replacedocumentterm(), MSG_REQUESTDOCUMENT, msg_requestdocument(), MSG_SETMETADATA, msg_setmetadata(), MSG_SYNONYMKEYLIST, msg_synonymkeylist(), MSG_SYNONYMTERMLIST, msg_synonymtermlist(), MSG_TERMEXISTS, msg_termexists(), MSG_TERMFREQ, msg_termfreq(), MSG_TERMLIST, msg_termlist(), MSG_UNIQUETERMS, msg_uniqueterms(), MSG_UPDATE, msg_update(), MSG_VALUESTATS, msg_valuestats(), MSG_WDFDOCMAX, msg_wdfdocmax(), MSG_WRITEACCESS, msg_writeaccess(), REPLY_EXCEPTION, send_message(), serialise_error(), and Xapian::Internal::str().

Referenced by RemoteTcpServer::handle_one_connection(), and main().

◆ send_message() [1/2]

void RemoteServer::send_message ( reply_type  type,
std::string_view  message 
)
private

◆ send_message() [2/2]

void RemoteServer::send_message ( reply_type  type,
std::string_view  message,
double  end_time 
)
inlineprivate

Send a message to the client, with specific end_time.

Definition at line 83 of file remoteserver.h.

References RealTime::end_time(), and RemoteConnection::send_message().

◆ set_registry()

void RemoteServer::set_registry ( const Xapian::Registry reg_)
inline

Set the registry used for (un)serialisation.

Definition at line 271 of file remoteserver.h.

Referenced by RemoteTcpServer::handle_one_connection().

Member Data Documentation

◆ active_timeout

double RemoteServer::active_timeout
private

Timeout for actions during a conversation.

The timeout is specified in seconds. If the timeout is exceeded then a Xapian::NetworkTimeoutError is thrown.

Definition at line 60 of file remoteserver.h.

Referenced by msg_query(), and send_message().

◆ db

Xapian::Database* RemoteServer::db = nullptr
private

◆ idle_timeout

double RemoteServer::idle_timeout
private

Timeout while waiting for a new action from the client.

The timeout is specified in seconds. If the timeout is exceeded then a Xapian::NetworkTimeoutError is thrown.

Definition at line 67 of file remoteserver.h.

Referenced by run().

◆ reg

Xapian::Registry RemoteServer::reg
private

The registry, which allows unserialisation of user subclasses.

Definition at line 70 of file remoteserver.h.

Referenced by msg_query().

◆ wdb

Xapian::WritableDatabase* RemoteServer::wdb = nullptr
private

◆ writable

bool RemoteServer::writable
private

Do we support writing?

Definition at line 53 of file remoteserver.h.

Referenced by msg_writeaccess().


The documentation for this class was generated from the following files: