diff --git a/HISTORY b/HISTORY index 8c19ebd1a3a25619d09cc2902368396fe3127a60..d289d6d8ae0a008ff0531d100e6c8dc4cdbe58b4 100644 --- a/HISTORY +++ b/HISTORY @@ -1,5 +1,5 @@ -Version 1.39 2018-07-26 +Version 1.39 2018-07-31 * add #@function REPLACE_VARS * #@set value can embed %{VARIABLE} * shared_func.h: add function starts_with and ends_with @@ -7,6 +7,7 @@ Version 1.39 2018-07-26 * sched_thread.c: fix first schedule time * ini_file_reader add function iniGetRequiredStrValueEx * add file fc_list.h + * sockopt.c: add global variable try_again_when_interrupt Version 1.38 2018-06-26 * connection_pool.c: set err_no to 0 when success diff --git a/src/sockopt.c b/src/sockopt.c index 696a44675966813166e238e9fa40922af5a15bfd..6c802ec9dd40ebad68c1315918978cfd02ca202f 100644 --- a/src/sockopt.c +++ b/src/sockopt.c @@ -70,6 +70,13 @@ #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 result; @@ -163,7 +170,7 @@ int tcprecvdata_ex(int sock, void *data, const int size, \ if (res < 0) { - if (errno == EINTR) + if (errno == EINTR && try_again_when_interrupt) { continue; } @@ -179,7 +186,7 @@ int tcprecvdata_ex(int sock, void *data, const int size, \ read_bytes = recv(sock, p, left_bytes, 0); if (read_bytes < 0) { - if (errno == EINTR) + if (errno == EINTR && try_again_when_interrupt) { continue; } @@ -250,7 +257,7 @@ int tcpsenddata(int sock, void* data, const int size, const int timeout) if (result < 0) { - if (errno == EINTR) + if (errno == EINTR && try_again_when_interrupt) { continue; } @@ -264,7 +271,7 @@ int tcpsenddata(int sock, void* data, const int size, const int timeout) write_bytes = send(sock, p, left_bytes, 0); if (write_bytes < 0) { - if (errno == EINTR) + if (errno == EINTR && try_again_when_interrupt) { continue; } @@ -357,7 +364,7 @@ int tcprecvdata_nb_ms(int sock, void *data, const int size, \ if (res < 0) { - if (errno == EINTR) + if (errno == EINTR && try_again_when_interrupt) { continue; } @@ -440,7 +447,7 @@ int tcpsenddata_nb(int sock, void* data, const int size, const int timeout) if (result < 0) { - if (errno == EINTR) + if (errno == EINTR && try_again_when_interrupt) { continue; } @@ -1287,7 +1294,7 @@ int tcpsendfile_ex(int sock, const char *filename, const int64_t file_offset, \ if (send_bytes <= 0) { result = errno != 0 ? errno : EIO; - if (result == EINTR) + if (result == EINTR && try_again_when_interrupt) { continue; } @@ -1309,7 +1316,7 @@ int tcpsendfile_ex(int sock, const char *filename, const int64_t file_offset, \ len = remain_bytes; if (sendfile(fd, sock, offset, &len, NULL, 0) != 0) { result = errno != 0 ? errno : EIO; - if (result != EINTR) + if (!(result == EINTR && try_again_when_interrupt)) { break; } @@ -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) { result = errno != 0 ? errno : EIO; - if (result != EINTR) + if (!(result == EINTR && try_again_when_interrupt)) { break; } diff --git a/src/sockopt.h b/src/sockopt.h index 9918a2a77940a06dd161c517522a9943e883d0b8..9b0b634896de82888c7c041489af33eb52e61e42 100644 --- a/src/sockopt.h +++ b/src/sockopt.h @@ -392,6 +392,13 @@ static inline bool is_ipv6_addr(const char *ip) 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 } #endif