diff --git a/configure.ac b/configure.ac index f09ec8c..2d029bc 100644 --- a/configure.ac +++ b/configure.ac @@ -75,6 +75,7 @@ AC_CHECK_FUNCS([mlockall]) AC_CHECK_FUNCS([getpagesizes]) AC_CHECK_FUNCS([memcntl]) AC_CHECK_FUNCS([backtrace]) +AC_CHECK_FUNCS([accept4], [AC_DEFINE(HAVE_ACCEPT4, 1, [Define to 1 if support accept4])]) # Search for library AC_SEARCH_LIBS([pthread_create], [pthread], [], diff --git a/src/mc_core.c b/src/mc_core.c index f163874..4495ccf 100644 --- a/src/mc_core.c +++ b/src/mc_core.c @@ -449,7 +449,11 @@ core_accept(struct conn *c) ASSERT(c->state == CONN_LISTEN); for (;;) { +#if (HAVE_ACCEPT4) + sd = accept4(c->sd, NULL, NULL, SOCK_NONBLOCK); +#else sd = accept(c->sd, NULL, NULL); +#endif if (sd < 0) { if (errno == EINTR) { log_debug(LOG_VERB, "accept on s %d not ready - eintr", c->sd); @@ -474,6 +478,7 @@ core_accept(struct conn *c) break; } +#if !(HAVE_ACCEPT4) status = mc_set_nonblocking(sd); if (status != MC_OK) { log_error("set nonblock on c %d from s %d failed: %s", sd, c->sd, @@ -481,6 +486,7 @@ core_accept(struct conn *c) close(sd); return; } +#endif status = mc_set_keepalive(sd); if (status != MC_OK) {