#include <RemoteServer.h>
Inheritance diagram for CODEX_Quorum::AsynchronousRemoteServer:


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.
| ||||||||||
| 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. | ||||||||||
| SocketBase * | socket () const | |||||||||
| If a socket is currently open, a pointer to it is returned. | ||||||||||
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.
|
||||||||||||||||||||
|
Create an AsynchronousRemoteServer.
The arguments are the same as for RemoteServer::RemoteServer(), except that the timeout structure is always Definition at line 384 of file RemoteServer.h. |
|
|
Reimplemented from CODEX_Quorum::RemoteServer. Definition at line 213 of file RemoteServer.cc. |
|
||||||||||||||||
|
Send a message and wait for a response. This is, in general, not the right thing to do, since it
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(). |
|
|
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(). |
|
||||||||||||
|
Check file descriptor bitmap.
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(). |
|
||||||||||||||||
|
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(). |
|
||||||||||||
|
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(). |
|
||||||||||||
|
Fill file descriptor bitmap.
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(). |
|
|
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(). |
1.4.1