Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

CODEX_Quorum::AsynchronousRemoteServer Class Reference

This is an asynchronous implementation of the synchronous base class. More...

#include <RemoteServer.h>

Inheritance diagram for CODEX_Quorum::AsynchronousRemoteServer:

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

Collaboration graph
[legend]
List of all members.

Public Member Functions

 AsynchronousRemoteServer (string address, int port, const SocketBuilder &socketBuilder, SocketBase *socket=0)
 Create an AsynchronousRemoteServer.
virtual ~AsynchronousRemoteServer ()
 Virtual destructor.
const struct sockaddr_in * sockaddr_in () const
 Socket address information for an IP socket.
const struct sockaddr * sockaddr () const
 Socket address information in generic form.
socklen_t addrlen () const
 Size of the sockaddr_in.
string name () const
 Name of the remote server.
int port () const
 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.
void closeSocket ()
 Closes the socket to the server, if it's open.
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.

Protected Member Functions

bool checkTimeout (const RemoteServerReturn &retval) const
void updateTime (RemoteServerReturn &retval) const
 Set the recorded time of retval to the current time.
SocketBasesocket () const
 If a socket is currently open, a pointer to it is returned.

Detailed Description

This is an asynchronous implementation of the synchronous base class.

Asynchronous servers can be instantiated directly as synchronous servers, but having a separate class makes it simpler to program, clearer to read, and less prone to errors. Checking for timeouts is also slightly faster.

Definition at line 376 of file RemoteServer.h.


Constructor & Destructor Documentation

CODEX_Quorum::AsynchronousRemoteServer::AsynchronousRemoteServer string  address,
int  port,
const SocketBuilder socketBuilder,
SocketBase socket = 0
[inline]
 

Create an AsynchronousRemoteServer.

The arguments are the same as for RemoteServer::RemoteServer(), except that the timeout structure is always 0.

Definition at line 384 of file RemoteServer.h.


Member Function Documentation

bool AsynchronousRemoteServer::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 from CODEX_Quorum::RemoteServer.

Definition at line 213 of file RemoteServer.cc.

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

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::RemoteServer::receiveFrom(), and CODEX_Quorum::RemoteServer::sendTo().

void RemoteServer::flushSocket  )  const [inherited]
 

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 CODEX_Quorum::RemoteServer::socket().

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

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

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(), and CODEX_Quorum::RemoteServer::socket().

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
[inherited]
 

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 CODEX_Quorum::RemoteServer::checkTimeout(), CODEX_Quorum::RemoteServer::closeSocket(), CODEX_Quorum::SocketBase::readAll(), CODEX_Quorum::RemoteServer::socket(), and CODEX_Quorum::RemoteServer::updateTime().

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

void RemoteServer::sendTo const Message msg,
RemoteServerReturn retval
const [inherited]
 

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::RemoteServer::socket(), and CODEX_Quorum::SocketBase::writeTo().

Referenced by CODEX_Quorum::StaticByzantineQuorumSystem< N, T >::broadcastMessage(), CODEX_Quorum::RemoteServer::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 [inherited]
 

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 CODEX_Quorum::RemoteServer::socket().

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

SocketBase * RemoteServer::socket  )  const [protected, inherited]
 

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::RemoteServer::flushSocket(), CODEX_Quorum::RemoteServer::isset_fd(), CODEX_Quorum::RemoteServer::receiveFrom(), CODEX_Quorum::RemoteServer::sendTo(), and CODEX_Quorum::RemoteServer::set_fd().


The documentation for this class was generated from the following files:
Generated on Fri May 6 17:42:31 2005 for COrnell Data EXchange (CODEX) by  doxygen 1.4.1