Entire Class Index | Main Class Index | Cross Index | Global Index

# Class CL_Socket

This is the lowlevel raw socket interface in clanlib.
Contained in: global
Derived from: none
Derived by: CL_BufferedSocket
Group: Network (Sockets)

#include <ClanLib/network.h>

### public function member index:

### Construction:

`` | `CL_Socket` | `()`;
`` | `CL_Socket` | `(`int` `socket`)`;
`` | `CL_Socket` | `(`Type` `type`)`;
`` | `CL_Socket` | `(`const` `CL_Socket`& `copy`)`;
``virtual`` | `~CL_Socket` | `()`;

### Attributes:

``int`` | `get_socket` | `() `const``;
``CL_EventTrigger`*` | `get_read_trigger` | `() `const``;
``CL_EventTrigger`*` | `get_write_trigger` | `() `const``;
``CL_EventTrigger`*` | `get_exception_trigger` | `() `const``;
``CL_IPAddress`` | `get_source_address` | `() `const``;
``CL_IPAddress`` | `get_dest_address` | `() `const``;
``CL_Signal_v0`&` | `sig_read_triggered` | `()`;
``CL_Signal_v0`&` | `sig_write_triggered` | `()`;
``CL_Signal_v0`&` | `sig_exception_triggered` | `()`;

### Operations:

``CL_Socket`&` | `operator``=` | `(`const` `CL_Socket`& `other`)`;
``void`` | `set_nonblocking` | `(`bool` `nonblocking` = true)`;
``void`` | `set_nodelay` | `(`bool` `nodelay` = true)`;
``int`` | `send` | `(`const` `void`* `data`, `int` `size`)`;
``int`` | `send` | `(`const` `void`* `data`, `int` `size`, `const` `CL_IPAddress`& `dest`)`;
``int`` | `send` | `(`const` `std::string`& `string`)`;
``void`` | `push` | `(`const` `std::string`& `string`)`;
``int`` | `recv` | `(`void`* `data`, `int` `size`)`;
``int`` | `recv` | `(`void`* `data`, `int` `size`, `CL_IPAddress`& `from`)`;
``void`` | `connect` | `(`const` `CL_IPAddress`& `address`)`;
``void`` | `shutdown` | `(`ShutdownHow` `how`)`;
``void`` | `bind` | `(`const` `CL_IPAddress`& `address`)`;
``void`` | `listen` | `(`int` `backlog`)`;
``CL_Socket`` | `accept` | `()`;

### Implementation:

`` | `CL_Socket` | `(`class` `CL_Socket_Generic`* `impl`)`;

## Description:

Its main purpose is to write the C sockets API, providing error handling via exceptions, and socket waiting (select) via the clanlib event waiting system (CL_EventListener, CL_EventTrigger).

## Function Member Descriptions:

CL_Socket::CL_Socket - Constructs a null socket.
`` `CL_Socket` `()`;

CL_Socket::CL_Socket - Constructs an attached socket.
`` `CL_Socket` `(`int` `socket`)`;

CL_Socket::CL_Socket - Constructs a new socket using the specified protocol type.
`` `CL_Socket` `(`Type` `type`)`;

CL_Socket::CL_Socket - Copy constructor.
`` `CL_Socket` `(`const` `CL_Socket`& `copy`)`;

CL_Socket::accept - Accept a connection on the socket.
``CL_Socket`` `accept` `()`;

CL_Socket::bind - Bind the socket to the specified address.
``void`` `bind` `(`const` `CL_IPAddress`& `address`)`;

CL_Socket::connect - Initiate a connection on the socket.
``void`` `connect` `(`const` `CL_IPAddress`& `address`)`;

CL_Socket::get_dest_address - Returns the name of the destination socket we are connected to.
``CL_IPAddress`` `get_dest_address` `() `const``;

CL_Socket::get_exception_trigger - Returns an event trigger that triggers when an exception occurs on the socket.
``CL_EventTrigger`*` `get_exception_trigger` `() `const``;

CL_Socket::get_read_trigger - Returns an event trigger that triggers when socket has data ready to be read.
``CL_EventTrigger`*` `get_read_trigger` `() `const``;

CL_Socket::get_socket - Returns the raw socket handle (for use with the lowlevel socket functions).
``int`` `get_socket` `() `const``;

CL_Socket::get_source_address - Returns the socket name.
``CL_IPAddress`` `get_source_address` `() `const``;

CL_Socket::get_write_trigger - Returns an event trigger that triggers when socket is ready for additional data.
``CL_EventTrigger`*` `get_write_trigger` `() `const``;

CL_Socket::listen - Listen for connections on the socket.
``void`` `listen` `(`int` `backlog`)`;

CL_Socket::operator = - Copy operator
``CL_Socket`&` `operator``=` `(`const` `CL_Socket`& `other`)`;

CL_Socket::recv - Reads data from the socket. Returns the amount that was read.
``int`` `recv` `(`void`* `data`, `int` `size`)`;

CL_Socket::recv - Reads data from the socket, storing the from address in the passed parameter.
``int`` `recv` `(`void`* `data`, `int` `size`, `CL_IPAddress`& `from`)`;

CL_Socket::send - Writes data to socket. Returns the amount that was written.
``int`` `send` `(`const` `void`* `data`, `int` `size`)`;

CL_Socket::send - Writes data to socket, using the specified destination host.
``int`` `send` `(`const` `void`* `data`, `int` `size`, `const` `CL_IPAddress`& `dest`)`;

CL_Socket::set_nodelay - If enabled, don't delay send to coalesce packets.
``void`` `set_nodelay` `(`bool` `nodelay` = true)`;

CL_Socket::set_nonblocking - Sets the socket blocking mode.
``void`` `set_nonblocking` `(`bool` `nonblocking` = true)`;

CL_Socket::shutdown - Shut down part of full-duplex connection.
``void`` `shutdown` `(`ShutdownHow` `how`)`;

CL_Socket::sig_exception_triggered - This signal is invoked when an exception occurred on the socket.
``CL_Signal_v0`&` `sig_exception_triggered` `()`;

CL_Socket::sig_read_triggered - This signal is invoked when the socket has data ready to be read.
``CL_Signal_v0`&` `sig_read_triggered` `()`;

CL_Socket::sig_write_triggered - This signal is invoked when the socket has data ready to be written.
``CL_Signal_v0`&` `sig_write_triggered` `()`;

CL_Socket::~CL_Socket - Socket destructor
``virtual`` `~CL_Socket` `()`;

## Variable Member Descriptions:

CL_Socket::input - Input source that operates on the socket.
``CL_InputSource_Socket`` ``input`;`

CL_Socket::output - Output source that operates on the socket.
``CL_OutputSource_Socket`` ``output`;`