X-Git-Url: http://developer.intra2net.com/git/?p=libt2n;a=blobdiff_plain;f=src%2Fsocket_client.hxx;h=a35bbfdbf938e6b175ccb780024d44e4a888cb3b;hp=117aa6d64aaa22227b2d73116d5a49d1257b396c;hb=a7170401dd90dc79cc7d7a808cfe18a06c7e983b;hpb=a11e19b7adab2d5b937573701959562f06087ac5 diff --git a/src/socket_client.hxx b/src/socket_client.hxx index 117aa6d..a35bbfd 100644 --- a/src/socket_client.hxx +++ b/src/socket_client.hxx @@ -24,19 +24,43 @@ namespace libt2n { +/** @brief a connection from client to server using sockets. -class socket_client_connection : public client_connection, socket_handler + Use this class to connect from a client to a server. + */ +class socket_client_connection : public client_connection, public socket_handler { + public: + static const int max_retries_default=3; + private: void real_write(const std::string& data) - { socket_handler::write(data); } + { socket_write(data); } + + void connect(); + + int max_retries; + + std::string path; + std::string server; + int port; + + std::ostream* get_logstream(log_level_values level) + { return client_connection::get_logstream(level); } public: - socket_client_connection(int port, const char* ip="0.0.0.0"); - socket_client_connection(const char* path, mode_t filemode, const char* user="", const char* group=""); + 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); - void fill_buffer(long long usec_timeout=-1) - { socket_handler::fill_buffer(buffer,usec_timeout); } + /** @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 + @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); } void close(); };