more clean up about "move TCP_NODELAY"
@@ -409,17 +409,12 @@ h2o_socket_t *h2o_evloop_socket_create(h2o_evloop_t *loop, int fd, int flags)
{
fcntl(fd, F_SETFL, O_NONBLOCK); /* not always needed under linux, the caller may already set this flag */
- {
- int flag = 1;
/**
* fd maybe from pipe(2)/eventfd(2)/socketpair(2)/unix domain socket besides tcp sockets.
* requiring the user of the event loop to set the flag would increase the complexity.
* so we set here and ignore errors
*/
- setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &flag, sizeof(flag));
- }
-
- return &create_socket(loop, fd, flags)->super;
+ return &create_socket_set_nodelay(loop, fd, flags)->super;
}
h2o_socket_t *h2o_evloop_socket_accept(h2o_socket_t *_listener)
@@ -430,30 +425,17 @@ h2o_socket_t *h2o_evloop_socket_accept(h2o_socket_t *_listener)
#if H2O_USE_ACCEPT4
if ((fd = accept4(listener->fd, NULL, NULL, SOCK_NONBLOCK | SOCK_CLOEXEC)) == -1)
return NULL;
-#else
- if ((fd = cloexec_accept(listener->fd, NULL, NULL)) == -1)
- return NULL;
- fcntl(fd, F_SETFL, O_NONBLOCK);
-#endif
-
-
/**
* the listening socket should already have TCP_NODELAY set.
- * if accepted socket can inherit this option form listing socket, do not call setsockopt again
+ * if accepted socket can inherit this option form listing socket, do not call setsockopt(2) again.
+ * For platforms that support inheritance of TCP_NODELAY but do not provide accept4 (maybe it's only NetBSD?)
+ * so using H2O_USE_ACCEPT4 to judge TCP_NODELAY option inherit.
* FIXME: check more platforms: e.g. OpenBSD, Solaris, AIX
- * currently done under:
+ * TCP_NODELAY inherit from listening socket known under:
* linux
- * FreeBSD version bigger than 4
+ * FreeBSD version bigger than 4.5
* NetBSD verison equal or bigger than 1.6(@see NetBSD6.0/usr/share/man/html4/tcp.html)
*/
-#if !(defined(__linux__) || (defined(__FreeBSD__) && (__FreeBSD__ > 4)) || \
- (defined(__NetBSD__) && (__NetBSD_Version__ >= 106000000)))
- {
- /* set TCP_NODELAY, ignore error */
- int flag = 1;
- setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &flag, sizeof(flag));
- }
-#else
#if !defined(NDEBUG) && defined(DEBUG)
{
/* check TCP_NODELAY flag when debug */
@@ -463,10 +445,15 @@ h2o_socket_t *h2o_evloop_socket_accept(h2o_socket_t *_listener)
assert(flag == 1);
}
}
-#endif
#endif
return &create_socket(listener->loop, fd, H2O_SOCKET_FLAG_IS_ACCEPTED_CONNECTION)->super;
+#else
+ if ((fd = cloexec_accept(listener->fd, NULL, NULL)) == -1)
+ return NULL;
+ fcntl(fd, F_SETFL, O_NONBLOCK);
+ return &create_socket_set_nodelay(listener->loop, fd, H2O_SOCKET_FLAG_IS_ACCEPTED_CONNECTION)->super;
+#endif
}
h2o_socket_t *h2o_socket_connect(h2o_loop_t *loop, struct sockaddr *addr, socklen_t addrlen, h2o_socket_cb cb)
