X-Git-Url: http://developer.intra2net.com/git/?p=libt2n;a=blobdiff_plain;f=src%2Fsocket_client.hxx;h=a7fe64e0a3c649eaa29ed4b3aad212e2090c6458;hp=a35bbfdbf938e6b175ccb780024d44e4a888cb3b;hb=af84dfb53a739a0c8c343d9172f1847fa908906d;hpb=a7170401dd90dc79cc7d7a808cfe18a06c7e983b diff --git a/src/socket_client.hxx b/src/socket_client.hxx index a35bbfd..a7fe64e 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,14 +34,18 @@ 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; @@ -49,20 +55,28 @@ class socket_client_connection : public client_connection, public socket_handler { 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); + socket_client_connection(const std::string& _path, + long long _connect_timeout_usec=connect_timeout_usec_default, + int _max_retries=max_retries_default); /** @brief read data from the socket and copy it into buffer @param usec_timeout wait until new data is found, max timeout usecs. - -1: wait endless - NULL: no timeout + -1: wait endless + 0: return instantly + @param usec_timeout_remaining if non-NULL the function will write the + not used time to the given target @retval true if new data was found (does not mean that the received data is a complete packet though) */ - bool fill_buffer(long long usec_timeout=-1) - { return socket_handler::fill_buffer(buffer,usec_timeout); } + bool fill_buffer(long long usec_timeout=-1, long long *usec_timeout_remaining=NULL) + { return socket_handler::fill_buffer(buffer,usec_timeout,usec_timeout_remaining); } void close(); + + void reconnect(); }; }