Intra2net AG

socket_client.hxx

Go to the documentation of this file.
00001 /*
00002 Copyright (C) 2006 by Intra2net AG - Gerd v. Egidy
00003 
00004 The software in this package is distributed under the GNU General
00005 Public License version 2 (with a special exception described below).
00006 
00007 A copy of GNU General Public License (GPL) is included in this distribution,
00008 in the file COPYING.GPL.
00009 
00010 As a special exception, if other files instantiate templates or use macros
00011 or inline functions from this file, or you compile this file and link it
00012 with other works to produce a work based on this file, this file
00013 does not by itself cause the resulting work to be covered
00014 by the GNU General Public License.
00015 
00016 However the source code for this file must still be made available
00017 in accordance with section (3) of the GNU General Public License.
00018 
00019 This exception does not invalidate any other reasons why a work based
00020 on this file might be covered by the GNU General Public License.
00021 */
00022 #ifndef __LIBT2N_SOCKET_CLIENT
00023 #define __LIBT2N_SOCKET_CLIENT
00024 
00025 #include "client.hxx"
00026 #include "socket_handler.hxx"
00027 
00028 struct sockaddr;
00029 
00030 namespace libt2n
00031 {
00036 class socket_client_connection : public client_connection, public socket_handler
00037 {
00038     public:
00039         static const int max_retries_default=3;
00040         static const long long connect_timeout_usec_default=30000000;
00041 
00042     private:
00043         void real_write(const std::string& data)
00044             { socket_write(data); }
00045 
00046         void tcp_connect(int max_retries);
00047         void unix_connect(int max_retries);
00048         void connect_with_timeout(struct sockaddr *sock_addr,unsigned int sockaddr_size);
00049 
00050         int max_retries;
00051         long long connect_timeout_usec;
00052 
00053         std::string path;
00054         std::string server;
00055         int port;
00056 
00057         std::string lastErrorMsg;
00058 
00059     protected:
00060 
00061         std::ostream* get_logstream(log_level_values level)
00062             { return client_connection::get_logstream(level); }
00063 
00064     public:
00065         socket_client_connection(int _port, const std::string& _server="127.0.0.1", 
00066             long long _connect_timeout_usec=connect_timeout_usec_default, 
00067             int _max_retries=max_retries_default,
00068             std::ostream *_logstream=NULL, log_level_values _log_level=none);
00069         socket_client_connection(const std::string& _path,
00070             long long _connect_timeout_usec=connect_timeout_usec_default, 
00071             int _max_retries=max_retries_default,
00072             std::ostream *_logstream=NULL, log_level_values _log_level=none);
00073 
00074         ~socket_client_connection();
00075 
00085         bool fill_buffer(long long usec_timeout=-1, long long *usec_timeout_remaining=NULL)
00086             { return socket_handler::fill_buffer(buffer,usec_timeout,usec_timeout_remaining); }
00087 
00088         virtual void close();
00089 
00090         void reconnect();
00091 
00092         std::string get_last_error_msg(void)
00093             { return lastErrorMsg; }
00094 };
00095 
00096 }
00097 
00098 #endif

Generated on 13 May 2015 by  doxygen 1.6.1
© Intra2net AG 2024 | Legal | Contact