Logo Search packages:      
Sourcecode: libsocket version File versions  Download package

Network::NetSocket Class Reference

#include <netsocket.hh>

Inheritance diagram for Network::NetSocket:

Network::Socket Network::TcpSocket Network::UdpSocket

List of all members.


Detailed Description

This class represent an abstract socket connection (udp | tcp server | tcp client).

Author:
Julien Lemoine <speedblue at="" happycoders="" dot="" org>="">

Definition at line 33 of file netsocket.hh.


Public Member Functions

void add_delim (const std::string &delim)
 set the delimitor for the text mode
void allow_empty_lines ()
 , if set, empty lines will be returned in text procols (if not, they are skipped)
bool connected () const
 return true when socket is connected
void del_delim (const std::string &delim)
 delete this delimitor for the socket
void enable_tls ()
 Enable TLS on socket.
int get_socket ()
 get socket (fd) warning: be very carefull with this method
void init_tls (GnuTLSKind kind, unsigned size=1024, const std::string &certfile="", const std::string &keyfile="", const std::string &trustfile="", const std::string &crlfile="")
 
Exceptions:
TLSSupportError when TLS is not enabled

 NetSocket (SOCKET_KIND kind, PROTO_KIND pkind, SOCKET_VERSION version=V4)
 NetSocket (SOCKET_KIND kind, SOCKET_VERSION version=V4)
std::string read (int &port, std::string &host, int timeout)
 Get a line from socket and store client hostname and port in port and host variable (with a timeout on listen).
std::string read (int &port, std::string &host)
 Get a line from socket and store client hostname and port in port and host variable.
std::string read (int timeout)
 read a string with a timeout
std::string read ()
 function used by >> operator (read a string on current socket)
std::string readn (int &port, std::string &host, int timeout, unsigned int size)
 Get a line from socket and store client hostname and port in port and host variable (with a timeout on listen).
std::string readn (int &port, std::string &host, unsigned int size)
 Get a line from socket and store client hostname and port in port and host variable.
std::string readn (int timeout, unsigned int size)
 read a string with a timeout
std::string readn (unsigned int size)
 read a string from socket
void write (const std::string &str)
 function used by << operator (write a string on current socket)
virtual void writeto (const std::string &str, const std::string &host, int port)
 function used to send a msg to a specific host (UDP)

Protected Member Functions

int _accept (int port, int server_socket) const
 Wait for a client
Exceptions:
AcceptError when accept libc function return a negative value.

int _bind (int port)
 Bind a TCP server
Exceptions:
SocketError when socket libc function return a negative value
SetsockoptError when setsockopt libc function return a negative value
BindError when bind libc function return a negative value
Exception if the selected protocole is incorrect (is you receive this exception, please submit a bug report).

int _bind (int port, const std::string &host)
 Bind a UDP server
Exceptions:
SocketError when socket libc function return a negative value
Exception if the selected protocole is incorrect (is you receive this exception, please submit a bug report).

void _close (int socket) const
 Close a connnection
Exceptions:
CloseException when close libc function return a negative value.

void _connect (int socket, int port, const std::string &host) const
 Connect to a hostname
Exceptions:
ConnectError when connect libc function return a negative value.

std::pair< int, int > _find_delim (const std::string &str, int start) const
struct sockaddr_in _get_addr (const std::string &host, int port) const
 internal function (construct a sockaddr)
Exceptions:
HostnameError when host is incorrect

struct sockaddr_in _get_addr (int port) const
 internal function (construct a sockaddr)
std::string _get_ip (int port, int socket) const
 Get Client Ip.
void _listen (int socket) const
 Listen on port
Exceptions:
ListenException when listen libc function return a negative value.

std::string _read_line (int socket, int &port, std::string &host)
 Get a line from socket and store client hostname and port in port and host variable (when used with textual protocol)
Exceptions:
NoConnection when there is no open socket
ConnectionClosed when there is no more connection
GetpeernameError when getpeername libc function return a negative value.

std::string _read_line (int socket)
 Get a line from socket (when used with textual protocol)
Exceptions:
NoConnection when there is no open socket
ConnectionClosed when there is no more connection.

virtual std::string _read_line_bin (int socket, unsigned int size)=0
 Get a line from socket (when used with binary protocol)
Exceptions:
NoConnection when there is no open socket
ConnectionClosed when there is no more connection.

virtual std::string _read_line_bin (int socket, int &port, std::string &host, unsigned int pkg_size)=0
 Get a line from socket and store client hostname and port in port and host variable (when used with binary protocol)
Exceptions:
NoConnection when there is no open socket
ConnectionClosed when there is no more connection
GetpeernameError when getpeername libc function return a negative value.

void _set_timeout (bool enable, int socket, int timeout)
 set a timeout on a socket
bool _update_buffer (std::pair< int, int > &delim, int &i, std::string &str)
 look delimiter and remove delimiter at begining of buffer if needed
void _write_str (int socket, const std::string &str) const
 Write a string to a socket (when used with textual protocol)
Exceptions:
NoConnection when there is no open socket
ConnectionClosed when there is no more connection.

void _write_str (int socket, const std::string &str, const std::string &host, int port) const
 Write a string to a socket to a particular host (UDP) (when used with textual protocol)
Exceptions:
NoConnection when there is no open socket
ConnectionClosed when there is no more connection.

void _write_str_bin (int socket, const std::string &str) const
 Write a string to a socket (when used with binary protocol)
Exceptions:
NoConnection when there is no open socket
ConnectionClosed when there is no more connection.

void _write_str_bin (int socket, const std::string &str, const std::string &host, int port) const
 Write a string to a socket to a particular host (UDP) (when used with binary protocol)
Exceptions:
NoConnection when there is no open socket
ConnectionClosed when there is no more connection.

bool Socket::_check_answer (int res, std::string &str)
 return the content of the buffer is there is

Protected Attributes

struct sockaddr_in _addr
std::string _buffer
std::list< std::string > _delim
bool _empty_lines
SOCKET_KIND _kind
int _port
PROTO_KIND _proto_kind
int _recv_flags
int _socket
unsigned _state_timeout
bool _tls
SOCKET_VERSION _version

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

Generated by  Doxygen 1.6.0   Back to index