Try to use SO_ACCEPTFILTER to defer accept on non-linux platforms
This commit is contained in:
20
src/main.c
20
src/main.c
@@ -98,6 +98,7 @@ enum sk_opt {
|
|||||||
sk_keepintvl,
|
sk_keepintvl,
|
||||||
sk_congestion,
|
sk_congestion,
|
||||||
sk_defer_accept,
|
sk_defer_accept,
|
||||||
|
sk_acceptfilter,
|
||||||
sk_quickack,
|
sk_quickack,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -143,6 +144,11 @@ static void sk_set (int fd, enum sk_opt opt, const void *val, socklen_t len)
|
|||||||
[sk_quickack] = { "TCP_QUICKACK",
|
[sk_quickack] = { "TCP_QUICKACK",
|
||||||
#ifdef TCP_QUICKACK
|
#ifdef TCP_QUICKACK
|
||||||
1, IPPROTO_TCP, TCP_QUICKACK,
|
1, IPPROTO_TCP, TCP_QUICKACK,
|
||||||
|
#endif
|
||||||
|
},
|
||||||
|
[sk_acceptfilter] = { "SO_ACCEPTFILTER",
|
||||||
|
#ifdef SO_ACCEPTFILTER
|
||||||
|
1, SOL_SOCKET, SO_ACCEPTFILTER,
|
||||||
#endif
|
#endif
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@@ -165,21 +171,23 @@ static int sk_listen (int fd, struct addrinfo *ai)
|
|||||||
{
|
{
|
||||||
sk_set_int(fd, sk_reuseaddr, 1);
|
sk_set_int(fd, sk_reuseaddr, 1);
|
||||||
|
|
||||||
int ret = bind(fd, ai->ai_addr, ai->ai_addrlen);
|
if (bind(fd, ai->ai_addr, ai->ai_addrlen)==-1) {
|
||||||
|
|
||||||
if (ret==-1) {
|
|
||||||
perror("bind");
|
perror("bind");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = listen(fd, 8);
|
if (listen(fd, 8)==-1) {
|
||||||
|
|
||||||
if (ret==-1) {
|
|
||||||
perror("listen");
|
perror("listen");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef __linux__
|
||||||
sk_set_int(fd, sk_defer_accept, GT_TIMEOUT/1000);
|
sk_set_int(fd, sk_defer_accept, GT_TIMEOUT/1000);
|
||||||
|
#else
|
||||||
|
char data[256] = {0};
|
||||||
|
str_cpy(data, "dataready", sizeof(data)-1);
|
||||||
|
sk_set(fd, sk_acceptfilter, &data, sizeof(data));
|
||||||
|
#endif
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user