diff --git a/HISTORY b/HISTORY index fac8eba..5977760 100644 --- a/HISTORY +++ b/HISTORY @@ -1,5 +1,5 @@ -Version 1.06 2014-07-02 +Version 1.06 2014-07-14 * update source code from FastDFS V5.02 * add function short2buff and buff2short * add object memory pool (fast_mblock.h and fast_mblock.c) @@ -15,6 +15,7 @@ Version 1.06 2014-07-02 * logger can delete old rotated files * bug fixed: connection pool should NOT increase counter when connect fail * logger.c do NOT call fsync after write + * sockopt.c add tcprecvdata_nb_ms to support millisecond timeout Version 1.05 2012-07-08 * update source code from FastDFS V3.09 diff --git a/src/sockopt.c b/src/sockopt.c index 2a8dc42..f0dea6c 100644 --- a/src/sockopt.c +++ b/src/sockopt.c @@ -267,6 +267,12 @@ int tcpsenddata(int sock, void* data, const int size, const int timeout) int tcprecvdata_nb_ex(int sock, void *data, const int size, \ const int timeout, int *count) +{ + return tcprecvdata_nb_ms(sock, data, size, timeout * 1000, count); +} + +int tcprecvdata_nb_ms(int sock, void *data, const int size, \ + const int timeout_ms, int *count) { int left_bytes; int read_bytes; @@ -304,7 +310,6 @@ int tcprecvdata_nb_ex(int sock, void *data, const int size, \ if (read_bytes < 0) { - if (!(errno == EAGAIN || errno == EWOULDBLOCK)) { ret_code = errno != 0 ? errno : EINTR; @@ -324,12 +329,12 @@ int tcprecvdata_nb_ex(int sock, void *data, const int size, \ } else { - t.tv_usec = 0; - t.tv_sec = timeout; + t.tv_usec = timeout_ms * 1000; + t.tv_sec = timeout_ms / 1000; res = select(sock+1, &read_set, NULL, NULL, &t); } #else - res = poll(&pollfds, 1, 1000 * timeout); + res = poll(&pollfds, 1, timeout_ms); if (pollfds.revents & POLLHUP) { ret_code = ENOTCONN; diff --git a/src/sockopt.h b/src/sockopt.h index 1c8773c..6019a66 100644 --- a/src/sockopt.h +++ b/src/sockopt.h @@ -61,13 +61,25 @@ int tcprecvdata_ex(int sock, void *data, const int size, \ * sock: the socket * data: the buffer * size: buffer size (max bytes can receive) - * timeout: read timeout + * timeout: read timeout in seconds * count: store the bytes recveived * return: error no, 0 success, != 0 fail */ int tcprecvdata_nb_ex(int sock, void *data, const int size, \ const int timeout, int *count); +/** recv data (non-block mode) in ms + * parameters: + * sock: the socket + * data: the buffer + * size: buffer size (max bytes can receive) + * timeout: read timeout in milliseconds + * count: store the bytes recveived + * return: error no, 0 success, != 0 fail +*/ +int tcprecvdata_nb_ms(int sock, void *data, const int size, \ + const int timeout_ms, int *count); + /** send data (block mode) * parameters: * sock: the socket