#include <netsocket.hh>
Inheritance diagram for Network::NetSocket:

Public Member Functions | |||||||||||||
| NetSocket (SOCKET_KIND kind, SOCKET_VERSION version=V4) | |||||||||||||
| NetSocket (SOCKET_KIND kind, PROTO_KIND pkind, SOCKET_VERSION version=V4) | |||||||||||||
| virtual | ~NetSocket () | ||||||||||||
| virtual void | writeto (const std::string &str, const std::string &host, int port) | ||||||||||||
| function used to send a msg to a specific host (UDP) | |||||||||||||
| std::string | read () | ||||||||||||
| function used by >> operator (read a string on current socket) | |||||||||||||
| std::string | read (int timeout) | ||||||||||||
| read a string with a timeout | |||||||||||||
| 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 &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 | readn (unsigned int size) | ||||||||||||
| read a string from socket | |||||||||||||
| std::string | readn (int timeout, unsigned int size) | ||||||||||||
| read a string with a timeout | |||||||||||||
| 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 &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). | |||||||||||||
Protected Member Functions | |||||||||||||
| sockaddr_in | _get_addr (int port) const | ||||||||||||
| internal function (construct a sockaddr) | |||||||||||||
| sockaddr_in | _get_addr (const std::string &host, int port) const | ||||||||||||
internal function (construct a sockaddr)
| |||||||||||||
| int | _bind (int port, const std::string &host) | ||||||||||||
Bind a UDP server
| |||||||||||||
| int | _bind (int port) | ||||||||||||
Bind a TCP server
| |||||||||||||
| int | _accept (int port, int server_socket) const | ||||||||||||
Wait for a client
| |||||||||||||
| std::string | _get_ip (int port, int socket) const | ||||||||||||
| Get Client Ip. | |||||||||||||
| void | _connect (int socket, int port, const std::string &host) const | ||||||||||||
Connect to a hostname
| |||||||||||||
| std::string | _read_line (int socket) | ||||||||||||
Get a line from socket (when used with textual protocol)
| |||||||||||||
| 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)
| |||||||||||||
| 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)
| |||||||||||||
| 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 std::string &host, int port) const | ||||||||||||
Write a string to a socket to a particular host (UDP) (when used with textual protocol)
| |||||||||||||
| 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)
| |||||||||||||
Protected Attributes | |||||||||||||
| int | _port | ||||||||||||
Definition at line 33 of file netsocket.hh.
| Network::NetSocket::NetSocket | ( | SOCKET_KIND | kind, | |
| SOCKET_VERSION | version = V4 | |||
| ) | [inline] |
Definition at line 36 of file netsocket.hh.
| Network::NetSocket::NetSocket | ( | SOCKET_KIND | kind, | |
| PROTO_KIND | pkind, | |||
| SOCKET_VERSION | version = V4 | |||
| ) | [inline] |
Definition at line 40 of file netsocket.hh.
| virtual Network::NetSocket::~NetSocket | ( | ) | [inline, virtual] |
Definition at line 45 of file netsocket.hh.
| int Network::NetSocket::_accept | ( | int | port, | |
| int | server_socket | |||
| ) | const [protected] |
Wait for a client
| AcceptError | when accept libc function return a negative value. |
Definition at line 211 of file netsocket.cc.
References _get_addr(), Network::Socket::_version, HERE, and Network::V4.
Referenced by Network::TcpSocket::accept().
| int Network::NetSocket::_bind | ( | int | port | ) | [protected] |
Bind a TCP server
| 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). |
Definition at line 128 of file netsocket.cc.
References _get_addr(), Network::Socket::_kind, Network::Socket::_version, HERE, Network::TCP, Network::UDP, and Network::V4.
| int Network::NetSocket::_bind | ( | int | port, | |
| const std::string & | host | |||
| ) | [protected] |
Bind a UDP server
| 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). |
Definition at line 86 of file netsocket.cc.
References Network::Socket::_addr, _get_addr(), Network::Socket::_kind, Network::Socket::_version, HERE, Network::TCP, Network::UDP, and Network::V4.
Referenced by Network::UdpSocket::connect(), and Network::TcpSocket::connect().
| void Network::NetSocket::_connect | ( | int | socket, | |
| int | port, | |||
| const std::string & | host | |||
| ) | const [protected] |
Connect to a hostname
| ConnectError | when connect libc function return a negative value. |
Definition at line 186 of file netsocket.cc.
References _get_addr(), Network::Socket::_version, HERE, and Network::V4.
Referenced by Network::TcpSocket::connect().
| struct sockaddr_in Network::NetSocket::_get_addr | ( | const std::string & | host, | |
| int | port | |||
| ) | const [protected] |
internal function (construct a sockaddr)
| HostnameError | when host is incorrect |
Definition at line 30 of file netsocket.cc.
References HERE.
| struct sockaddr_in Network::NetSocket::_get_addr | ( | int | port | ) | const [protected] |
internal function (construct a sockaddr)
Definition at line 61 of file netsocket.cc.
Referenced by _accept(), _bind(), _connect(), _write_str(), and _write_str_bin().
| std::string Network::NetSocket::_get_ip | ( | int | port, | |
| int | socket | |||
| ) | const [protected] |
Get Client Ip.
Definition at line 243 of file netsocket.cc.
Referenced by Network::TcpSocket::get_ip().
| std::string Network::NetSocket::_read_line | ( | int | socket, | |
| int & | port, | |||
| std::string & | host | |||
| ) | [protected] |
Get a line from socket and store client hostname and port in port and host variable (when used with textual protocol)
| NoConnection | when there is no open socket | |
| ConnectionClosed | when there is no more connection | |
| GetpeernameError | when getpeername libc function return a negative value. |
Definition at line 300 of file netsocket.cc.
References Network::Socket::_buffer, Network::Socket::_check_answer(), Network::Socket::_kind, Network::Socket::_set_timeout(), Network::Socket::_socket, Network::Socket::_state_timeout, Network::Socket::_tls, Network::Socket::_update_buffer(), Network::Socket::_version, HERE, Network::UDP, and Network::V4.
| std::string Network::NetSocket::_read_line | ( | int | socket | ) | [protected, 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. |
Implements Network::Socket.
Definition at line 261 of file netsocket.cc.
References Network::Socket::_buffer, Network::Socket::_check_answer(), Network::Socket::_kind, Network::Socket::_set_timeout(), Network::Socket::_socket, Network::Socket::_state_timeout, Network::Socket::_tls, Network::Socket::_update_buffer(), HERE, and Network::UDP.
Referenced by read().
| virtual std::string Network::NetSocket::_read_line_bin | ( | int | socket, | |
| unsigned int | size | |||
| ) | [protected, pure 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. |
Implements Network::Socket.
Implemented in Network::TcpSocket, and Network::UdpSocket.
| virtual std::string Network::NetSocket::_read_line_bin | ( | int | socket, | |
| int & | port, | |||
| std::string & | host, | |||
| unsigned int | pkg_size | |||
| ) | [protected, pure virtual] |
Get a line from socket and store client hostname and port in port and host variable (when used with binary protocol)
| NoConnection | when there is no open socket | |
| ConnectionClosed | when there is no more connection | |
| GetpeernameError | when getpeername libc function return a negative value. |
Implemented in Network::TcpSocket, and Network::UdpSocket.
| void Network::NetSocket::_write_str | ( | int | socket, | |
| const std::string & | str, | |||
| const std::string & | host, | |||
| int | port | |||
| ) | const [protected] |
Write a string to a socket to a particular host (UDP) (when used with textual protocol)
| NoConnection | when there is no open socket | |
| ConnectionClosed | when there is no more connection. |
Definition at line 400 of file netsocket.cc.
References Network::Socket::_addr, _get_addr(), Network::Socket::_tls, Network::Socket::_version, HERE, SENDTO_FLAGS, and Network::V4.
Referenced by writeto().
| void Network::NetSocket::_write_str_bin | ( | int | socket, | |
| const std::string & | str, | |||
| const std::string & | host, | |||
| int | port | |||
| ) | const [protected] |
Write a string to a socket to a particular host (UDP) (when used with binary protocol)
| NoConnection | when there is no open socket | |
| ConnectionClosed | when there is no more connection. |
Definition at line 446 of file netsocket.cc.
References Network::Socket::_addr, _get_addr(), Network::Socket::_tls, Network::Socket::_version, HERE, SENDTO_FLAGS, and Network::V4.
Referenced by writeto().
| std::string Network::NetSocket::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).
Definition at line 519 of file netsocket.cc.
References Network::Socket::_proto_kind, _read_line(), _read_line_bin(), Network::Socket::_set_timeout(), Network::Socket::_socket, Network::Socket::_state_timeout, and Network::binary.
| std::string Network::NetSocket::read | ( | int & | port, | |
| std::string & | host | |||
| ) |
Get a line from socket and store client hostname and port in port and host variable.
Definition at line 511 of file netsocket.cc.
References Network::Socket::_proto_kind, _read_line(), _read_line_bin(), Network::Socket::_socket, and Network::binary.
| std::string Network::NetSocket::read | ( | int | timeout | ) | [virtual] |
read a string with a timeout
Implements Network::Socket.
Definition at line 541 of file netsocket.cc.
References Network::Socket::_proto_kind, _read_line(), _read_line_bin(), Network::Socket::_set_timeout(), Network::Socket::_socket, Network::Socket::_state_timeout, and Network::binary.
| std::string Network::NetSocket::read | ( | ) | [virtual] |
function used by >> operator (read a string on current socket)
Implements Network::Socket.
Definition at line 533 of file netsocket.cc.
References Network::Socket::_proto_kind, _read_line(), _read_line_bin(), Network::Socket::_socket, and Network::binary.
Referenced by Network::TcpSocket::_read_line_bin().
| std::string Network::NetSocket::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).
| size | represente the number of byte to read |
Definition at line 564 of file netsocket.cc.
References Network::Socket::_buffer, _read_line_bin(), Network::Socket::_set_timeout(), and Network::Socket::_socket.
| std::string Network::NetSocket::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.
| size | represente the number of byte to read |
Definition at line 555 of file netsocket.cc.
References _read_line_bin(), and Network::Socket::_socket.
| std::string Network::NetSocket::readn | ( | int | timeout, | |
| unsigned int | size | |||
| ) | [virtual] |
read a string with a timeout
| size | represente the number of byte to read |
Implements Network::Socket.
Definition at line 583 of file netsocket.cc.
References Network::Socket::_buffer, _read_line_bin(), Network::Socket::_set_timeout(), and Network::Socket::_socket.
| std::string Network::NetSocket::readn | ( | unsigned int | size | ) | [virtual] |
read a string from socket
| size | represente the number of byte to read |
Implements Network::Socket.
Definition at line 575 of file netsocket.cc.
References _read_line_bin(), and Network::Socket::_socket.
| void Network::NetSocket::writeto | ( | const std::string & | str, | |
| const std::string & | host, | |||
| int | port | |||
| ) | [virtual] |
function used to send a msg to a specific host (UDP)
Definition at line 502 of file netsocket.cc.
References Network::Socket::_proto_kind, Network::Socket::_socket, _write_str(), _write_str_bin(), and Network::binary.
int Network::NetSocket::_port [protected] |
Definition at line 161 of file netsocket.hh.
Referenced by Network::TcpSocket::accept(), Network::UdpSocket::connect(), Network::TcpSocket::connect(), and Network::TcpSocket::get_ip().
1.4.7