CL_TCPConnection Class Reference
[clanNetwork Socket]

TCP connection socket I/O device. More...

#include <tcp_connection.h>

Inheritance diagram for CL_TCPConnection:
Inheritance graph
[legend]

List of all members.

Public Types

Enumerations

enum  SeekMode { seek_set, seek_cur, seek_end }
 

Seeking modes.

More...

Public Member Functions

Construction

 CL_TCPConnection ()
 CL_TCPConnection (const CL_SocketName &remote)
 Constructs a TCPConnection.
 CL_TCPConnection (const CL_SocketName &remote, const CL_SocketName &local)
 Constructs a TCPConnection.
 CL_TCPConnection (int socket, bool close_socket)
 Constructs a TCPConnection.
 ~CL_TCPConnection ()
Attributes

int get_handle () const
 Get Handle.
CL_SocketName get_local_name () const
 Get Local name.
CL_SocketName get_remote_name () const
 Get Remote name.
CL_Event get_read_event ()
 Get Read event.
CL_Event get_write_event ()
 Get Write event.
Operations

void connect (const CL_SocketName &remote)
 Connect.
void connect (const CL_SocketName &remote, const CL_SocketName &local)
 Connect.
void set_handle (int socket, bool close_socket)
 Set handle.
void disconnect_graceful ()
 Performs a graceful shutdown, ensuring all data is sent before the connection is closed.
void disconnect_abortive ()
 Performs an abortive shutdown, closing the connection immediately.
void set_nodelay (bool enable=true)
 Disables or enables buffering data before it is sent.
void set_keep_alive (bool enable, int timeout=0, int interval=0)
 Enables or disables transmitting keep-alive packets.
Attributes

bool is_null () const
 Returns true if this object is invalid.
void throw_if_null () const
 Throw an exception if this object is invalid.
int get_size () const
 Returns the size of data stream.
int get_position () const
 Returns the position in the data stream.
bool is_little_endian () const
 Returns true if the input source is in little endian mode.
const CL_IODeviceProviderget_provider () const
 Returns the provider for this object.
CL_IODeviceProviderget_provider ()
 Returns the provider for this object.
Operations

int send (const void *data, int len, bool send_all=true)
 Send data to device.
int receive (void *data, int len, bool receive_all=true)
 Receive data from device.
int peek (void *data, int len)
 Peek data from device (data is left in the buffer).
bool seek (int position, SeekMode mode=seek_set)
 Seek in data stream.
int read (void *data, int len, bool receive_all=true)
 Alias for receive(data, len, receive_all).
int write (const void *data, int len, bool send_all=true)
 Alias for send(data, len, send_all).
void set_system_mode ()
 Changes input data endianess to the local systems mode.
void set_big_endian_mode ()
 Changes input data endianess to big endian mode. (Default is little endian).
void set_little_endian_mode ()
 Changes input data endianess to little endian mode. This is the default setting.
void write_int64 (cl_byte64 data)
 Writes a signed 64 bit integer to output source.
void write_uint64 (cl_ubyte64 data)
 Writes an unsigned 64 bit integer to output source.
void write_int32 (cl_byte32 data)
 Writes a signed 32 bit integer to output source.
void write_uint32 (cl_ubyte32 data)
 Writes an unsigned 32 bit integer to output source.
void write_int16 (cl_byte16 data)
 Writes a signed 16 bit integer to output source.
void write_uint16 (cl_ubyte16 data)
 Writes an unsigned 16 bit integer to output source.
void write_int8 (cl_byte8 data)
 Writes a signed 8 bit integer to output source.
void write_uint8 (cl_ubyte8 data)
 Writes an unsigned 8 bit integer to output source.
void write_float (float data)
 Writes a float to output source.
void write_string_a (const CL_StringRef8 &str)
 Writes a string to the output source.
void write_string_nul (const CL_StringRef8 &str)
 Writes a nul terminated string to the output source.
void write_string_text (const CL_StringRef8 &str)
 Writes a text string to the output source.
cl_byte64 read_int64 ()
 Reads a signed 64 bit integer from input source.
cl_ubyte64 read_uint64 ()
 Reads an unsigned 64 bit integer from input source.
cl_byte32 read_int32 ()
 Reads a signed 32 bit integer from input source.
cl_ubyte32 read_uint32 ()
 Reads an unsigned 32 bit integer from input source.
cl_byte16 read_int16 ()
 Reads a signed 16 bit integer from input source.
cl_ubyte16 read_uint16 ()
 Reads an unsigned 16 bit integer from input source.
cl_byte8 read_int8 ()
 Reads a signed 8 bit integer from input source.
cl_ubyte8 read_uint8 ()
 Reads an unsigned 8 bit integer from input source.
float read_float ()
 Reads a float from input source.
CL_String8 read_string_a ()
 Reads a string from the input source.
CL_String8 read_string_nul ()
 Reads a nul terminated string from the input source.
CL_String8 read_string_text (const char *skip_initial_chars, const char *read_until_chars, bool allow_eof=true)
 Reads a string from the input source where the source is a text file.
CL_IODevice duplicate ()
 Create a new CL_IODevice referencing the same resource.

Protected Attributes

Implementation

CL_SharedPtr< CL_IODevice_Impl > impl

Detailed Description

TCP connection socket I/O device.


Member Enumeration Documentation

enum CL_IODevice::SeekMode [inherited]

Seeking modes.

Enumerator:
seek_set 

Set to a specific value from the start.

seek_cur 

Set relative to the current position.

seek_end 

Set to a specific value from the end (use negative position).


Constructor & Destructor Documentation

CL_TCPConnection::CL_TCPConnection (  ) 
CL_TCPConnection::CL_TCPConnection ( const CL_SocketName remote  ) 

Constructs a TCPConnection.

Parameters:
remote = Socket Name
CL_TCPConnection::CL_TCPConnection ( const CL_SocketName remote,
const CL_SocketName local 
)

Constructs a TCPConnection.

Parameters:
remote = Socket Name
local = Socket Name
CL_TCPConnection::CL_TCPConnection ( int  socket,
bool  close_socket 
)

Constructs a TCPConnection.

Parameters:
socket = value
close_socket = bool
CL_TCPConnection::~CL_TCPConnection (  ) 

Member Function Documentation

void CL_TCPConnection::connect ( const CL_SocketName remote  ) 

Connect.

Parameters:
remote = Socket Name
void CL_TCPConnection::connect ( const CL_SocketName remote,
const CL_SocketName local 
)

Connect.

Parameters:
remote = Socket Name
local = Socket Name
void CL_TCPConnection::disconnect_abortive (  ) 

Performs an abortive shutdown, closing the connection immediately.

void CL_TCPConnection::disconnect_graceful (  ) 

Performs a graceful shutdown, ensuring all data is sent before the connection is closed.

CL_IODevice CL_IODevice::duplicate (  )  [inherited]

Create a new CL_IODevice referencing the same resource.

int CL_TCPConnection::get_handle (  )  const

Get Handle.

Returns:
handle
CL_SocketName CL_TCPConnection::get_local_name (  )  const

Get Local name.

Returns:
local_name
int CL_IODevice::get_position (  )  const [inherited]

Returns the position in the data stream.

Returns -1 if the position is unknown.

Returns:
The size (-1 if position is unknown)
const CL_IODeviceProvider* CL_IODevice::get_provider (  )  const [inherited]

Returns the provider for this object.

CL_IODeviceProvider* CL_IODevice::get_provider (  )  [inherited]

Returns the provider for this object.

CL_Event CL_TCPConnection::get_read_event (  ) 

Get Read event.

Returns:
read_event
CL_SocketName CL_TCPConnection::get_remote_name (  )  const

Get Remote name.

Returns:
remote_name
int CL_IODevice::get_size (  )  const [inherited]

Returns the size of data stream.

Returns -1 if the size is unknown.

Returns:
The size (-1 if size is unknown)
CL_Event CL_TCPConnection::get_write_event (  ) 

Get Write event.

Returns:
write_event
bool CL_IODevice::is_little_endian (  )  const [inherited]

Returns true if the input source is in little endian mode.

Returns:
true if little endian
bool CL_IODevice::is_null (  )  const [inline, inherited]

Returns true if this object is invalid.

Reimplemented in CL_HTTPServerConnection.

int CL_IODevice::peek ( void *  data,
int  len 
) [inherited]

Peek data from device (data is left in the buffer).

Parameters:
data Data to receive
len Maximum length of data to receive
Returns:
size of data received.
int CL_IODevice::read ( void *  data,
int  len,
bool  receive_all = true 
) [inherited]

Alias for receive(data, len, receive_all).

Parameters:
data Data to receive
len Length to receive
receive_all true to receive all the data. false = receive part of the data, if it would block
Returns:
size of data received
float CL_IODevice::read_float (  )  [inherited]

Reads a float from input source.

Warning, this is not portable

Returns:
The float read.
cl_byte16 CL_IODevice::read_int16 (  )  [inherited]

Reads a signed 16 bit integer from input source.

Returns:
The integer read.
cl_byte32 CL_IODevice::read_int32 (  )  [inherited]

Reads a signed 32 bit integer from input source.

Returns:
The integer read.
cl_byte64 CL_IODevice::read_int64 (  )  [inherited]

Reads a signed 64 bit integer from input source.

Returns:
The integer read.
cl_byte8 CL_IODevice::read_int8 (  )  [inherited]

Reads a signed 8 bit integer from input source.

Returns:
The integer read.
CL_String8 CL_IODevice::read_string_a (  )  [inherited]

Reads a string from the input source.

The binary format expected in the input source is first an uint32 telling the length of the string, and then the string itself.

Returns:
The string read.
CL_String8 CL_IODevice::read_string_nul (  )  [inherited]

Reads a nul terminated string from the input source.

The binary format expected in the input source is a nul terminated string. (The NUL termintor is read, so that the file position is set after the NUL)

Returns:
The string read.
CL_String8 CL_IODevice::read_string_text ( const char *  skip_initial_chars,
const char *  read_until_chars,
bool  allow_eof = true 
) [inherited]

Reads a string from the input source where the source is a text file.

After reading the input source up to "read_until_chars", the file position is set to the first character that was not read. If the file contains NUL characters, then the input is read up to the NUL character, and the file position is set AFTER the NUL)

Parameters:
skip_initial_chars Ignore any of these characters at the start of the string. NULL = Do not ignore any characters
read_until_chars Read from the input until any of these characters are found. NULL = Read until the end of the file
allow_eof Allow EOF
Returns:
The string read.
cl_ubyte16 CL_IODevice::read_uint16 (  )  [inherited]

Reads an unsigned 16 bit integer from input source.

Returns:
The integer read.
cl_ubyte32 CL_IODevice::read_uint32 (  )  [inherited]

Reads an unsigned 32 bit integer from input source.

Returns:
The integer read.
cl_ubyte64 CL_IODevice::read_uint64 (  )  [inherited]

Reads an unsigned 64 bit integer from input source.

Returns:
The integer read.
cl_ubyte8 CL_IODevice::read_uint8 (  )  [inherited]

Reads an unsigned 8 bit integer from input source.

Returns:
The integer read.
int CL_IODevice::receive ( void *  data,
int  len,
bool  receive_all = true 
) [inherited]

Receive data from device.

Parameters:
data Data to receive
len Length to receive
receive_all true to receive all the data. false = receive part of the data, if it would block
Returns:
size of data received
bool CL_IODevice::seek ( int  position,
SeekMode  mode = seek_set 
) [inherited]

Seek in data stream.

Parameters:
position Position to use (usage depends on the seek mode)
mode Seek mode
Returns:
false = Failed
int CL_IODevice::send ( const void *  data,
int  len,
bool  send_all = true 
) [inherited]

Send data to device.

If the device databuffer is too small, it will be extended (ie grow memory block size or file size)

Parameters:
data Data to send
len Length to send
send_all true to send all the data. false = send part of the data, if it would block
Returns:
size of data sent
void CL_IODevice::set_big_endian_mode (  )  [inherited]

Changes input data endianess to big endian mode. (Default is little endian).

void CL_TCPConnection::set_handle ( int  socket,
bool  close_socket 
)

Set handle.

Parameters:
socket = value
close_socket = bool
void CL_TCPConnection::set_keep_alive ( bool  enable,
int  timeout = 0,
int  interval = 0 
)

Enables or disables transmitting keep-alive packets.

Parameters:
enable = True to enable keep-alive, false to disable
timeout = Specifies the timeout, in milliseconds, with no activity until the first keep-alive packet is sent.
interval = Specifies the interval, in milliseconds, between when successive keep-alive packets are sent if no acknowledgment is received.

Both timeout and interval must be set to a non-zero value before any of them are used. They cannot be specified individually.

void CL_IODevice::set_little_endian_mode (  )  [inherited]

Changes input data endianess to little endian mode. This is the default setting.

void CL_TCPConnection::set_nodelay ( bool  enable = true  ) 

Disables or enables buffering data before it is sent.

void CL_IODevice::set_system_mode (  )  [inherited]

Changes input data endianess to the local systems mode.

void CL_IODevice::throw_if_null (  )  const [inherited]

Throw an exception if this object is invalid.

Reimplemented in CL_HTTPServerConnection.

int CL_IODevice::write ( const void *  data,
int  len,
bool  send_all = true 
) [inherited]

Alias for send(data, len, send_all).

Parameters:
data Data to send
len Length to send
send_all true to send all the data. false = send part of the data, if it would block
Returns:
size of data sent
void CL_IODevice::write_float ( float  data  )  [inherited]

Writes a float to output source.

Parameters:
data = Float to write

Warning, this is not portable.

void CL_IODevice::write_int16 ( cl_byte16  data  )  [inherited]

Writes a signed 16 bit integer to output source.

Parameters:
data Integer to write
void CL_IODevice::write_int32 ( cl_byte32  data  )  [inherited]

Writes a signed 32 bit integer to output source.

Parameters:
data Integer to write
void CL_IODevice::write_int64 ( cl_byte64  data  )  [inherited]

Writes a signed 64 bit integer to output source.

Parameters:
data Integer to write
void CL_IODevice::write_int8 ( cl_byte8  data  )  [inherited]

Writes a signed 8 bit integer to output source.

Parameters:
data Integer to write
void CL_IODevice::write_string_a ( const CL_StringRef8 str  )  [inherited]

Writes a string to the output source.

Parameters:
str String to write

The binary format written to the output source is first an uint32 telling the length of the string, and then the string itself.

void CL_IODevice::write_string_nul ( const CL_StringRef8 str  )  [inherited]

Writes a nul terminated string to the output source.

Parameters:
str String to write

The binary format written to the output source is the string content followed by the NUL character.

void CL_IODevice::write_string_text ( const CL_StringRef8 str  )  [inherited]

Writes a text string to the output source.

Parameters:
str String to write

The binary format written to the output source is the string content appended with a native newline. On Windows the newline is CR+LF sequence and on other platforms it is only LF character. This function is intended for use with text files.

void CL_IODevice::write_uint16 ( cl_ubyte16  data  )  [inherited]

Writes an unsigned 16 bit integer to output source.

Parameters:
data Integer to write
void CL_IODevice::write_uint32 ( cl_ubyte32  data  )  [inherited]

Writes an unsigned 32 bit integer to output source.

Parameters:
data Integer to write
void CL_IODevice::write_uint64 ( cl_ubyte64  data  )  [inherited]

Writes an unsigned 64 bit integer to output source.

Parameters:
data Integer to write
void CL_IODevice::write_uint8 ( cl_ubyte8  data  )  [inherited]

Writes an unsigned 8 bit integer to output source.

Parameters:
data Integer to write

Member Data Documentation

CL_SharedPtr<CL_IODevice_Impl> CL_IODevice::impl [protected, inherited]

The documentation for this class was generated from the following file: