|
@@ -32,6 +32,7 @@
|
|
|
# include <pthread_np.h>
|
|
# include <pthread_np.h>
|
|
|
#endif
|
|
#endif
|
|
|
#ifndef WIN32
|
|
#ifndef WIN32
|
|
|
|
|
+#include <fcntl.h>
|
|
|
# ifdef __linux
|
|
# ifdef __linux
|
|
|
# include <sys/prctl.h>
|
|
# include <sys/prctl.h>
|
|
|
# endif
|
|
# endif
|
|
@@ -236,14 +237,24 @@ out:
|
|
|
|
|
|
|
|
static int keep_sockalive(SOCKETTYPE fd)
|
|
static int keep_sockalive(SOCKETTYPE fd)
|
|
|
{
|
|
{
|
|
|
|
|
+ const int tcp_one = 1;
|
|
|
const int tcp_keepidle = 45;
|
|
const int tcp_keepidle = 45;
|
|
|
const int tcp_keepintvl = 30;
|
|
const int tcp_keepintvl = 30;
|
|
|
- const int tcp_one = 1;
|
|
|
|
|
int ret = 0;
|
|
int ret = 0;
|
|
|
|
|
|
|
|
if (unlikely(setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, (const char *)&tcp_one, sizeof(tcp_one))))
|
|
if (unlikely(setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, (const char *)&tcp_one, sizeof(tcp_one))))
|
|
|
ret = 1;
|
|
ret = 1;
|
|
|
|
|
|
|
|
|
|
+#ifndef WIN32
|
|
|
|
|
+ int flags = fcntl(fd, F_GETFL, 0);
|
|
|
|
|
+
|
|
|
|
|
+ fcntl(fd, F_SETFL, O_NONBLOCK | flags);
|
|
|
|
|
+#else
|
|
|
|
|
+ u_long flags = 1;
|
|
|
|
|
+
|
|
|
|
|
+ ioctlsocket(fd, FIONBIO, &flags);
|
|
|
|
|
+#endif
|
|
|
|
|
+
|
|
|
if (!opt_delaynet)
|
|
if (!opt_delaynet)
|
|
|
#ifndef __linux
|
|
#ifndef __linux
|
|
|
if (unlikely(setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (const void *)&tcp_one, sizeof(tcp_one))))
|
|
if (unlikely(setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (const void *)&tcp_one, sizeof(tcp_one))))
|