AXCEL C++ Framework
Elegance through abstraction
|
Transmission Control Protocol socket. More...
#include <axcel.h>
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 |
bool axcel::net::socket::tcp::accept | ( | tcp & | f | ) |
Accept connection.
f | Reference to net::socket::tcp object |
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.
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.
bool axcel::net::socket::tcp::close | ( | ) |
bool axcel::net::socket::tcp::connect | ( | const char * | host, |
const char * | port | ||
) |
bool axcel::net::socket::tcp::connected | ( | ) |
data axcel::net::socket::tcp::dump | ( | ) | [virtual] |
Read until EOF.
Reimplemented from axcel::io::input.
int axcel::net::socket::tcp::getc | ( | ) | [virtual] |
Read byte.
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:
Implements axcel::io::input.
string axcel::net::socket::tcp::ip | ( | ) |
bool axcel::net::socket::tcp::listen | ( | const char * | port, |
int | backlog | ||
) |
string axcel::net::socket::tcp::name | ( | ) |
axcel::net::socket::tcp::operator string | ( | ) | [virtual] |
Convert to string.
Reimplemented from axcel::io::ios.
int axcel::net::socket::tcp::putc | ( | int | c | ) | [virtual] |
Write byte.
c | Character to write |
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:
Implements axcel::io::output.
int axcel::net::socket::tcp::puts | ( | const char * | s | ) | [virtual] |
Send data.
buf | Buffer |
len | Length of buffer |
Sends len bytes of data from buffer.
Receive data
buf | Buffer Length of buffer |
Reads at most len bytes of packet data to buffer
Reimplemented from axcel::io::output.
int axcel::net::socket::tcp::recv | ( | char * | buf, |
size_t | len | ||
) |
Recieve data.
buf | Buffer to read into |
len | Length of buffer |
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.
int axcel::net::socket::tcp::send | ( | const char * | buf, |
size_t | len | ||
) |
string axcel::net::socket::tcp::type | ( | ) | [virtual] |
Get type of object.
Reimplemented from axcel::io::ios.