CoreSocket Class Reference

The abstract core socket class. More...

#include <core_socket.h>

Inheritance diagram for CoreSocket:

TCPSocket UDPSocket

List of all members.

Public Member Functions

 CoreSocket ()
 The default constructor.
 CoreSocket (socket_t socket)
 The constructor for an existing socket.
virtual ~CoreSocket ()
 The destructor.
virtual int Close ()
 Close the socket.
virtual int GetError () const
 Get the error value for the socket.
u_long GetRemoteHost ()
 Fetches the IP address of the remote host.
const char * GetRemoteIP ()
 Fetches the IP address of the remote host.
u_long GetLocalHost ()
 Fetches the IP address of the remote host.
const char * GetLocalIP ()
 Fetches the IP address of the remote host.
socket_t GetSocket ()
 Gives access to the socket itself (for extensibility only).
virtual bool IsReadable () const
 Determines whether the socket is ready for a Read operation.
virtual bool IsWritable () const
 Determines whether the socket is ready for a Read operation.
virtual socketState State () const
 Fetch the state of the socket.
virtual int Listen (unsigned short _port)=0
 Opens the port specified to listen for incoming connections.
virtual int Read (char *_output, unsigned int *_len)
 Reads a block of data with a specified maximum size.
virtual int Read (std::string &_output)
 Reads a block of data with a specified maximum size.
virtual int Send (const void *_data, size_t _length)
 Sends a block of data.
virtual int Send (std::string _data)
 Sends a string.

Protected Member Functions

virtual int SetAttributes (socket_t _socket)=0
 Sets some important attributes on the socket.

Protected Attributes

int m_bufferSize
 The maximum number of bytes to read per CoreSocket::Read or CoreSocket::ReadLine call.
char m_calledInitialise
 Indicates whether __socket_initialise() was called when the class was initialized.
socket_t m_sock
 Stores the socket data.
socketProtocol m_proto
 Indicates the protocol used by this socket instance.
socketState m_state
 Indicates the current state of m_sock.


Detailed Description

The abstract core socket class.

Abstract class only. Must be inherited.


Member Function Documentation

virtual int Close (  )  [virtual]

Close the socket.

Doesn't need to be called before an instance is destructed, because it is automatically called in the destructor.

Returns:
Currently always returns CC_ERR_NONE.

virtual int GetError (  )  const [virtual]

Get the error value for the socket.

Returns:
The error value for the socket.

u_long GetLocalHost (  ) 

Fetches the IP address of the remote host.

Returns:
The host represented in old-style sockaddr_in format.

const char* GetLocalIP (  ) 

Fetches the IP address of the remote host.

Returns:
A pointer to the IP address string in dot notation. Note that the pointer this returns will be reused on the next GetRemoteIP call, so the data pointed at by the return value should be copied into another buffer.

u_long GetRemoteHost (  ) 

Fetches the IP address of the remote host.

Returns:
The host represented in old-style sockaddr_in format.

const char* GetRemoteIP (  ) 

Fetches the IP address of the remote host.

Returns:
A pointer to the IP address string in dot notation. Note that the pointer this returns will be reused on the next GetRemoteIP call, so the data pointed at by the return value should be copied into another buffer.

socket_t GetSocket (  ) 

Gives access to the socket itself (for extensibility only).

Returns:
CoreSocket::m_sock

virtual bool IsReadable (  )  const [virtual]

Determines whether the socket is ready for a Read operation.

Returns:
True if the socket is writable, false otherwise.
Warning:
If the return value is false, check the return value of State() to make sure that the socket hasn't entered an error state.
See also:
State

CrissCross::Network::socketState

virtual bool IsWritable (  )  const [virtual]

Determines whether the socket is ready for a Read operation.

Returns:
True if the socket is writable, false otherwise.
Warning:
If the return value is false, check the return value of State() to make sure that the socket hasn't entered an error state.
See also:
State

CrissCross::Network::socketState

virtual int Listen ( unsigned short  _port  )  [pure virtual]

Opens the port specified to listen for incoming connections.

Parameters:
_port The port to listen on.
Returns:
If the return value is greater than zero, it is an 'errno' value. If it is less than zero, it is a socketError value.

Implemented in TCPSocket, and UDPSocket.

virtual int Read ( std::string &  _output  )  [virtual]

Reads a block of data with a specified maximum size.

Parameters:
_output An std::string in which the data will be stored.
Returns:
If the return value is greater than zero, it is an 'errno' value. If it is less than zero, it is a socketError value.

virtual int Read ( char *  _output,
unsigned int *  _len 
) [virtual]

Reads a block of data with a specified maximum size.

Parameters:
_output A buffer with size _len. Will contain the received data on return.
_len The maximum number of bytes to read. On return, this will contain the size of data received.
Returns:
If the return value is greater than zero, it is an 'errno' value. If it is less than zero, it is a socketError value.

virtual int Send ( std::string  _data  )  [virtual]

Sends a string.

Parameters:
_data The string to be sent.
Returns:
The actual number of bytes sent.

virtual int Send ( const void *  _data,
size_t  _length 
) [virtual]

Sends a block of data.

Parameters:
_data The data to be sent.
_length The number of bytes of _data to send (must NOT exceed the size of _data).
Returns:
The actual number of bytes sent.

virtual int SetAttributes ( socket_t  _socket  )  [protected, pure virtual]

Sets some important attributes on the socket.

Will set SO_LINGER and TCP_NODELAY on TCP sockets.

Parameters:
_socket The socket to modify.
Returns:
CC_ERR_NONE if no error is encountered, otherwise returns 'errno'.

Implemented in TCPSocket, and UDPSocket.

virtual socketState State (  )  const [virtual]

Fetch the state of the socket.

Returns:
The current state of m_sock.
See also:
CrissCross::Network::socketState

Reimplemented in TCPSocket.


Generated on Sun Feb 8 11:10:00 2009 for CrissCross by  doxygen 1.5.8