X-Git-Url: http://developer.intra2net.com/git/?p=libt2n;a=blobdiff_plain;f=src%2Fsocket_handler.cpp;h=2856adf4e67a5de09ad920628fbe6f07d3216dba;hp=f2ddcb6a4b6abd9ccabc1f2645b6af9da133738b;hb=7087e18783f91d2b889e880462d1d1da24831c28;hpb=07e98688a1a8c3e915ce923f79261a88251a9edd diff --git a/src/socket_handler.cpp b/src/socket_handler.cpp index f2ddcb6..2856adf 100644 --- a/src/socket_handler.cpp +++ b/src/socket_handler.cpp @@ -44,6 +44,7 @@ using namespace std; namespace libt2n { +/// set options like fast reuse and keepalive every socket should have void socket_handler::set_socket_options(int sock) { int i=1; @@ -105,6 +106,8 @@ void socket_handler::set_socket_options(int sock) } } +/// close the underlying socket connection. Don't call directly, use the version provided +/// by the connection class you are using. void socket_handler::close() { // graceful shutdown @@ -112,6 +115,7 @@ void socket_handler::close() ::close(sock); } +/// is the underlying socket connection still open? bool socket_handler::is_closed() { int r=fcntl(sock,F_GETFL); @@ -119,6 +123,11 @@ bool socket_handler::is_closed() return !(r & O_ACCMODE); } +/** @brief check if new data is waiting on the raw socket + @param usec_timeout wait until new data is found, max timeout usecs. + -1: wait endless + NULL: no timeout +*/ bool socket_handler::data_waiting(long long usec_timeout) { // just our socket @@ -147,6 +156,12 @@ bool socket_handler::data_waiting(long long usec_timeout) return false; } +/** @brief read data from the raw socket and copy it into the provided buffer + @param buffer the buffer where to append the new data + @param usec_timeout wait until new data is found, max timeout usecs. + -1: wait endless + NULL: no timeout +*/ bool socket_handler::fill_buffer(std::string& buffer, long long usec_timeout) { // fast path for timeout==0 @@ -156,6 +171,10 @@ bool socket_handler::fill_buffer(std::string& buffer, long long usec_timeout) return false; } +/** @brief read data from the raw socket and copy it into the provided buffer. Returns + instantly if no data is waiting. + @param buffer the buffer where to append the new data +*/ bool socket_handler::fill_buffer(std::string& buffer) { bool try_again=false; @@ -201,6 +220,8 @@ bool socket_handler::fill_buffer(std::string& buffer) return false; } +/// writes raw data to the socket. Don't use directly, use the write() function provided by the +/// connection because it encapsulates the data. void socket_handler::socket_write(const std::string& data) { int offset = 0;