AXCEL C++ Framework
Elegance through abstraction
Public Member Functions | Public Attributes
axcel::net::socket::tcp Class Reference

Transmission Control Protocol socket. More...

#include <axcel.h>

Inheritance diagram for axcel::net::socket::tcp:
axcel::io::ios axcel::io::input axcel::io::output axcel::io::iob axcel::io::iob axcel::object axcel::object

List of all members.

Public Member Functions

virtual string type ()
 Get type of object.
virtual operator string ()
 Convert to string.
 tcp ()
int putc (int c)
 Write byte.
int getc ()
 Read byte.
data dump ()
 Read until EOF.
int puts (const char *s)
 Send data.
int send (const char *buf, size_t len)
 Send data.
int recv (char *buf, size_t len)
 Recieve data.
bool connect (const char *host, const char *port)
 Connect to host.
bool listen (const char *port, int backlog)
 Bind and Listen on port.
bool accept (tcp &f)
 Accept connection.
bool blocking (int i=-1)
 Set blocking mode.
bool ready ()
bool close ()
 Shutdown and close socket.
bool connected ()
 Check for connected socket.
string ip ()
 Get peer ip address.
string name ()
 Get peer name.

Public Attributes

int fd

Detailed Description

Transmission Control Protocol socket.

Definition at line 923 of file axcel.h.


Constructor & Destructor Documentation

axcel::net::socket::tcp::tcp ( )

Definition at line 3965 of file axcel.cpp.


Member Function Documentation

bool axcel::net::socket::tcp::accept ( tcp f)

Accept connection.

Parameters:
fReference to net::socket::tcp object
Returns:
true success, false failure

Accepts connection on current listening socket and associates the client socket to f. If no pending connections are present, and the socket is not marked as nonblocking, accept() blocks the caller until a connection is present. If the socket is marked nonblocking and no pedning connections are present, accept() fails.

Definition at line 3878 of file axcel.cpp.

bool axcel::net::socket::tcp::blocking ( int  i = -1)

Set blocking mode.

If i = 1, the socket is set as blocking, if i = 0 the socket is set as nonblocking and return true on success or false on failure. If i is default value of -1, this function returns true if the socket is set as blocking or false if set as nonblocking.

Definition at line 3943 of file axcel.cpp.

bool axcel::net::socket::tcp::close ( )

Shutdown and close socket.

Returns:
true success, false failure

Definition at line 3921 of file axcel.cpp.

bool axcel::net::socket::tcp::connect ( const char *  host,
const char *  port 
)

Connect to host.

Parameters:
hostHostname or IP address in string format
portPort number or service name
Returns:
true success, false failure

Definition at line 3763 of file axcel.cpp.

bool axcel::net::socket::tcp::connected ( )

Check for connected socket.

Returns:
true if socket is connected, false if not

Definition at line 4001 of file axcel.cpp.

data axcel::net::socket::tcp::dump ( ) [virtual]

Read until EOF.

Returns:
data object containing every byte read from this stream until an error or end-of-file was detected. This method may or may not block depending on the deriving object implementing this class.

Reimplemented from axcel::io::input.

Definition at line 6789 of file axcel.cpp.

int axcel::net::socket::tcp::getc ( ) [virtual]

Read byte.

Returns:
Character read as an unsigned char cast to an int or EOF on end of file or error

Reads the next character from stream and returns it as an unsigned char cast to an int, or EOF on end of file or error. Before returning from the method, one of the following methods of the stream must be called:

  • If end of file is reached, the method must call drain()
  • If a small error occurs but the stream is still usable, the method must call hurt()
  • If a fatal error occurs and the stream is unusable, the method must call kill()
  • If successful, the method must call heal()

Implements axcel::io::input.

Definition at line 3658 of file axcel.cpp.

string axcel::net::socket::tcp::ip ( )

Get peer ip address.

Returns:
IP address of connected peer represented as a string

Definition at line 4006 of file axcel.cpp.

bool axcel::net::socket::tcp::listen ( const char *  port,
int  backlog 
)

Bind and Listen on port.

Parameters:
portPort number or service name
backlogMaximum pending connections queue
Returns:
true success, false failure

Definition at line 3813 of file axcel.cpp.

string axcel::net::socket::tcp::name ( )

Get peer name.

Returns:
Name of connected peer

Definition at line 4034 of file axcel.cpp.

axcel::net::socket::tcp::operator string ( ) [virtual]

Convert to string.

Returns:
Suitable string representation of object's data

Reimplemented from axcel::io::ios.

Definition at line 284 of file axcel.cpp.

int axcel::net::socket::tcp::putc ( int  c) [virtual]

Write byte.

Parameters:
cCharacter to write
Returns:
Character written or EOF on end of file or error

Writes character c to stream and returns a non-negative number on success or EOF on error. Before returning from within this method, one of the following methods must be called:

  • If end of file is reached, the method must call drain()
  • If an error occurs, the method must call kill()
  • If successful, the method must call heal()

Implements axcel::io::output.

Definition at line 3649 of file axcel.cpp.

int axcel::net::socket::tcp::puts ( const char *  s) [virtual]

Send data.

Parameters:
bufBuffer
lenLength of buffer
Returns:
Number of bytes sent or -1 on error

Sends len bytes of data from buffer.

Receive data

Parameters:
bufBuffer Length of buffer
Returns:
Number of bytes received or -1 on error

Reads at most len bytes of packet data to buffer

Reimplemented from axcel::io::output.

Definition at line 4452 of file axcel.cpp.

bool axcel::net::socket::tcp::ready ( )

Definition at line 4478 of file axcel.cpp.

int axcel::net::socket::tcp::recv ( char *  buf,
size_t  len 
)

Recieve data.

Parameters:
bufBuffer to read into
lenLength of buffer
Returns:
Number of bytes received, or -1 on error, or 0 when peer has performed an orderly shutdown

Receives data from the associated socket. If no messages are available, this method blocks until data arrive, unless it is set to nonblocking (see blocking()), in which case the value -1 is returned. This method normally returns any data available, up to the requested amount, rather than waiting for receipt of the full amount requested.

Definition at line 3751 of file axcel.cpp.

int axcel::net::socket::tcp::send ( const char *  buf,
size_t  len 
)

Send data.

Parameters:
bufBuffer to send
lenLength of buffer
Returns:
Number of bytes sent or -1 on error.

Definition at line 3735 of file axcel.cpp.

string axcel::net::socket::tcp::type ( ) [virtual]

Get type of object.

Returns:
string containing name of object's class.

Reimplemented from axcel::io::ios.

Definition at line 258 of file axcel.cpp.


Member Data Documentation

Definition at line 935 of file axcel.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Defines