Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

netsocket.hh

Go to the documentation of this file.
00001 /*
00002 ** netsocket.hh
00003 ** Login : Julien Lemoine <speedblue@happycoders.org>
00004 ** Started on  Mon May 12 22:23:32 2003 Julien Lemoine
00005 ** $Id: netsocket.hh,v 1.2 2004/06/01 21:30:53 speedblue Exp $
00006 **
00007 ** Copyright (C) 2003,2004 Julien Lemoine
00008 ** This program is free software; you can redistribute it and/or modify
00009 ** it under the terms of the GNU Lesser General Public License as published by
00010 ** the Free Software Foundation; either version 2 of the License, or
00011 ** (at your option) any later version.
00012 **
00013 ** This program is distributed in the hope that it will be useful,
00014 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 ** GNU Lesser General Public License for more details.
00017 **
00018 ** You should have received a copy of the GNU Lesser General Public License
00019 ** along with this program; if not, write to the Free Software
00020 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
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      /* !NETSOCKET_HH_ */

Generated on Fri Apr 8 06:13:01 2005 for libsocket by  doxygen 1.4.0