Skip to content
This repository has been archived by the owner on Nov 2, 2021. It is now read-only.

Add linux accept4() support #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -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], [],
Expand Down
6 changes: 6 additions & 0 deletions src/mc_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -474,13 +478,15 @@ 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,
strerror(errno));
close(sd);
return;
}
#endif

status = mc_set_keepalive(sd);
if (status != MC_OK) {
Expand Down