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 #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