socket_client.hxx

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2006 by Gerd v. Egidy                                   *
00003  *   gve@intra2net.com                                                     *
00004  *                                                                         *
00005  *   This library is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU Lesser General Public License version   *
00007  *   2.1 as published by the Free Software Foundation.                     *
00008  *                                                                         *
00009  *   This library is distributed in the hope that it will be useful,       *
00010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00012  *   GNU Lesser General Public License for more details.                   *
00013  *                                                                         *
00014  *   You should have received a copy of the GNU Lesser General Public      *
00015  *   License along with this program; if not, write to the                 *
00016  *   Free Software Foundation, Inc.,                                       *
00017  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00018  ***************************************************************************/
00019 #ifndef __LIBT2N_SOCKET_CLIENT
00020 #define __LIBT2N_SOCKET_CLIENT
00021 
00022 #include "client.hxx"
00023 #include "socket_handler.hxx"
00024 
00025 struct sockaddr;
00026 
00027 namespace libt2n
00028 {
00033 class socket_client_connection : public client_connection, public socket_handler
00034 {
00035     public:
00036         static const int max_retries_default=3;
00037         static const long long connect_timeout_usec_default=30000000;
00038 
00039     private:
00040         void real_write(const std::string& data)
00041             { socket_write(data); }
00042 
00043         void tcp_connect(int max_retries);
00044         void unix_connect(int max_retries);
00045         void connect_with_timeout(struct sockaddr *sock_addr,unsigned int sockaddr_size);
00046 
00047         int max_retries;
00048         long long connect_timeout_usec;
00049 
00050         std::string path;
00051         std::string server;
00052         int port;
00053 
00054         std::string lastErrorMsg;
00055 
00056     protected:
00057 
00058         std::ostream* get_logstream(log_level_values level)
00059             { return client_connection::get_logstream(level); }
00060 
00061     public:
00062         socket_client_connection(int _port, const std::string& _server="127.0.0.1", 
00063             long long _connect_timeout_usec=connect_timeout_usec_default, 
00064             int _max_retries=max_retries_default,
00065             std::ostream *_logstream=NULL, log_level_values _log_level=none);
00066         socket_client_connection(const std::string& _path,
00067             long long _connect_timeout_usec=connect_timeout_usec_default, 
00068             int _max_retries=max_retries_default,
00069             std::ostream *_logstream=NULL, log_level_values _log_level=none);
00070 
00080         bool fill_buffer(long long usec_timeout=-1, long long *usec_timeout_remaining=NULL)
00081             { return socket_handler::fill_buffer(buffer,usec_timeout,usec_timeout_remaining); }
00082 
00083         void close();
00084 
00085         void reconnect();
00086 
00087         std::string get_last_error_msg(void)
00088             { return lastErrorMsg; }
00089 };
00090 
00091 }
00092 
00093 #endif

Generated on Fri Sep 26 15:36:59 2008 for libt2n by  doxygen 1.5.6