RemoteConnection Class Reference

A RemoteConnection object provides a bidirectional connection to another RemoteConnection object on a remote machine. More...

#include <remoteconnection.h>

Inheritance diagram for RemoteConnection:

Inheritance graph
[legend]
Collaboration diagram for RemoteConnection:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 RemoteConnection (int fdin_, int fdout_, const std::string &context_)
 Constructor.
 ~RemoteConnection ()
 Destructor.
bool ready_to_read () const
 See if there is data available to read.
char get_message (std::string &result, const OmTime &end_time)
 Read one message from fdin.
void send_message (char type, const std::string &s, const OmTime &end_time)
 Send a message.
void do_close (bool wait)
 Shutdown the connection.

Protected Attributes

std::string context
 The context to report with errors.

Private Member Functions

void operator= (const RemoteConnection &)
 Don't allow assignment.
 RemoteConnection (const RemoteConnection &)
 Don't allow copying.
void read_at_least (size_t min_len, const OmTime &end_time)
 Read until there are at least min_len bytes in buffer.

Private Attributes

int fdin
 The file descriptor used for reading.
int fdout
 The file descriptor used for writing.
std::string buffer
 Buffer to hold unprocessed input.

Detailed Description

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 95 of file remoteconnection.h.


Constructor & Destructor Documentation

RemoteConnection::RemoteConnection ( const RemoteConnection  )  [private]

Don't allow copying.

RemoteConnection::RemoteConnection ( int  fdin_,
int  fdout_,
const std::string &  context_ 
)

Constructor.

RemoteConnection::~RemoteConnection (  ) 

Destructor.

Definition at line 132 of file remoteconnection.cc.


Member Function Documentation

void RemoteConnection::operator= ( const RemoteConnection  )  [private]

Don't allow assignment.

void RemoteConnection::read_at_least ( size_t  min_len,
const OmTime end_time 
) [private]

Read until there are at least min_len bytes in buffer.

If for some reason this isn't possible, throws NetworkError.

Parameters:
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 == OmTime(), then keep trying indefinitely.

Definition at line 141 of file remoteconnection.cc.

References Assert, buffer, context, DEBUGCALL, DEBUGLINE, fdin, OmTime::is_set(), OmTime::now(), OmTime::sec, and OmTime::usec.

bool RemoteConnection::ready_to_read (  )  const

See if there is data available to read.

Returns:
true if there is data waiting to be read.

Definition at line 236 of file remoteconnection.cc.

References buffer, DEBUGCALL, fdin, and RETURN.

Referenced by RemoteDatabase::get_remote_stats().

char RemoteConnection::get_message ( std::string &  result,
const OmTime end_time 
)

Read one message from fdin.

Parameters:
[out] result Message data.
end_time If this time is reached, then a timeout exception will be thrown. If !end_time.is_set() then the operation will never timeout.
Returns:
Message type code.

Referenced by RemoteServer::get_message(), and RemoteDatabase::get_message().

void RemoteConnection::send_message ( char  type,
const std::string &  s,
const OmTime end_time 
)

Send a message.

Parameters:
type Message type code.
s Message data.
end_time If this time is reached, then a timeout exception will be thrown. If !end_time.is_set() then the operation will never timeout.

Referenced by do_close(), RemoteServer::run(), RemoteServer::send_message(), and RemoteDatabase::send_message().

void RemoteConnection::do_close ( bool  wait  ) 

Shutdown the connection.

Parameters:
wait If true, wait for the remote end to close the connection before returning.

Definition at line 400 of file remoteconnection.cc.

References close_fd_or_socket(), DEBUGCALL, dummy, fdin, fdout, MSG_SHUTDOWN, and send_message().

Referenced by RemoteDatabase::do_close().


Member Data Documentation

int RemoteConnection::fdin [private]

The file descriptor used for reading.

Definition at line 103 of file remoteconnection.h.

Referenced by do_close(), read_at_least(), and ready_to_read().

int RemoteConnection::fdout [private]

The file descriptor used for writing.

Definition at line 106 of file remoteconnection.h.

Referenced by do_close().

std::string RemoteConnection::buffer [private]

Buffer to hold unprocessed input.

Definition at line 109 of file remoteconnection.h.

Referenced by read_at_least(), and ready_to_read().

std::string RemoteConnection::context [protected]

The context to report with errors.

Subclasses are allowed to manage this.

Definition at line 142 of file remoteconnection.h.

Referenced by read_at_least(), and RemoteServer::RemoteServer().


The documentation for this class was generated from the following files:
Documentation for Xapian (version 1.0.10).
Generated on 24 Dec 2008 by Doxygen 1.5.2.