00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef NETSOCKET_HH_
00024 # define NETSOCKET_HH_
00025
00026 #include "socket.hh"
00027
00028 namespace Network
00029 {
00033 class NetSocket : public Socket
00034 {
00035 public:
00036 NetSocket(SOCKET_KIND kind, SOCKET_VERSION version = V4) :
00037 Socket(kind, version), _port(0)
00038 {
00039 }
00040 NetSocket(SOCKET_KIND kind, PROTO_KIND pkind, SOCKET_VERSION version = V4) :
00041 Socket(kind, pkind, version), _port(0)
00042 {
00043 }
00044
00045 virtual ~NetSocket() {}
00046
00047 public:
00049 virtual void writeto(const std::string& str,
00050 const std::string& host, int port);
00051
00054 std::string read();
00056 std::string read(int timeout);
00059 std::string read(int& port, std::string& host);
00062 std::string read(int& port, std::string& host, int timeout);
00065 std::string readn(unsigned int size);
00068 std::string readn(int timeout, unsigned int size);
00072 std::string readn(int& port, std::string& host, unsigned int size);
00076 std::string readn(int& port, std::string& host, int timeout,
00077 unsigned int size);
00078
00079 protected:
00081 struct sockaddr_in _get_addr(int port) const;
00082 #ifdef IPV6_ENABLED
00083 struct sockaddr_in6 _get_addr6(int port) const;
00084 #endif
00085
00088 struct sockaddr_in _get_addr(const std::string& host,
00089 int port) const;
00090 #ifdef IPV6_ENABLED
00091 struct sockaddr_in6 _get_addr6(const std::string& host,
00092 int port) const;
00093 #endif
00099 int _bind(int port, const std::string& host);
00109 int _bind(int port);
00113 int _accept(int port, int server_socket) const;
00115 std::string _get_ip(int port, int socket) const;
00119 void _connect(int socket, int port,
00120 const std::string& host) const;
00124 std::string _read_line(int socket);
00131 std::string _read_line(int socket, int& port,
00132 std::string& host);
00139 virtual std::string _read_line_bin(int socket, int& port,
00140 std::string& host,
00141 unsigned int pkg_size) = 0;
00145 virtual std::string _read_line_bin(int socket, unsigned int size) = 0;
00146
00151 void _write_str(int socket, const std::string& str,
00152 const std::string& host, int port) const;
00157 void _write_str_bin(int socket, const std::string& str,
00158 const std::string& host, int port) const;
00159
00160 protected:
00161 int _port;
00162 };
00163 }
00164
00165
00166 #endif