|
libsocket 1.5
|
This class represent an abstract socket connection (udp | tcp server | tcp client) More...
#include <socket.hh>
Public Member Functions | |
| Socket (SOCKET_KIND kind, SOCKET_VERSION version=V4) | |
| Socket (SOCKET_KIND kind, PROTO_KIND pkind, SOCKET_VERSION version=V4) | |
| virtual | ~Socket () |
| void | write (const std::string &str) |
| function used by << operator (write a string on current socket) | |
| bool | connected () const |
| return true when socket is connected | |
| int | get_socket () |
| get socket (fd) warning: be very carefull with this method | |
| void | add_delim (const std::string &delim) |
| set the delimitor for the text mode | |
| void | del_delim (const std::string &delim) |
| delete this delimitor for the socket | |
| void | allow_empty_lines () |
| , if set, empty lines will be returned in text procols (if not, they are skipped) | |
| void | init_tls (GnuTLSKind kind, unsigned size=1024, const std::string &certfile="", const std::string &keyfile="", const std::string &trustfile="", const std::string &crlfile="") |
| void | enable_tls () |
| Enable TLS on socket. | |
| virtual std::string | read ()=0 |
| function used by >> operator (read a string on current socket) | |
| virtual std::string | read (int timeout)=0 |
| read a string with a timeout | |
| virtual std::string | readn (unsigned int size)=0 |
| read a string from socket | |
| virtual std::string | readn (int timeout, unsigned int size)=0 |
| read a string with a timeout | |
Protected Member Functions | |
| void | _close (int socket) const |
| Close a connnection. | |
| void | _listen (int socket) const |
| Listen on port. | |
| virtual std::string | _read_line (int socket)=0 |
| Get a line from socket (when used with textual protocol) | |
| virtual std::string | _read_line_bin (int socket, unsigned int size)=0 |
| Get a line from socket (when used with binary protocol) | |
| void | _write_str (int socket, const std::string &str) const |
| Write a string to a socket (when used with textual protocol) | |
| void | _write_str_bin (int socket, const std::string &str) const |
| Write a string to a socket (when used with binary protocol) | |
| void | _set_timeout (bool enable, int socket, int timeout) |
| set a timeout on a socket | |
| std::pair< int, int > | _find_delim (const std::string &str, int start) const |
| bool | _update_buffer (std::pair< int, int > &delim, int &i, std::string &str) |
| look delimiter and remove delimiter at begining of buffer if needed | |
| bool | _check_answer (int res, std::string &str) |
| return the content of the buffer is there is | |
Protected Attributes | |
| SOCKET_KIND | _kind |
| SOCKET_VERSION | _version |
| unsigned | _state_timeout |
| int | _socket |
| int | _recv_flags |
| struct sockaddr_in | _addr |
| PROTO_KIND | _proto_kind |
| std::list< std::string > | _delim |
| bool | _empty_lines |
| std::string | _buffer |
| bool | _tls |
This class represent an abstract socket connection (udp | tcp server | tcp client)
| Network::Socket::Socket | ( | SOCKET_KIND | kind, |
| SOCKET_VERSION | version = V4 |
||
| ) |
Definition at line 31 of file socket.cc.
References _delim, HERE, and Network::V6.
| Network::Socket::Socket | ( | SOCKET_KIND | kind, |
| PROTO_KIND | pkind, | ||
| SOCKET_VERSION | version = V4 |
||
| ) |
Definition at line 48 of file socket.cc.
References _delim, HERE, and Network::V6.
|
inlineprotected |
return the content of the buffer is there is
Definition at line 28 of file socket.hxx.
References _buffer, _state_timeout, and HERE.
Referenced by Network::NetSocket::_read_line(), and Network::NetSocket::_read_line().
|
protected |
Close a connnection.
| CloseException | when close libc function return a negative value |
Definition at line 167 of file socket.cc.
Referenced by Network::LocalSocket::close(), Network::TcpSocket::close(), and Network::UdpSocket::close().
|
protected |
Definition at line 339 of file socket.cc.
References _delim.
Referenced by _update_buffer().
|
protected |
Listen on port.
| ListenException | when listen libc function return a negative value |
Definition at line 192 of file socket.cc.
References HERE.
Referenced by Network::TcpSocket::connect().
|
protectedpure virtual |
Get a line from socket (when used with textual protocol)
| NoConnection | when there is no open socket |
| ConnectionClosed | when there is no more connection |
Implemented in Network::LocalSocket, and Network::NetSocket.
|
protectedpure virtual |
Get a line from socket (when used with binary protocol)
| NoConnection | when there is no open socket |
| ConnectionClosed | when there is no more connection |
Implemented in Network::TcpSocket, Network::LocalSocket, Network::UdpSocket, and Network::NetSocket.
|
protected |
set a timeout on a socket
| timeout | is in second |
| Timeout | when there is a timeout |
| SelectError | when select libc function return a negative value |
Definition at line 272 of file socket.cc.
References HERE.
Referenced by Network::NetSocket::_read_line(), Network::NetSocket::_read_line(), Network::NetSocket::read(), Network::LocalSocket::read(), Network::NetSocket::read(), Network::LocalSocket::read(), Network::NetSocket::readn(), Network::LocalSocket::readn(), Network::NetSocket::readn(), and Network::LocalSocket::readn().
|
inlineprotected |
look delimiter and remove delimiter at begining of buffer if needed
Definition at line 45 of file socket.hxx.
References _buffer, _empty_lines, and _find_delim().
Referenced by Network::LocalSocket::_read_line(), Network::NetSocket::_read_line(), Network::NetSocket::_read_line(), and Network::LocalSocket::_read_line().
|
protected |
Write a string to a socket (when used with textual protocol)
| NoConnection | when there is no open socket |
| ConnectionClosed | when there is no more connection |
Definition at line 198 of file socket.cc.
References _addr, _tls, _version, HERE, SENDTO_FLAGS, and Network::V4.
Referenced by write().
|
protected |
Write a string to a socket (when used with binary protocol)
| NoConnection | when there is no open socket |
| ConnectionClosed | when there is no more connection |
Definition at line 230 of file socket.cc.
References _addr, _tls, _version, HERE, SENDTO_FLAGS, and Network::V4.
Referenced by write().
| void Network::Socket::add_delim | ( | const std::string & | delim | ) |
| void Network::Socket::allow_empty_lines | ( | ) |
, if set, empty lines will be returned in text procols (if not, they are skipped)
Definition at line 308 of file socket.cc.
References _empty_lines.
| bool Network::Socket::connected | ( | ) | const |
return true when socket is connected
Definition at line 303 of file socket.cc.
References _socket.
Referenced by enable_tls().
| void Network::Socket::del_delim | ( | const std::string & | delim | ) |
| void Network::Socket::enable_tls | ( | ) |
Enable TLS on socket.
Definition at line 69 of file socket.cc.
References _kind, _socket, connected(), HERE, and Network::TCP.
Referenced by Network::TcpSocket::accept().
| int Network::Socket::get_socket | ( | ) |
| void Network::Socket::init_tls | ( | GnuTLSKind | kind, |
| unsigned | size = 1024, |
||
| const std::string & | certfile = "", |
||
| const std::string & | keyfile = "", |
||
| const std::string & | trustfile = "", |
||
| const std::string & | crlfile = "" |
||
| ) |
| TLSSupportError | when TLS is not enabled |
Definition at line 92 of file socket.cc.
|
pure virtual |
function used by >> operator (read a string on current socket)
Implemented in Network::LocalSocket, and Network::NetSocket.
Referenced by Network::operator>>().
|
pure virtual |
read a string with a timeout
Implemented in Network::LocalSocket, and Network::NetSocket.
|
pure virtual |
read a string with a timeout
| size | represente the number of byte to read |
Implemented in Network::LocalSocket, and Network::NetSocket.
|
pure virtual |
read a string from socket
| size | represente the number of byte to read |
Implemented in Network::LocalSocket, and Network::NetSocket.
| void Network::Socket::write | ( | const std::string & | str | ) |
function used by << operator (write a string on current socket)
Definition at line 295 of file socket.cc.
References _proto_kind, _socket, _write_str(), _write_str_bin(), and Network::binary.
Referenced by Network::operator<<().
|
protected |
Definition at line 195 of file socket.hh.
Referenced by Network::NetSocket::_bind(), _write_str(), Network::NetSocket::_write_str(), _write_str_bin(), and Network::NetSocket::_write_str_bin().
|
protected |
Definition at line 202 of file socket.hh.
Referenced by _check_answer(), Network::LocalSocket::_read_line(), Network::NetSocket::_read_line(), Network::NetSocket::_read_line(), Network::LocalSocket::_read_line(), Network::UdpSocket::_read_line_bin(), Network::TcpSocket::_read_line_bin(), Network::LocalSocket::_read_line_bin(), Network::TcpSocket::_read_line_bin(), Network::LocalSocket::_read_line_bin(), Network::UdpSocket::_read_line_bin(), _update_buffer(), Network::NetSocket::readn(), Network::LocalSocket::readn(), Network::NetSocket::readn(), and Network::LocalSocket::readn().
|
protected |
Definition at line 200 of file socket.hh.
Referenced by _find_delim(), add_delim(), del_delim(), Socket(), and Socket().
|
protected |
Definition at line 201 of file socket.hh.
Referenced by _update_buffer(), and allow_empty_lines().
|
protected |
Definition at line 190 of file socket.hh.
Referenced by Network::NetSocket::_bind(), Network::NetSocket::_bind(), Network::NetSocket::_read_line(), Network::NetSocket::_read_line(), and enable_tls().
|
protected |
Definition at line 199 of file socket.hh.
Referenced by Network::TcpSocket::accept(), Network::LocalSocket::read(), Network::NetSocket::read(), Network::NetSocket::read(), Network::NetSocket::read(), Network::LocalSocket::read(), Network::NetSocket::read(), Network::LocalSocket::read(), Network::LocalSocket::read(), write(), Network::LocalSocket::writeto(), and Network::NetSocket::writeto().
|
protected |
Definition at line 193 of file socket.hh.
Referenced by Network::NetSocket::_read_line(), Network::NetSocket::_read_line(), Network::TcpSocket::accept(), Network::LocalSocket::close(), Network::TcpSocket::close(), Network::UdpSocket::close(), Network::TcpSocket::connect(), Network::UdpSocket::connect(), Network::TcpSocket::connect(), Network::UdpSocket::connect(), connected(), enable_tls(), Network::TcpSocket::get_ip(), get_socket(), Network::LocalSocket::init(), Network::LocalSocket::read(), Network::NetSocket::read(), Network::NetSocket::read(), Network::NetSocket::read(), Network::LocalSocket::read(), Network::NetSocket::read(), Network::LocalSocket::read(), Network::LocalSocket::read(), Network::NetSocket::readn(), Network::NetSocket::readn(), Network::LocalSocket::readn(), Network::NetSocket::readn(), Network::LocalSocket::readn(), Network::LocalSocket::readn(), Network::LocalSocket::readn(), Network::NetSocket::readn(), Network::TcpSocket::TcpSocket(), Network::TcpSocket::TcpSocket(), write(), Network::LocalSocket::writeto(), and Network::NetSocket::writeto().
|
protected |
Definition at line 192 of file socket.hh.
Referenced by _check_answer(), Network::LocalSocket::_read_line(), Network::NetSocket::_read_line(), Network::NetSocket::_read_line(), Network::LocalSocket::_read_line(), Network::NetSocket::read(), Network::LocalSocket::read(), Network::NetSocket::read(), and Network::LocalSocket::read().
|
protected |
Definition at line 203 of file socket.hh.
Referenced by _close(), Network::NetSocket::_read_line(), Network::NetSocket::_read_line(), Network::TcpSocket::_read_line_bin(), Network::TcpSocket::_read_line_bin(), _write_str(), Network::NetSocket::_write_str(), _write_str_bin(), Network::NetSocket::_write_str_bin(), Network::TcpSocket::accept(), and init_tls().
|
protected |
Definition at line 191 of file socket.hh.
Referenced by Network::NetSocket::_accept(), Network::NetSocket::_bind(), Network::NetSocket::_bind(), Network::NetSocket::_connect(), Network::NetSocket::_read_line(), Network::UdpSocket::_read_line_bin(), Network::TcpSocket::_read_line_bin(), _write_str(), Network::NetSocket::_write_str(), _write_str_bin(), Network::NetSocket::_write_str_bin(), and Network::TcpSocket::accept().