sockopt.c add tcprecvdata_nb_ms to support millisecond timeout
parent
31db77f3cd
commit
dd42d9c08c
3
HISTORY
3
HISTORY
|
|
@ -1,5 +1,5 @@
|
||||||
|
|
||||||
Version 1.06 2014-07-02
|
Version 1.06 2014-07-14
|
||||||
* update source code from FastDFS V5.02
|
* update source code from FastDFS V5.02
|
||||||
* add function short2buff and buff2short
|
* add function short2buff and buff2short
|
||||||
* add object memory pool (fast_mblock.h and fast_mblock.c)
|
* 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
|
* logger can delete old rotated files
|
||||||
* bug fixed: connection pool should NOT increase counter when connect fail
|
* bug fixed: connection pool should NOT increase counter when connect fail
|
||||||
* logger.c do NOT call fsync after write
|
* logger.c do NOT call fsync after write
|
||||||
|
* sockopt.c add tcprecvdata_nb_ms to support millisecond timeout
|
||||||
|
|
||||||
Version 1.05 2012-07-08
|
Version 1.05 2012-07-08
|
||||||
* update source code from FastDFS V3.09
|
* update source code from FastDFS V3.09
|
||||||
|
|
|
||||||
|
|
@ -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, \
|
int tcprecvdata_nb_ex(int sock, void *data, const int size, \
|
||||||
const int timeout, int *count)
|
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 left_bytes;
|
||||||
int read_bytes;
|
int read_bytes;
|
||||||
|
|
@ -304,7 +310,6 @@ int tcprecvdata_nb_ex(int sock, void *data, const int size, \
|
||||||
|
|
||||||
if (read_bytes < 0)
|
if (read_bytes < 0)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (!(errno == EAGAIN || errno == EWOULDBLOCK))
|
if (!(errno == EAGAIN || errno == EWOULDBLOCK))
|
||||||
{
|
{
|
||||||
ret_code = errno != 0 ? errno : EINTR;
|
ret_code = errno != 0 ? errno : EINTR;
|
||||||
|
|
@ -324,12 +329,12 @@ int tcprecvdata_nb_ex(int sock, void *data, const int size, \
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
t.tv_usec = 0;
|
t.tv_usec = timeout_ms * 1000;
|
||||||
t.tv_sec = timeout;
|
t.tv_sec = timeout_ms / 1000;
|
||||||
res = select(sock+1, &read_set, NULL, NULL, &t);
|
res = select(sock+1, &read_set, NULL, NULL, &t);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
res = poll(&pollfds, 1, 1000 * timeout);
|
res = poll(&pollfds, 1, timeout_ms);
|
||||||
if (pollfds.revents & POLLHUP)
|
if (pollfds.revents & POLLHUP)
|
||||||
{
|
{
|
||||||
ret_code = ENOTCONN;
|
ret_code = ENOTCONN;
|
||||||
|
|
|
||||||
|
|
@ -61,13 +61,25 @@ int tcprecvdata_ex(int sock, void *data, const int size, \
|
||||||
* sock: the socket
|
* sock: the socket
|
||||||
* data: the buffer
|
* data: the buffer
|
||||||
* size: buffer size (max bytes can receive)
|
* size: buffer size (max bytes can receive)
|
||||||
* timeout: read timeout
|
* timeout: read timeout in seconds
|
||||||
* count: store the bytes recveived
|
* count: store the bytes recveived
|
||||||
* return: error no, 0 success, != 0 fail
|
* return: error no, 0 success, != 0 fail
|
||||||
*/
|
*/
|
||||||
int tcprecvdata_nb_ex(int sock, void *data, const int size, \
|
int tcprecvdata_nb_ex(int sock, void *data, const int size, \
|
||||||
const int timeout, int *count);
|
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)
|
/** send data (block mode)
|
||||||
* parameters:
|
* parameters:
|
||||||
* sock: the socket
|
* sock: the socket
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue