socket_client.hxx
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
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