|
xapian-core
2.0.0
|
A RemoteConnection object provides a bidirectional connection to another RemoteConnection object on a remote machine. More...
#include <remoteconnection.h>
Inheritance diagram for RemoteConnection:
Collaboration diagram for RemoteConnection:Public Member Functions | |
| 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... | |
Protected Attributes | |
| std::string | context |
| The context to report with errors. More... | |
Private Member Functions | |
| void | operator= (const RemoteConnection &) |
| Don't allow assignment. More... | |
| RemoteConnection (const RemoteConnection &) | |
| Don't allow copying. More... | |
| bool | read_at_least (size_t min_len, double end_time) |
| Read until there are at least min_len bytes in buffer. More... | |
| ssize_t | send_or_write (const void *p, size_t n) |
| Helper which calls send() or write(). More... | |
Private Attributes | |
| int | fdin |
| The file descriptor used for reading. More... | |
| int | fdout |
| The file descriptor used for writing. More... | |
| std::string | buffer |
| Buffer to hold unprocessed input. More... | |
| off_t | chunked_data_left |
| Remaining bytes of message data still to come over fdin for a chunked read. More... | |
A RemoteConnection object provides a bidirectional connection to another RemoteConnection object on a remote machine.
The connection is implemented using a pair of file descriptors. Messages with a single byte type code and arbitrary data as the contents can be sent and received.
Definition at line 41 of file remoteconnection.h.
|
private |
Don't allow copying.
| RemoteConnection::RemoteConnection | ( | int | fdin_, |
| int | fdout_, | ||
| const std::string & | context_ = std::string() |
||
| ) |
| void RemoteConnection::do_close | ( | ) |
Close the connection.
Definition at line 784 of file remoteconnection.cc.
References close_fd_or_socket(), fdin, fdout, and LOGCALL_VOID.
Referenced by RemoteDatabase::do_close(), and OwnedRemoteConnection::~OwnedRemoteConnection().
|
inline |
Return the context to report with errors.
Definition at line 267 of file remoteconnection.h.
References context.
Referenced by RemoteDatabase::get_backend_info(), RemoteDatabase::get_description(), RemoteDatabase::get_doclength(), RemoteDatabase::get_freqs(), RemoteDatabase::get_message(), RemoteDatabase::get_unique_terms(), RemoteDatabase::get_wdfdocmax(), RemoteDatabase::open_term_list(), RemoteDatabase::positionlist_count(), RemoteDatabase::read_value_stats(), RemoteDatabase::remove_spelling(), and RemoteDatabase::update_stats().
| int RemoteConnection::get_message | ( | std::string & | result, |
| double | end_time | ||
| ) |
Read one message from fdin.
| [out] | result | Message data. |
| end_time | If this time is reached, then a timeout exception will be thrown. If (end_time == 0.0) then the operation will never timeout. |
Definition at line 593 of file remoteconnection.cc.
References buffer, RealTime::end_time(), fdin, LOGCALL, p, read_at_least(), RETURN, throw_database_closed(), and unpack_uint().
Referenced by RemoteServer::get_message(), RemoteDatabase::get_message(), ReplicateTcpServer::handle_one_connection(), and RemoteDatabase::send_message().
| int RemoteConnection::get_message_chunk | ( | std::string & | result, |
| size_t | at_least, | ||
| double | end_time | ||
| ) |
Read a chunk of a message from fdin.
You must call get_message_chunked() before calling this method.
| [in,out] | result | Message data. This is appended to, so if you read more than needed the previous time, leave the excess in result. |
| at_least | Return at least this many bytes in result, unless there isn't enough data left in the message (in which case all remaining data is read and 0 is returned). | |
| end_time | If this time is reached, then a timeout exception will be thrown. If (end_time == 0.0) then the operation will never timeout. |
Definition at line 674 of file remoteconnection.cc.
References buffer, chunked_data_left, RealTime::end_time(), fdin, LOGCALL, read_at_least(), RETURN, and throw_database_closed().
Referenced by GlassDatabaseReplicator::apply_changeset_from_conn(), GlassDatabaseReplicator::process_changeset_chunk_blocks(), and GlassDatabaseReplicator::process_changeset_chunk_version().
| int RemoteConnection::get_message_chunked | ( | double | end_time | ) |
Prepare to read one message from fdin in chunks.
Sometimes a message can be sufficiently large that you don't want to read it all into memory before processing it. Also, it may be more efficient to process it as you go.
This method doesn't actually return any message data - call get_message_chunk() to do that.
| end_time | If this time is reached, then a timeout exception will be thrown. If (end_time == 0.0) then the operation will never timeout. |
Definition at line 633 of file remoteconnection.cc.
References buffer, chunked_data_left, RealTime::end_time(), fdin, LOGCALL, p, rare, read_at_least(), RETURN, throw_database_closed(), throw_network_error_message_too_long_for_off_t(), and unpack_uint().
Referenced by GlassDatabaseReplicator::apply_changeset_from_conn(), and receive_file().
|
inline |
Return the underlying fd this remote connection reads from.
Definition at line 147 of file remoteconnection.h.
References fdin.
Referenced by RemoteDatabase::get_read_fd().
|
private |
Don't allow assignment.
|
private |
Read until there are at least min_len bytes in buffer.
If for some reason this isn't possible, returns false upon EOF and otherwise throws NetworkError.
| min_len | Minimum number of bytes required in buffer. |
| end_time | If this time is reached, then a timeout exception will be thrown. If (end_time == 0.0), then keep trying indefinitely. |
Definition at line 157 of file remoteconnection.cc.
References Assert, buffer, CHUNKSIZE, context, RealTime::end_time(), fdin, LOGCALL, LOGLINE, RealTime::now(), RETURN, RealTime::sleep(), throw_timeout(), and RealTime::to_timeval().
Referenced by get_message(), get_message_chunk(), get_message_chunked(), receive_file(), and sniff_next_message_type().
| int RemoteConnection::receive_file | ( | const std::string & | file, |
| double | end_time | ||
| ) |
Save the contents of a message as a file.
| file | Path to file to save the message data into. If the file exists it will be overwritten. |
| end_time | If this time is reached, then a timeout exception will be thrown. If (end_time == 0.0) then the operation will never timeout. |
Definition at line 714 of file remoteconnection.cc.
References buffer, chunked_data_left, CHUNKSIZE, RealTime::end_time(), fdin, get_message_chunked(), LOGCALL, O_CLOEXEC, posixy_open, read_at_least(), RETURN, throw_database_closed(), and write_all().
| void RemoteConnection::send_file | ( | char | type, |
| int | fd, | ||
| double | end_time | ||
| ) |
Send the contents of a file as a message.
| type | Message type code. |
| fd | File containing the message data. |
| end_time | If this time is reached, then a timeout exception will be thrown. If (end_time == 0.0) then the operation will never timeout. |
Definition at line 428 of file remoteconnection.cc.
References AssertRel, CHUNKSIZE, context, RealTime::end_time(), fdout, file_size(), LOGCALL_VOID, LOGLINE, RealTime::now(), pack_uint(), POLLSELECT, send_or_write(), RealTime::sleep(), throw_database_closed(), throw_timeout(), and RealTime::to_timeval().
Referenced by GlassDatabase::send_whole_database(), and GlassDatabase::write_changesets_to_fd().
| void RemoteConnection::send_message | ( | char | type, |
| std::string_view | s, | ||
| double | end_time | ||
| ) |
Send a message.
| type | Message type code. |
| s | Message data. |
| end_time | If this time is reached, then a timeout exception will be thrown. If (end_time == 0.0) then the operation will never timeout. |
Definition at line 300 of file remoteconnection.cc.
References context, RealTime::end_time(), fdout, LOGCALL_VOID, LOGLINE, RealTime::now(), pack_uint(), POLLSELECT, send_or_write(), RealTime::sleep(), Xapian::Internal::str(), throw_database_closed(), throw_timeout(), and RealTime::to_timeval().
Referenced by RemoteDatabase::send_message(), RemoteServer::send_message(), GlassDatabase::send_whole_database(), shutdown(), Xapian::DatabaseMaster::write_changesets_to_fd(), and GlassDatabase::write_changesets_to_fd().
|
private |
Helper which calls send() or write().
Definition at line 283 of file remoteconnection.cc.
References fdout, p, and usual.
Referenced by send_file(), and send_message().
| void RemoteConnection::shutdown | ( | ) |
Shutdown the connection.
Sends a shutdown message to the server and waits for it to close its end of the connection.
Definition at line 738 of file remoteconnection.cc.
References dummy, fdin, LOGCALL_VOID, MSG_SHUTDOWN, and send_message().
Referenced by RemoteDatabase::do_close().
| int RemoteConnection::sniff_next_message_type | ( | double | end_time | ) |
Check what the next message type is.
This must not be called after a call to get_message_chunked() until get_message_chunk() has returned 0 to indicate the whole message has been received.
Other than that restriction, this may be called at any time to determine what the next message waiting to be processed is: it will not affect subsequent calls which read messages.
| end_time | If this time is reached, then a timeout exception will be thrown. If (end_time == 0.0) then the operation will never timeout. |
Definition at line 580 of file remoteconnection.cc.
References buffer, RealTime::end_time(), fdin, LOGCALL, read_at_least(), RETURN, and throw_database_closed().
|
private |
Buffer to hold unprocessed input.
Definition at line 91 of file remoteconnection.h.
Referenced by get_message(), get_message_chunk(), get_message_chunked(), read_at_least(), receive_file(), and sniff_next_message_type().
|
private |
Remaining bytes of message data still to come over fdin for a chunked read.
Definition at line 94 of file remoteconnection.h.
Referenced by get_message_chunk(), get_message_chunked(), and receive_file().
|
protected |
The context to report with errors.
Subclasses are allowed to manage this.
Definition at line 134 of file remoteconnection.h.
Referenced by get_context(), read_at_least(), RemoteConnection(), RemoteServer::RemoteServer(), send_file(), and send_message().
|
private |
The file descriptor used for reading.
If this is -1, the connection is unidirectional and write-only. If both fdin and fdout are -1, then the connection has been closed.
Definition at line 53 of file remoteconnection.h.
Referenced by do_close(), get_message(), get_message_chunk(), get_message_chunked(), get_read_fd(), read_at_least(), receive_file(), shutdown(), and sniff_next_message_type().
|
private |
The file descriptor used for writing.
If this is -1, the connection is unidirectional and read-only. If both fdin and fdout are -1, then the connection has been closed. It is valid for fdout to be the same as fdin.
Definition at line 61 of file remoteconnection.h.
Referenced by do_close(), RemoteConnection(), send_file(), send_message(), and send_or_write().