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

CODEX_Quorum::LoopbackSocket Class Reference

This class implements a loopback socket. More...

#include <LoopbackSocket.h>

Inheritance diagram for CODEX_Quorum::LoopbackSocket:

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

Collaboration graph
[legend]
List of all members.

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

 LoopbackSocket ()
 Constructor for loopback sockets.
 LoopbackSocket (const LoopbackSocket &aOther)
 Copy constructor.
virtual ~LoopbackSocket ()
 Destructor.
void setup (int port, int backlog)
 Dummy function.
void setup (struct sockaddr *my_addr, socklen_t addrlen, int backlog)
 Dummy function.
void connect (const RemoteServer &server)
 Dummy function.
SocketBaseaccept ()
 Accept is meaningless for this type of socket.
size_t readFrom (void *output, size_t maxSize=1024) const
 Uses internal buffer.
int set_fd (fd_set *fd_bitmap, StateType s) const
 Fill file descriptor bitmap.
bool isset_fd (const fd_set *fd_bitmap, StateType s) const
 Check file descriptor bitmap.
void flush () const
 Force a blocking write of the internal buffer.
Socket I/O
These functions handle basic socket I/O.

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.

Protected Member Functions

SocketBaseclone ()
 Clone the current socket.
virtual int internal_write (const unsigned char *output, size_t maxSize) const
 Write data to the socket.
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 SocketBaseprotected_accept ()
 
Exceptions:
QSESocketBaseAcceptFailed 

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)
 
Exceptions:
QSESocketBaseCannotBind 

virtual void protected_listen (int backlog)
 
Exceptions:
QSESocketBaseListenFailed 

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.

Detailed Description

This class implements a loopback socket.

The LoopbackSocket is essentially just a buffer, but it behaves like a socket from the perspective of the I/O abstraction.

Definition at line 36 of file LoopbackSocket.h.


Member Function Documentation

SocketBase* CODEX_Quorum::LoopbackSocket::clone  )  [inline, protected, virtual]
 

Clone the current socket.

This is a largely meaningless operation, since LoopbackSocket connects back to itself. Consequently, we just return the socket itself. Given that clone() is typically only used in accept, this shouldn't even get called.

Reimplemented from CODEX_Quorum::SocketBase.

Definition at line 102 of file LoopbackSocket.h.

Referenced by accept().

void SocketBase::finish_accept  )  [protected, virtual, inherited]
 

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 CODEX_Quorum::SocketBase::protected_accept().

void LoopbackSocket::flush  )  const [virtual]
 

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 from CODEX_Quorum::SocketBase.

Definition at line 94 of file LoopbackSocket.cc.

References CODEX_Quorum::Message::buffer().

int SocketBase::internal_write const unsigned char *  output,
size_t  maxSize
const [protected, virtual, inherited]
 

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.

Parameters:
output Buffer containing the data to write
maxSize Maximum number of bytes to write
Returns:
Number of bytes written
Exceptions:
QSESocketBaseWriteFailed An error occurred during writing.

Reimplemented in CODEX_SSL::SSLSocket.

Definition at line 314 of file Socket.cc.

Referenced by CODEX_Quorum::SocketBase::flush(), and CODEX_Quorum::SocketBase::isset_fd().

bool SocketBase::isset_fd const fd_set *  fd_bitmap,
StateType  s
const [virtual, 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 242 of file Socket.cc.

References CODEX_Quorum::Message::buffer(), CODEX_Quorum::SocketBase::internal_write(), CODEX_Quorum::Message::length(), CODEX_Quorum::SocketBase::m_msgOffset, CODEX_Quorum::SocketBase::m_msgQueue, and CODEX_Quorum::SocketBase::set_fd().

Referenced by CODEX_SSL::SSLSocket::isset_fd(), CODEX_Quorum::RemoteServer::isset_fd(), CODEX_Quorum::LocalServer::isset_fd(), CODEX_Quorum::EchoServer::processRequest(), and CODEX_Quorum::SocketBase::readAll().

bool LoopbackSocket::isset_fd const fd_set *  fd_bitmap,
StateType  s
const
 

Check file descriptor bitmap.

As there is no file descriptor, the output of select(2) is irrelevant for this socket. What matters is whether there is information in the read buffer. Testing write is always going to be successful.

Definition at line 66 of file LoopbackSocket.cc.

References CODEX_Quorum::Message::buffer().

void SocketBase::protected_bind struct sockaddr *  my_addr,
socklen_t  addrlen
[protected, virtual, inherited]
 

Exceptions:
QSESocketBaseCannotBind 

Bug:
This may not be the right place to call setsockopt(2), and it may not always be appropriate to call it.

Todo:
Make a real setsockopt interface.

Definition at line 402 of file Socket.cc.

Referenced by CODEX_Quorum::SocketBase::setup().

size_t SocketBase::readAll Message msg,
size_t  length = 0
const [virtual, inherited]
 

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.

Parameters:
msg Buffer for the message data
length Number of bytes to read, or 0 if unknown
Returns:
Number of bytes left to read in this message
Exceptions:
QSESocketBaseSocketClosed The socket is closed.
QSESocketBaseMessageTooLong The incoming message has a length field greater than 4GB.
QSESocketBaseMessageTooShort The buffer read from the socket is not long enough to contain any data.
QSESocketBaseReadFailed select(2) returned an error or readFrom() threw it.

Definition at line 119 of file Socket.cc.

References CODEX_Quorum::SocketBase::isset_fd(), CODEX_Quorum::SocketBase::readFrom(), and CODEX_Quorum::SocketBase::set_fd().

Referenced by CODEX_Quorum::RemoteServer::receiveFrom().

int SocketBase::set_fd fd_set *  fd_bitmap,
StateType  s
const [virtual, 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 235 of file Socket.cc.

Referenced by CODEX_Quorum::SocketBase::isset_fd(), CODEX_Quorum::EchoServer::processRequest(), CODEX_Quorum::SocketBase::readAll(), CODEX_SSL::SSLSocket::set_fd(), CODEX_Quorum::RemoteServer::set_fd(), and CODEX_Quorum::LocalServer::set_fd().

int CODEX_Quorum::LoopbackSocket::set_fd fd_set *  fd_bitmap,
StateType  s
const [inline]
 

Fill file descriptor bitmap.

This is a dummy routine. Since there isn't a real socket, there's no file descriptor.

Definition at line 79 of file LoopbackSocket.h.

void SocketBase::writeTo const Message input  )  const [virtual, inherited]
 

Write data to a socket.

Parameters:
input Message to queue for writing.
Exceptions:
QSESocketBaseWriteFailed An error occurred while writing.

Definition at line 212 of file Socket.cc.

References CODEX_Quorum::Message::fill(), and CODEX_Quorum::SocketBase::m_msgQueue.

Referenced by CODEX_Quorum::EchoServer::processRequest(), and CODEX_Quorum::RemoteServer::sendTo().


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