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


Public Member Functions | ||||||||||
| 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 | |||||||||
| 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 | ||||||||||
| SocketBase * | socket () const | |||||||||
| If a socket is currently open, a pointer to it is returned. | ||||||||||
| virtual bool | checkTimeout (const RemoteServerReturn &retval) const | |||||||||
| virtual void | updateTime (RemoteServerReturn &retval) const | |||||||||
| Set the recorded time of retval to the current time. | ||||||||||
As a base class, it makes a synchrony assumption for responses.
Definition at line 159 of file RemoteServer.h.
|
||||||||||||||||||||||||
|
Constructor.
Definition at line 28 of file RemoteServer.cc. |
|
|
Reimplemented in CODEX_Quorum::AsynchronousRemoteServer. Definition at line 168 of file RemoteServer.cc. Referenced by receiveFrom(). |
|
||||||||||||||||
|
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 receiveFrom(), and 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 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 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 checkTimeout(), closeSocket(), CODEX_Quorum::SocketBase::readAll(), socket(), and updateTime(). Referenced by 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 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(). |
|
||||||||||||
|
Fill file descriptor bitmap.
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(). |
|
|
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 flushSocket(), isset_fd(), receiveFrom(), sendTo(), and set_fd(). |
1.4.1