X-Git-Url: http://developer.intra2net.com/git/?p=libt2n;a=blobdiff_plain;f=src%2Fsocket_client.hxx;h=cea491e01346c7ce17c1344990f5b2bf83771634;hp=1d8240005010700b4752a4f1a231a194edc80a54;hb=fb3345ada7ea94225b78994fd50e3de693a2a3d5;hpb=45a2ebc9695c4d7be6548b7e0f800d117ae56a0b diff --git a/src/socket_client.hxx b/src/socket_client.hxx index 1d82400..cea491e 100644 --- a/src/socket_client.hxx +++ b/src/socket_client.hxx @@ -22,6 +22,8 @@ #include "client.hxx" #include "socket_handler.hxx" +struct sockaddr; + namespace libt2n { /** @brief a connection from client to server using sockets. @@ -32,25 +34,39 @@ class socket_client_connection : public client_connection, public socket_handler { public: static const int max_retries_default=3; + static const long long connect_timeout_usec_default=30000000; private: void real_write(const std::string& data) { socket_write(data); } - void connect(); + void tcp_connect(int max_retries); + void unix_connect(int max_retries); + void connect_with_timeout(struct sockaddr *sock_addr,unsigned int sockaddr_size); int max_retries; + long long connect_timeout_usec; std::string path; std::string server; int port; + std::string lastErrorMsg; + + protected: + std::ostream* get_logstream(log_level_values level) { return client_connection::get_logstream(level); } public: - socket_client_connection(const std::string& _server, int _port, int _max_retries=max_retries_default); - socket_client_connection(const std::string& _path, int _max_retries=max_retries_default); + socket_client_connection(int _port, const std::string& _server="127.0.0.1", + long long _connect_timeout_usec=connect_timeout_usec_default, + int _max_retries=max_retries_default, + std::ostream *_logstream=NULL, log_level_values _log_level=none); + socket_client_connection(const std::string& _path, + long long _connect_timeout_usec=connect_timeout_usec_default, + int _max_retries=max_retries_default, + std::ostream *_logstream=NULL, log_level_values _log_level=none); /** @brief read data from the socket and copy it into buffer @param usec_timeout wait until new data is found, max timeout usecs. @@ -65,6 +81,11 @@ class socket_client_connection : public client_connection, public socket_handler { return socket_handler::fill_buffer(buffer,usec_timeout,usec_timeout_remaining); } void close(); + + void reconnect(); + + std::string get_last_error_msg(void) + { return lastErrorMsg; } }; }