NewNet::Socket Class Reference

Base class for network sockets. More...

#include <nnsocket.h>

Inheritance diagram for NewNet::Socket:

NewNet::Object NewNet::ClientSocket NewNet::ServerSocket NewNet::TcpClientSocket NewNet::UnixClientSocket NewNet::TcpServerSocket NewNet::UnixServerSocket List of all members.

Public Types

enum  SocketState {
  SocketUninitialized, SocketListening, SocketConnecting, SocketConnected,
  SocketDisconnecting, SocketDisconnected, SocketException
}
 Enumeration to describe the state of the socket. More...
enum  ReadyState { StateSend = 1, StateReceive = 2, StateException = 4 }
 Enumeration to describe pending network events. More...
enum  SocketError {
  ErrorNoError, ErrorCannotResolve, ErrorInvalidPath, ErrorCannotConnect,
  ErrorCannotBind, ErrorCannotListen, ErrorUnknown
}
 Enumeration to describe the error that last occured. More...

Public Member Functions

 Socket ()
 Create a new uninitialized socket.
Reactorreactor () const
 Return the associated reactor.
void setReactor (Reactor *reactor)
 Set the associated reactor.
int descriptor () const
 Return the socket's descriptor.
void setDescriptor (int fd)
 Set the socket's descriptor.
SocketState socketState () const
 Return the current socket state.
void setSocketState (SocketState socketState)
 Set the current socket state.
int readyState () const
 Return the socket's ready state.
void setReadyState (int readyState)
 Set the socket's ready state.
SocketError socketError () const
 Return the socket's error state.
void setSocketError (SocketError socketError)
 Set the socket's error state.
bool dataWaiting () const
 Return wether there's data waiting to be sent.
void setDataWaiting (bool dataWaiting)
 Set the data waiting flag.
RateLimiterdownRateLimiter ()
 Return the current download rate limiter.
void setDownRateLimiter (RateLimiter *limiter)
 Set the current download rate limiter.
RateLimiterupRateLimiter ()
 Return the current upload rate limiter.
void setUpRateLimiter (RateLimiter *limiter)
 Set the current upload rate limiter.
virtual void process ()
 Processor function.

Detailed Description

This provides a generic base class for both client and server sockets. The reactor doesn't differentiate between those two and just operates on this socket type.

Definition at line 36 of file nnsocket.h.


Member Enumeration Documentation

enum NewNet::Socket::SocketState

This defines the current state of the socket. The value can be retrieved with socketState() and set with setSocketState().

Enumerator:
SocketUninitialized  The socket is uninitialized.
SocketListening  The socket is listening for client connections.
SocketConnecting  The socket is currently busy connecting.
SocketConnected  The socket is connected.
SocketDisconnecting  The socket is currently busy disconnecting.
SocketDisconnected  The socket is disconnected.
SocketException  An error occured, the socket is dead.

Definition at line 42 of file nnsocket.h.

enum NewNet::Socket::ReadyState

This defines what kind of network events are currently pending on the socket. The value can be retrieved using readyState() and set with setReadyState().

Enumerator:
StateSend  The socket is ready to send data.
StateReceive  Data was received, socket is ready to read.
StateException  Out-of-band data was received.

Definition at line 57 of file nnsocket.h.

enum NewNet::Socket::SocketError

This defines what kind of error made the state go into exception state. It can be retrieved using socketError() and set with setSocketError().

Enumerator:
ErrorNoError  No error at all, everything's fine.
ErrorCannotResolve  The socket was unable to resolve the destination host.
ErrorInvalidPath  The specified path was invalid.
ErrorCannotConnect  The socket was unable to connect to the remote end.
ErrorCannotBind  The socket couldn't bind to the specified address.
ErrorCannotListen  The socket couldn't listen on the specified address.
ErrorUnknown  An unknown error occured.

Definition at line 68 of file nnsocket.h.


Constructor & Destructor Documentation

NewNet::Socket::Socket (  )  [inline]

This creates a new socket that has an invalid descriptor, is uninitialized, has no pending events, no error and no data waiting.

Definition at line 82 of file nnsocket.h.


Member Function Documentation

Reactor* NewNet::Socket::reactor (  )  const [inline]

Return the reactor this socket is associated to, if any.

Definition at line 90 of file nnsocket.h.

Referenced by NewNet::Reactor::add(), NewNet::Reactor::remove(), and setReactor().

void NewNet::Socket::setReactor ( Reactor reactor  )  [inline]

This is called by the reactor when the socket is added to the reactor. Note: stores a regular pointer to the reactor.

Definition at line 98 of file nnsocket.h.

References reactor().

Referenced by NewNet::Reactor::add(), and NewNet::Reactor::remove().

int NewNet::Socket::descriptor (  )  const [inline]

This returns the socket's descriptor.

Definition at line 105 of file nnsocket.h.

Referenced by NewNet::UnixClientSocket::connect(), NewNet::TcpClientSocket::connect(), NewNet::UnixServerSocket::disconnect(), NewNet::ServerSocket::disconnect(), NewNet::ClientSocket::disconnect(), NewNet::ServerSocket::process(), and NewNet::ClientSocket::process().

void NewNet::Socket::setDescriptor ( int  fd  )  [inline]

This initializes the socket's descriptor. Usually called by subclasses when connecting or by socket factories when accepting a new client.

Definition at line 114 of file nnsocket.h.

Referenced by NewNet::UnixClientSocket::connect(), NewNet::TcpClientSocket::connect(), NewNet::UnixServerSocket::listen(), and NewNet::TcpServerSocket::listen().

SocketState NewNet::Socket::socketState (  )  const [inline]

Retrieves the current socket state.

Definition at line 121 of file nnsocket.h.

Referenced by NewNet::UnixClientSocket::connect(), NewNet::TcpClientSocket::connect(), NewNet::UnixServerSocket::disconnect(), NewNet::ServerSocket::disconnect(), NewNet::ClientSocket::disconnect(), and NewNet::ClientSocket::process().

void NewNet::Socket::setSocketState ( SocketState  socketState  )  [inline]

Changes the current socket state.

Definition at line 128 of file nnsocket.h.

Referenced by NewNet::UnixClientSocket::connect(), NewNet::TcpClientSocket::connect(), NewNet::ServerSocket::disconnect(), NewNet::ClientSocket::disconnect(), NewNet::UnixServerSocket::listen(), NewNet::TcpServerSocket::listen(), NewNet::ClientSocket::process(), and setSocketError().

int NewNet::Socket::readyState (  )  const [inline]

Returns what kind of events are pending on the socket.

Definition at line 135 of file nnsocket.h.

Referenced by NewNet::ServerSocket::process(), and NewNet::ClientSocket::process().

void NewNet::Socket::setReadyState ( int  readyState  )  [inline]

Usually called by subclasses and the reactor to specify what kind of network events are pending.

Definition at line 143 of file nnsocket.h.

Referenced by NewNet::ServerSocket::process(), and NewNet::ClientSocket::process().

SocketError NewNet::Socket::socketError (  )  const [inline]

Returns what kind of error last occured on the socket.

Definition at line 150 of file nnsocket.h.

void NewNet::Socket::setSocketError ( SocketError  socketError  )  [inline]

Usually called by subclasses to specify what kind of error occured on the socket.

Definition at line 158 of file nnsocket.h.

References setSocketState(), and SocketException.

Referenced by NewNet::UnixClientSocket::connect(), NewNet::TcpClientSocket::connect(), NewNet::UnixServerSocket::listen(), NewNet::TcpServerSocket::listen(), and NewNet::ClientSocket::process().

bool NewNet::Socket::dataWaiting (  )  const [inline]

Called by the reactor to determine wether the socket has data waiting to be sent.

Definition at line 167 of file nnsocket.h.

Referenced by NewNet::ClientSocket::process().

void NewNet::Socket::setDataWaiting ( bool  dataWaiting  )  [inline]

Called by subclasses to specify that there's data waiting to be sent

Definition at line 174 of file nnsocket.h.

Referenced by NewNet::ClientSocket::process(), and NewNet::ClientSocket::send().

RateLimiter* NewNet::Socket::downRateLimiter (  )  [inline]

Return the current download rate limiter.

Definition at line 181 of file nnsocket.h.

Referenced by NewNet::ClientSocket::process().

void NewNet::Socket::setDownRateLimiter ( RateLimiter limiter  )  [inline]

Set the current download rate limiter. Note: stores a RefPtr to the rate limiter.

Definition at line 189 of file nnsocket.h.

RateLimiter* NewNet::Socket::upRateLimiter (  )  [inline]

Return the current upload rate limiter.

Definition at line 196 of file nnsocket.h.

Referenced by NewNet::ClientSocket::process().

void NewNet::Socket::setUpRateLimiter ( RateLimiter limiter  )  [inline]

Set the current upload rate limiter. Note: stores a RefPtr to the rate limiter.

Definition at line 204 of file nnsocket.h.

virtual void NewNet::Socket::process (  )  [inline, virtual]

This is called by the reactor when there are pending network events.

Reimplemented in NewNet::ClientSocket, and NewNet::ServerSocket.

Definition at line 211 of file nnsocket.h.


The documentation for this class was generated from the following file:
Generated on Sun Jan 7 14:00:02 2007 for NewNet by  doxygen 1.5.1