Merge pull request #71 from clowwindy/master

use runtime checking instead of compile-time checking for TCP_FASTOPEN
This commit is contained in:
Max Lv
2014-05-03 16:59:47 +08:00
2 changed files with 18 additions and 1 deletions
+6
View File
@@ -211,6 +211,12 @@ static void server_recv_cb (EV_P_ ev_io *w, int revents)
else
{
ERROR("sendto");
if (errno == ENOTCONN)
{
LOGE("fast open is not supported on this platform");
// just turn it off
fast_open = 0;
}
close_and_free_remote(EV_A_ remote);
close_and_free_server(EV_A_ server);
return;
+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