提交 722a9442 编写于 作者: Y yuqing

sockopt.c: add global variable try_again_when_interrupt

上级 4ae9c8f5
Version 1.39 2018-07-26 Version 1.39 2018-07-31
* add #@function REPLACE_VARS * add #@function REPLACE_VARS
* #@set value can embed %{VARIABLE} * #@set value can embed %{VARIABLE}
* shared_func.h: add function starts_with and ends_with * shared_func.h: add function starts_with and ends_with
...@@ -7,6 +7,7 @@ Version 1.39 2018-07-26 ...@@ -7,6 +7,7 @@ Version 1.39 2018-07-26
* sched_thread.c: fix first schedule time * sched_thread.c: fix first schedule time
* ini_file_reader add function iniGetRequiredStrValueEx * ini_file_reader add function iniGetRequiredStrValueEx
* add file fc_list.h * add file fc_list.h
* sockopt.c: add global variable try_again_when_interrupt
Version 1.38 2018-06-26 Version 1.38 2018-06-26
* connection_pool.c: set err_no to 0 when success * connection_pool.c: set err_no to 0 when success
......
...@@ -70,6 +70,13 @@ ...@@ -70,6 +70,13 @@
#endif #endif
#endif #endif
static bool try_again_when_interrupt = true;
void tcp_set_try_again_when_interrupt(const bool value)
{
try_again_when_interrupt = value;
}
int tcpgets(int sock, char* s, const int size, const int timeout) int tcpgets(int sock, char* s, const int size, const int timeout)
{ {
int result; int result;
...@@ -163,7 +170,7 @@ int tcprecvdata_ex(int sock, void *data, const int size, \ ...@@ -163,7 +170,7 @@ int tcprecvdata_ex(int sock, void *data, const int size, \
if (res < 0) if (res < 0)
{ {
if (errno == EINTR) if (errno == EINTR && try_again_when_interrupt)
{ {
continue; continue;
} }
...@@ -179,7 +186,7 @@ int tcprecvdata_ex(int sock, void *data, const int size, \ ...@@ -179,7 +186,7 @@ int tcprecvdata_ex(int sock, void *data, const int size, \
read_bytes = recv(sock, p, left_bytes, 0); read_bytes = recv(sock, p, left_bytes, 0);
if (read_bytes < 0) if (read_bytes < 0)
{ {
if (errno == EINTR) if (errno == EINTR && try_again_when_interrupt)
{ {
continue; continue;
} }
...@@ -250,7 +257,7 @@ int tcpsenddata(int sock, void* data, const int size, const int timeout) ...@@ -250,7 +257,7 @@ int tcpsenddata(int sock, void* data, const int size, const int timeout)
if (result < 0) if (result < 0)
{ {
if (errno == EINTR) if (errno == EINTR && try_again_when_interrupt)
{ {
continue; continue;
} }
...@@ -264,7 +271,7 @@ int tcpsenddata(int sock, void* data, const int size, const int timeout) ...@@ -264,7 +271,7 @@ int tcpsenddata(int sock, void* data, const int size, const int timeout)
write_bytes = send(sock, p, left_bytes, 0); write_bytes = send(sock, p, left_bytes, 0);
if (write_bytes < 0) if (write_bytes < 0)
{ {
if (errno == EINTR) if (errno == EINTR && try_again_when_interrupt)
{ {
continue; continue;
} }
...@@ -357,7 +364,7 @@ int tcprecvdata_nb_ms(int sock, void *data, const int size, \ ...@@ -357,7 +364,7 @@ int tcprecvdata_nb_ms(int sock, void *data, const int size, \
if (res < 0) if (res < 0)
{ {
if (errno == EINTR) if (errno == EINTR && try_again_when_interrupt)
{ {
continue; continue;
} }
...@@ -440,7 +447,7 @@ int tcpsenddata_nb(int sock, void* data, const int size, const int timeout) ...@@ -440,7 +447,7 @@ int tcpsenddata_nb(int sock, void* data, const int size, const int timeout)
if (result < 0) if (result < 0)
{ {
if (errno == EINTR) if (errno == EINTR && try_again_when_interrupt)
{ {
continue; continue;
} }
...@@ -1287,7 +1294,7 @@ int tcpsendfile_ex(int sock, const char *filename, const int64_t file_offset, \ ...@@ -1287,7 +1294,7 @@ int tcpsendfile_ex(int sock, const char *filename, const int64_t file_offset, \
if (send_bytes <= 0) if (send_bytes <= 0)
{ {
result = errno != 0 ? errno : EIO; result = errno != 0 ? errno : EIO;
if (result == EINTR) if (result == EINTR && try_again_when_interrupt)
{ {
continue; continue;
} }
...@@ -1309,7 +1316,7 @@ int tcpsendfile_ex(int sock, const char *filename, const int64_t file_offset, \ ...@@ -1309,7 +1316,7 @@ int tcpsendfile_ex(int sock, const char *filename, const int64_t file_offset, \
len = remain_bytes; len = remain_bytes;
if (sendfile(fd, sock, offset, &len, NULL, 0) != 0) { if (sendfile(fd, sock, offset, &len, NULL, 0) != 0) {
result = errno != 0 ? errno : EIO; result = errno != 0 ? errno : EIO;
if (result != EINTR) if (!(result == EINTR && try_again_when_interrupt))
{ {
break; break;
} }
...@@ -1326,7 +1333,7 @@ int tcpsendfile_ex(int sock, const char *filename, const int64_t file_offset, \ ...@@ -1326,7 +1333,7 @@ int tcpsendfile_ex(int sock, const char *filename, const int64_t file_offset, \
if (sendfile(fd, sock, offset, remain_bytes, NULL, &sbytes, 0) != 0) if (sendfile(fd, sock, offset, remain_bytes, NULL, &sbytes, 0) != 0)
{ {
result = errno != 0 ? errno : EIO; result = errno != 0 ? errno : EIO;
if (result != EINTR) if (!(result == EINTR && try_again_when_interrupt))
{ {
break; break;
} }
......
...@@ -392,6 +392,13 @@ static inline bool is_ipv6_addr(const char *ip) ...@@ -392,6 +392,13 @@ static inline bool is_ipv6_addr(const char *ip)
return (*ip == ':' || strchr(ip, ':') != NULL); //ipv6 return (*ip == ':' || strchr(ip, ':') != NULL); //ipv6
} }
void tcp_set_try_again_when_interrupt(const bool value);
static inline void tcp_dont_try_again_when_interrupt()
{
tcp_set_try_again_when_interrupt(false);
}
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册