31#if defined(_MSC_VER) || defined(__MINGW32__) || defined(__CYGWIN__)
38# include <sys/types.h>
43# define SENDTO_FLAGS 0
45# if defined(__APPLE__) && defined(__MACH__)
46# define SENDTO_FLAGS 0
48# define SENDTO_FLAGS MSG_NOSIGNAL
50# include <sys/socket.h>
51# include <netinet/in.h>
52# include <arpa/inet.h>
58# include <gnutls/gnutls.h>
93 static const int MAXPKTSIZE = 65507;
95 static const char DEFAULT_DELIM =
'\0';
110 void write(
const std::string& str);
119 void add_delim(
const std::string& delim);
121 void del_delim(
const std::string& delim);
129 unsigned size = 1024,
130 const std::string &certfile =
"",
131 const std::string &keyfile =
"",
132 const std::string &trustfile =
"",
133 const std::string &crlfile =
"");
140 virtual std::string
read() = 0;
142 virtual std::string
read(
int timeout) = 0;
145 virtual std::string
readn(
unsigned int size) = 0;
148 virtual std::string
readn(
int timeout,
unsigned int size) = 0;
154 void _close(
int socket)
const;
158 void _listen(
int socket)
const;
170 void _write_str(
int socket,
const std::string& str)
const;
180 void _set_timeout(
bool enable,
int socket,
int timeout);
182 std::pair<int, int>
_find_delim(
const std::string& str,
int start)
const;
185 bool _update_buffer(std::pair<int, int> &delim,
int &i, std::string &str);
197 struct sockaddr_in6 _addr6;
205 gnutls_session _session;
206 gnutls_certificate_credentials _x509_cred;
This class represent an abstract socket connection (udp | tcp server | tcp client)
std::pair< int, int > _find_delim(const std::string &str, int start) const
int get_socket()
get socket (fd) warning: be very carefull with this method
virtual std::string _read_line_bin(int socket, unsigned int size)=0
Get a line from socket (when used with binary protocol)
void write(const std::string &str)
function used by << operator (write a string on current socket)
void _write_str_bin(int socket, const std::string &str) const
Write a string to a socket (when used with binary protocol)
virtual std::string readn(unsigned int size)=0
read a string from socket
void _set_timeout(bool enable, int socket, int timeout)
set a timeout on a socket
void add_delim(const std::string &delim)
set the delimitor for the text mode
virtual std::string _read_line(int socket)=0
Get a line from socket (when used with textual protocol)
virtual std::string readn(int timeout, unsigned int size)=0
read a string with a timeout
void del_delim(const std::string &delim)
delete this delimitor for the socket
bool _check_answer(int res, std::string &str)
return the content of the buffer is there is
void enable_tls()
Enable TLS on 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 _listen(int socket) const
Listen on port.
bool connected() const
return true when socket is connected
virtual std::string read(int timeout)=0
read a string with a timeout
void _close(int socket) const
Close a connnection.
void allow_empty_lines()
, if set, empty lines will be returned in text procols (if not, they are skipped)
std::list< std::string > _delim
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 _write_str(int socket, const std::string &str) const
Write a string to a socket (when used with textual protocol)
virtual std::string read()=0
function used by >> operator (read a string on current socket)
Network namespace represent all networks connection.
Socket & operator>>(Socket &s, std::string &str)
read a string on current socket
Socket & operator<<(Socket &s, const std::string &str)
write a string on current socket
enum Network::e_version SOCKET_VERSION
enum Network::e_kind SOCKET_KIND
enum Network::e_gnutls_kind GnuTLSKind
enum Network::e_pkind PROTO_KIND