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

Network::LocalSocket Class Reference

#include <localsocket.hh>

Inheritance diagram for Network::LocalSocket:

Network::Socket

List of all members.


Detailed Description

This class represent a local connection (client and server).

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

Definition at line 34 of file localsocket.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)
void close ()
 connect to a local socket (client)
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 (const std::string &filename)
 Initialize a local socket (server).
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

 LocalSocket (PROTO_KIND pkind)
std::string read (std::string &filename, int timeout)
 read a string and put the client named socket name in filename with a timeout
std::string read (std::string &filename)
 read a string and put the client named socket name in filename
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 (std::string &filename, int timeout, unsigned int size)
 read a string and put the client named socket name in filename with a timeout
std::string readn (std::string &filename, unsigned int size)
 read a string and put the client named socket name in filename
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)
void writeto (const std::string &str, const std::string &filename)
 function used to send a msg to a specific named socket

Protected Member Functions

int _bind (const std::string &filename)
 Initialize a local socket connection (server in UDP) create a named socket with name filename
Exceptions:
NoConnection when there is no open socket
BindError when bind libc function return a negative value.

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

std::pair< int, int > _find_delim (const std::string &str, int start) const
void _listen (int socket) const
 Listen on port
Exceptions:
ListenException when listen libc function return a negative value.

std::string _read_line (int socket, std::string &filename)
 Get a line from socket and give client socket filename (for named socket) (when used with textual protocol)
Exceptions:
NoConnection when there is no open socket
ConnectionClosed when there is no more connection.

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.

std::string _read_line_bin (int socket, std::string &filename, unsigned int pkg_size)
 Get a line from socket and give client socket filename (for named socket) (when used with binary protocol)
Exceptions:
NoConnection when there is no open socket
ConnectionClosed when there is no more connection.

std::string _read_line_bin (int socket, unsigned int size)
 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.

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 &filename) const
 Write a string to a socket to a particular named socket (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 &filename) const
 Write a string to a socket to a particular named socket (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
std::string _filename
SOCKET_KIND _kind
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