#include <Socket.h>
Inheritance diagram for CODEX_Quorum::SocketBase:

Public Types | ||||
| typedef std::queue< Message * > | MsgQueueType | |||
| Outgoing messages are kept in a queue. | ||||
| enum | StateType { kRead, kWrite, kError } | |||
| Type of state to check. | ||||
Public Member Functions | ||||
Socket Creation and Maintenance | ||||
These functions, including constructors and a destructor, create, maintain, and destroy sockets.
In addition to construction, this also includes setting up sockets to receive incoming connections and establishing incoming and outgoing connections. | ||||
| SocketBase (int domain=PF_INET, int type=SOCK_STREAM, int protocol=0, bool blocking=false) | ||||
| The constructor creates a socket(2). | ||||
| virtual | ~SocketBase () | |||
| virtual void | setup (int port, int backlog) | |||
| This version of SocketBase::setup() assumes an IPv4 socket. | ||||
| virtual void | setup (struct sockaddr *my_addr, socklen_t addrlen, int backlog) | |||
| This version of SocketBase::setup() allows for other varieties of sockets aside from IPv4. | ||||
| virtual void | connect (const RemoteServer &server) | |||
| This replaces the standard C connect(2) function, calling the standard function in the base class (with all arguments handled transparently to the user) and allowing refinements in derived classes. | ||||
| virtual SocketBase * | accept () | |||
| This replaces the standard C accept(2) function, calling the standard function in the base class (with all arguments handled transparently to the user) and allowing refinements in derived classes. | ||||
Socket I/O | ||||
These functions handle basic socket I/O. | ||||
| virtual size_t | readFrom (void *output, size_t maxSize=1024) const | |||
| Read data from a socket. | ||||
| virtual size_t | readAll (Message &msg, size_t length=0) const | |||
| This method reads an entire message from the socket, using the message length information encoded in the packet. | ||||
| virtual void | writeTo (const Message &input) const | |||
| Write data to a socket. | ||||
| virtual int | set_fd (fd_set *fd_bitmap, StateType s) const | |||
| Fill file descriptor bitmap. | ||||
| virtual bool | isset_fd (const fd_set *fd_bitmap, StateType s) const | |||
| Check file descriptor bitmap. | ||||
| virtual void | flush () const | |||
| Force a blocking write of the internal buffer. | ||||
Protected Member Functions | ||||
| virtual int | internal_write (const unsigned char *output, size_t maxSize) const | |||
| Write data to the socket. | ||||
Protected Constructors | ||||
These functions allow controlled construction of new SocketBase%s. | ||||
| SocketBase (const SocketBase &aOther) | ||||
| Copy constructor. | ||||
| virtual SocketBase * | clone () | |||
| Subclass-aware object duplication. | ||||
Protected Setup and Maintenance Methods | ||||
These methods implement the functionality of their non-protected counterparts.
This allows derived classes to use the public methods without having to fully reimplement the base class methods. | ||||
| virtual SocketBase * | protected_accept () | |||
| ||||
| virtual void | finish_accept () | |||
| Post-creation method called by protected_accept(). | ||||
| virtual void | protected_bind (int port) | |||
| virtual void | protected_bind (struct sockaddr *my_addr, socklen_t addrlen) | |||
| ||||
| virtual void | protected_listen (int backlog) | |||
| ||||
| void | setSocket (int socketFD) | |||
| void | setBacklog (int backlog) | |||
| void | setPort (int port) | |||
Protected Accessors | ||||
These accessor methods allow derived classes to read, but not modify, private member data. | ||||
| int | domain () const | |||
| int | type () const | |||
| int | protocol () const | |||
| bool | blocking () const | |||
| int | port () const | |||
| int | backlog () const | |||
| int | socket () const | |||
Protected Attributes | ||||
| MsgQueueType | m_msgQueue | |||
| Message queue, which allows us to do in-order non-blocking writes. | ||||
| unsigned int | m_msgOffset | |||
| Offset into the buffer of the first message on the queue. | ||||
Definition at line 38 of file Socket.h.
|
||||||||||||||||||||
|
The constructor creates a socket(2). Additional configuration, such as bind(2) and listen(2) must be done after construction. The default values establish an IPv4 TCP socket.
Definition at line 36 of file Socket.cc. Referenced by clone(). |
|
|
Copy constructor. The copy constructor does not create a new socket, but rather copies the configuration of the original socket. This is used when accept%ing connections, where the listening socket is clone%d for each incoming connection. |
|
|
This replaces the standard C accept(2) function, calling the standard function in the base class (with all arguments handled transparently to the user) and allowing refinements in derived classes. The connection information is held within the member data of SocketBase. As the standard accept(2) returns a new socket filehandle, this version acts as a clone function. The bulk of the work is handled in the protected member function SocketBase::protected_accept(), which should be called by derived-class reimplementations of SocketBase::accept().
Reimplemented in CODEX_Quorum::LoopbackSocket. Definition at line 97 of file Socket.cc. References protected_accept(). Referenced by CODEX_Quorum::EchoServer::processRequest(). |
|
|
Subclass-aware object duplication. This is similar to a copy constructor except that, as a virtual function, it can be overridden in order for derived classes to return copies of themselves that have the correct type, yet which use an identical interface from the base class. Each class in the SocketBase hierarchy overrides this method to use its own copy constructor. Reimplemented in CODEX_Quorum::LoopbackSocket, and CODEX_SSL::SSLSocket. Definition at line 374 of file Socket.cc. References SocketBase(). Referenced by protected_accept(). |
|
|
This replaces the standard C connect(2) function, calling the standard function in the base class (with all arguments handled transparently to the user) and allowing refinements in derived classes.
Reimplemented in CODEX_Quorum::LoopbackSocket. Definition at line 88 of file Socket.cc. Referenced by CODEX_SSL::SSLSocket::connect(), and CODEX_Quorum::RemoteServer::socket(). |
|
|
Post-creation method called by protected_accept(). The default version of this method does nothing. It exists so that derived classes may add their own setup after accept(2) has run, but before the actual type is lost by the socket being returned as a pointer to SocketBase. Reimplemented in CODEX_SSL::SSLSocket. Definition at line 369 of file Socket.cc. Referenced by protected_accept(). |
|
|
Force a blocking write of the internal buffer. Reads are not affected. Single-threaded servers should not call this, but it's fine for multi-threaded servers and clients that want to block until they get a response. Reimplemented in CODEX_Quorum::LoopbackSocket. Definition at line 282 of file Socket.cc. References CODEX_Quorum::Message::buffer(), internal_write(), CODEX_Quorum::Message::length(), m_msgOffset, and m_msgQueue. Referenced by CODEX_Quorum::RemoteServer::flushSocket(). |
|
||||||||||||
|
Write data to the socket. Derived classes that need special semantics for writing but can still use the select(2) mechanism, such as for SSL, only need to override this method. The public writeTo() method is SSL-clean.
Reimplemented in CODEX_SSL::SSLSocket. Definition at line 314 of file Socket.cc. Referenced by flush(), and isset_fd(). |
|
||||||||||||
|
Check file descriptor bitmap.
Definition at line 242 of file Socket.cc. References CODEX_Quorum::Message::buffer(), internal_write(), CODEX_Quorum::Message::length(), m_msgOffset, m_msgQueue, and set_fd(). Referenced by CODEX_SSL::SSLSocket::isset_fd(), CODEX_Quorum::RemoteServer::isset_fd(), CODEX_Quorum::LocalServer::isset_fd(), CODEX_Quorum::EchoServer::processRequest(), and readAll(). |
|
||||||||||||
|
Definition at line 402 of file Socket.cc. Referenced by setup(). |
|
||||||||||||
|
This method reads an entire message from the socket, using the message length information encoded in the packet. If reading the entire message would block, the available data is put into msg and the remaining number of bytes to be read is returned. The message passed in will be appended to, so in the case where a read would have blocked, the Message can be passed to readAll() again when more data becomes available.
Definition at line 119 of file Socket.cc. References isset_fd(), readFrom(), and set_fd(). Referenced by CODEX_Quorum::RemoteServer::receiveFrom(). |
|
||||||||||||
|
Read data from a socket.
Reimplemented in CODEX_Quorum::LoopbackSocket, and CODEX_SSL::SSLSocket. Definition at line 103 of file Socket.cc. Referenced by CODEX_Quorum::EchoServer::processRequest(), and readAll(). |
|
||||||||||||
|
Fill file descriptor bitmap.
Definition at line 235 of file Socket.cc. Referenced by isset_fd(), CODEX_Quorum::EchoServer::processRequest(), readAll(), CODEX_SSL::SSLSocket::set_fd(), CODEX_Quorum::RemoteServer::set_fd(), and CODEX_Quorum::LocalServer::set_fd(). |
|
||||||||||||||||
|
This version of SocketBase::setup() allows for other varieties of sockets aside from IPv4. The arguments provided conform to the arguments of bind(2) and listen(2). Reimplemented in CODEX_Quorum::LoopbackSocket. Definition at line 79 of file Socket.cc. References protected_bind(), and protected_listen(). |
|
||||||||||||
|
This version of SocketBase::setup() assumes an IPv4 socket.
It will use
Reimplemented in CODEX_Quorum::LoopbackSocket. Definition at line 72 of file Socket.cc. References protected_bind(), and protected_listen(). Referenced by CODEX_Quorum::LocalServer::enable(). |
|
|
Write data to a socket.
Definition at line 212 of file Socket.cc. References CODEX_Quorum::Message::fill(), and m_msgQueue. Referenced by CODEX_Quorum::EchoServer::processRequest(), and CODEX_Quorum::RemoteServer::sendTo(). |
1.4.1