Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   Related Pages  

CODEX_Quorum::RemoteServer Class Reference

This holds the information necessary in order to contact a server. More...

#include <RemoteServer.h>

Inheritance diagram for CODEX_Quorum::RemoteServer:

Inheritance graph
[legend]
Collaboration diagram for CODEX_Quorum::RemoteServer:

Collaboration graph
[legend]
List of all members.

Communications Methods

These methods send messages to and receive replied from the server.

If an operation does not complete before the timer expires, a failure is reported. Note that retval must be initialized in advance, though the default constructor is typically sufficient for this.

Parameters:
msg  The message being sent.
response  The response received.
retval  The return value, updated from the value passed in.


void contact (const Message &msg, Response &response, RemoteServerReturn &retval)
 Send a message and wait for a response.

void sendTo (const Message &msg, RemoteServerReturn &retval) const
 Send a message without waiting for a response.

size_t receiveFrom (Response &response, RemoteServerReturn &retval, size_t length=0)
 Look for a response to a previously-sent message.

void closeSocket ()
 Closes the socket to the server, if it's open.

SocketBasesocket () const
virtual bool checkTimeout (const RemoteServerReturn &retval) const
virtual void updateTime (RemoteServerReturn &retval) const
 Set the recorded time of retval to the current time.


Public Methods

 RemoteServer (struct timeval *timeout, string address, int port, const SocketBuilder &socketBuilder, SocketBase *socket=0)
 Constructor.

virtual ~RemoteServer ()
 Virtual destructor.

const struct sockaddr_in * sockaddr_in () const
 
Returns:
socket address information for an IP socket


const struct sockaddr * sockaddr () const
 
Returns:
socket address information in generic form


socklen_t addrlen () const
 
Returns:
size of the sockaddr_in


string name () const
 
Returns:
name of the remote server


int port () const
 
Returns:
remote port on which server is listening


int set_fd (fd_set *fd_bitmap, SocketBase::StateType s) const
 Fill file descriptor bitmap.

bool isset_fd (const fd_set *fd_bitmap, SocketBase::StateType s) const
 Check file descriptor bitmap.

void flushSocket () const
 Forwards a flush request to the socket.


Detailed Description

This holds the information necessary in order to contact a server.

As a base class, it makes a synchrony assumption for responses.

Definition at line 156 of file RemoteServer.h.


Constructor & Destructor Documentation

RemoteServer::RemoteServer struct timeval *    timeout,
string    address,
int    port,
const SocketBuilder   socketBuilder,
SocketBase   socket = 0
 

Constructor.

Parameters:
timeout  Given a synchrony assumption, this gives the length of time to wait for a response before inferring that the server has crashed. If 0, the server is asynchronous. RemoteServer does not take ownership of this pointer.
address  The address of the server.
port  The port on which the server listens.
socketBuilder  Reference to the SocketBuilder object that is able to create an appropriate socket for this RemoteServer.
socket  If specified, a pointer to an existing (and open) socket. Otherwise, the SocketBuilder will create a new socket the first time it is requested. The memory becomes owned by the RemoteServer.

Definition at line 28 of file RemoteServer.cc.

References port().


Member Function Documentation

bool RemoteServer::checkTimeout const RemoteServerReturn   retval const [protected, virtual]
 

Parameters:
retval  The return status from a RemoteServer operation.
Return values:
false  retval indicates the timeout has been exceeded.

Reimplemented in CODEX_Quorum::AsynchronousRemoteServer.

Definition at line 168 of file RemoteServer.cc.

References CODEX_Quorum::RemoteServerReturn::elapsed().

Referenced by receiveFrom().

void RemoteServer::contact const Message   msg,
Response   response,
RemoteServerReturn   retval
 

Send a message and wait for a response.

This is, in general, not the right thing to do, since it

  1. blocks, and
  2. waits for the connection to end before reporting success.
Internally, this method calls sendTo() and receiveFrom(), which are better options for most applications.

Definition at line 118 of file RemoteServer.cc.

References CODEX_Quorum::RemoteServerReturn::errorCode(), receiveFrom(), CODEX_Quorum::RemoteServerReturn::reset(), CODEX_Quorum::RemoteServerReturn::returnCode(), and sendTo().

void RemoteServer::flushSocket  
 

Forwards a flush request to the socket.

This will force a blocking write, as opposed to the select(2)-based mechanism. This method does not affect reads.

Definition at line 111 of file RemoteServer.cc.

References CODEX_Quorum::SocketBase::flush(), and socket().

Referenced by CODEX_Client::Client::contactServer().

bool RemoteServer::isset_fd const fd_set *    fd_bitmap,
SocketBase::StateType    s
const
 

Check file descriptor bitmap.

Parameters:
fd_bitmap  bitmap of file descriptors to check. This is typically a fd_set returned by select(2), and will have the bit corresponding to the socket file descriptor set to 1 if the relevant action is appropriate.
s  state of the socket to be tested. This allows derived classes to manipulate the return value appropriately when there is additional socket state to consider.
Return values:
true  the bit is set
false  the bit is not set

Definition at line 103 of file RemoteServer.cc.

References CODEX_Quorum::SocketBase::isset_fd().

Referenced by CODEX_Server::QuorumBuilderAct::handler(), and CODEX_Quorum::StaticByzantineQuorumSystem< N, T >::poll().

size_t RemoteServer::receiveFrom Response   response,
RemoteServerReturn   retval,
size_t    length = 0
 

Look for a response to a previously-sent message.

Generally used with select(2), as in the following example:

#include <sys/types.h>

RemoteServerReturn retval;
Response           resp;
while ( retval.returnCode() != RemoteServerReturn::kSuccess )
{
   fd_set read_set;
   FD_ZERO( &read_set );
   int socketFD = remoteServer.set_fd( &read_set,
                                                 SocketBase::kRead );
   if ( ( select( socketFD + 1, &read_set, 0, 0, 0 ) > 0 ) &&
        ( remoteServer.isset_fd( &read_set, SocketBase::kRead ) ) )
   {
      remoteServer.receiveFrom( resp, retval );
      if ( retval.errorCode() != RemoteServerReturn::kNone )
      {
         // ...
      }
   }
   else
   {
      // ...
   }
}

Definition at line 144 of file RemoteServer.cc.

References checkTimeout(), closeSocket(), CODEX_Quorum::SocketBase::readAll(), CODEX_Quorum::RemoteServerReturn::setErrorCode(), CODEX_Quorum::RemoteServerReturn::setReturnCode(), socket(), and updateTime().

Referenced by contact(), CODEX_Client::Client::contactServer(), CODEX_Quorum::StaticByzantineQuorumSystem< N, T >::poll(), and CODEX_Server::QuorumBuilderExpectNonceEvent::read().

void RemoteServer::sendTo const Message   msg,
RemoteServerReturn   retval
const
 

Send a message without waiting for a response.

This method will also prepend the necessary length information so that the receiving server knows how long the complete message is.

Generally used with select(2), as in the following example:

#include <sys/types.h>

RemoteServerReturn retval;
while ( retval.returnCode() != RemoteServerReturn::kSuccess )
{
   fd_set write_set;
   FD_ZERO( &write_set );
   int socketFD = remoteServer.set_fd( &write_set,
                                                 SocketType::kWrite );
   if ( ( select( socketFD + 1, 0, &write_set, 0, 0 ) > 0 ) &&
        ( remoteServer.isset_fd( &write_set, SocketType::kWrite ) ) )
   {
      remoteServer.sendTo( msg, retval );
      if ( retval.errorCode() != RemoteServerReturn::kNone )
      {
         // ...
      }
   }
   else
   {
      // ...
   }
}

Definition at line 135 of file RemoteServer.cc.

References CODEX_Quorum::RemoteServerReturn::setReturnCode(), socket(), and CODEX_Quorum::SocketBase::writeTo().

Referenced by CODEX_Quorum::StaticByzantineQuorumSystem< N, T >::broadcastMessage(), contact(), CODEX_Client::Client::contactServer(), CODEX_Server::ServerResponseHandler::handler(), CODEX_Server::QuorumBuilderAct::handler(), and CODEX_Quorum::StaticByzantineQuorumSystem< N, T >::unicastMessage().

int RemoteServer::set_fd fd_set *    fd_bitmap,
SocketBase::StateType    s
const
 

Fill file descriptor bitmap.

Parameters:
fd_bitmap  bitmap of file descriptors to modify. The bit corresponding to the socket file descriptor will be set to 1.
s  state of the socket to be tested. This allows derived classes to manipulate the bitmap appropriately when there is additional socket state to consider.
Returns:
file descriptor of the socket

Definition at line 96 of file RemoteServer.cc.

References CODEX_Quorum::SocketBase::set_fd(), and socket().

Referenced by CODEX_Server::QuorumBuilderAct::handler(), and CODEX_Quorum::StaticByzantineQuorumSystem< N, T >::poll().

SocketBase * RemoteServer::socket   [protected]
 

Returns:
If a socket is currently open, a pointer to it is returned. Otherwise, the SocketBuilder passed to the constructor is used to create a new socket, a pointer to which is then returned.

Definition at line 191 of file RemoteServer.cc.

References CODEX_Quorum::SocketBase::connect().

Referenced by CODEX_Quorum::AsynchronousRemoteServer::AsynchronousRemoteServer(), flushSocket(), receiveFrom(), sendTo(), and set_fd().


The documentation for this class was generated from the following files:
Generated on Wed Jun 2 16:33:18 2004 for COrnell Data EXchange (CODEX) by doxygen1.2.18