NewNet::ClientSocket Class Reference

Base class for network client sockets. More...

#include <nnclientsocket.h>

Inheritance diagram for NewNet::ClientSocket:

NewNet::Socket NewNet::Object NewNet::TcpClientSocket NewNet::UnixClientSocket List of all members.

Public Member Functions

 ClientSocket ()
 Create an empty client socket.
virtual void disconnect ()
 Disconnect the client socket.
virtual void process ()
 Process network events.
void send (const unsigned char *data, size_t n)
 Append data to the send buffer.
BuffersendBuffer ()
 Return a reference to the send buffer.
BufferreceiveBuffer ()
 Return a reference to the receive buffer.

Public Attributes

Event< ClientSocket * > cannotConnectEvent
 Invoked when the socket can't connect.
Event< ClientSocket * > connectedEvent
 Invoked when the socket is connected.
Event< ClientSocket * > disconnectedEvent
 Invoked when the socket is disconnected.
Event< ClientSocket * > dataReceivedEvent
 Invoked when there's new data waiting in the receive buffer.
Event< ClientSocket * > dataSentEvent
 Invoked when data has been sent through the network socket.

Detailed Description

Provides a base class that will monitor the state of the socket and emit events when something happens. Note: this class is usually not used by your application. Applications should use TcpClientSocket or UnixClientSocket instead.

Definition at line 34 of file nnclientsocket.h.


Constructor & Destructor Documentation

NewNet::ClientSocket::ClientSocket (  )  [inline]

This will create an empty client socket. The client socket starts in an uninitialized state without a descriptor.

Definition at line 40 of file nnclientsocket.h.


Member Function Documentation

void NewNet::ClientSocket::disconnect (  )  [virtual]

This immediately disconnects the client socket and invokes the disconnected event.

Definition at line 26 of file nnclientsocket.cpp.

References NewNet::Socket::descriptor(), disconnectedEvent, NewNet::Socket::setSocketState(), NewNet::Socket::SocketConnected, NewNet::Socket::SocketDisconnected, and NewNet::Socket::socketState().

void NewNet::ClientSocket::process (  )  [virtual]

This method is called by the reactor, it will process the events specified in readyState(): read from the socket, detect disconnections and send data through the socket.

Reimplemented from NewNet::Socket.

Definition at line 40 of file nnclientsocket.cpp.

References NewNet::Buffer::append(), cannotConnectEvent, connectedEvent, NewNet::Buffer::count(), NewNet::Buffer::data(), dataReceivedEvent, dataSentEvent, NewNet::Socket::dataWaiting(), NewNet::Socket::descriptor(), disconnectedEvent, NewNet::Socket::downRateLimiter(), NewNet::Socket::ErrorCannotConnect, NewNet::Socket::ErrorUnknown, NewNet::Socket::readyState(), NewNet::Buffer::seek(), send(), NewNet::Socket::setDataWaiting(), NewNet::Socket::setReadyState(), NewNet::Socket::setSocketError(), NewNet::Socket::setSocketState(), NewNet::Socket::SocketConnected, NewNet::Socket::SocketConnecting, NewNet::Socket::SocketDisconnected, NewNet::Socket::socketState(), NewNet::Socket::StateException, NewNet::Socket::StateReceive, NewNet::Socket::StateSend, NewNet::RateLimiter::transferred(), and NewNet::Socket::upRateLimiter().

void NewNet::ClientSocket::send ( const unsigned char *  data,
size_t  n 
) [inline]

This is a convenience function that will append data to the send buffer and will mark the flag that specifies that the socket wants to send data.

Definition at line 59 of file nnclientsocket.h.

References NewNet::Buffer::append(), NewNet::Buffer::count(), and NewNet::Socket::setDataWaiting().

Referenced by process().

Buffer& NewNet::ClientSocket::sendBuffer (  )  [inline]

Returns a reference to the send buffer. Note: if you manipulate the send buffer, be sure to call setDataWaiting(bool) to make sure the data waiting flag is set correctly.

Definition at line 69 of file nnclientsocket.h.

Buffer& NewNet::ClientSocket::receiveBuffer (  )  [inline]

Returns a reference to the receive buffer.

Definition at line 76 of file nnclientsocket.h.


Member Data Documentation

Event<ClientSocket *> NewNet::ClientSocket::cannotConnectEvent

This event will be invoked when the socket detects it cannot connect to the remote host.

Definition at line 84 of file nnclientsocket.h.

Referenced by NewNet::UnixClientSocket::connect(), NewNet::TcpClientSocket::connect(), and process().

Event<ClientSocket *> NewNet::ClientSocket::connectedEvent

This event will be invoked when the socket detects it has successfully connected to the remote host.

Definition at line 88 of file nnclientsocket.h.

Referenced by NewNet::UnixClientSocket::connect(), NewNet::TcpClientSocket::connect(), and process().

Event<ClientSocket *> NewNet::ClientSocket::disconnectedEvent

This event will be invoked when the socket has been disconnected from the remote host.

Definition at line 92 of file nnclientsocket.h.

Referenced by disconnect(), and process().

Event<ClientSocket *> NewNet::ClientSocket::dataReceivedEvent

This event will be invoked when the socket received information from the remote host. The information will be appended to the receive buffer.

Definition at line 97 of file nnclientsocket.h.

Referenced by process().

Event<ClientSocket *> NewNet::ClientSocket::dataSentEvent

This event will be invoked when data has been send to the remote host.

Definition at line 101 of file nnclientsocket.h.

Referenced by process().


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