use runtime checking instead of compile-time checking for TCP_FASTOPEN

This commit is contained in:
clowwindy
2014-05-03 15:39:05 +08:00
parent 75add87313
commit 5d0696f655
2 changed files with 18 additions and 1 deletions
+12 -1
View File
@@ -100,7 +100,18 @@ int create_and_bind(const char *host, const char *port)
if (fast_open)
{
opt = 5;
setsockopt(listen_sock, SOL_TCP, TCP_FASTOPEN, &opt, sizeof(opt));
int r = setsockopt(listen_sock, IPPROTO_TCP, TCP_FASTOPEN, &opt, sizeof(opt));
if (r == -1)
{
if (errno == EPROTONOSUPPORT || errno == ENOPROTOOPT)
{
LOGE("fast open is not supported on this platform");
}
else
{
ERROR("setsockopt");
}
}
}
#endif