made an accepted socket non-block

This commit is contained in:
hyunghwan.chung 2018-01-14 15:38:06 +00:00
parent 2255425b3f
commit 8eae9095c1
5 changed files with 28 additions and 1 deletions

11
moo/configure vendored
View File

@ -19654,6 +19654,17 @@ _ACEOF
fi
done
for ac_func in accept4
do :
ac_fn_c_check_func "$LINENO" "accept4" "ac_cv_func_accept4"
if test "x$ac_cv_func_accept4" = xyes; then :
cat >>confdefs.h <<_ACEOF
#define HAVE_ACCEPT4 1
_ACEOF
fi
done
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for dcNewCallVM in -ldyncall_s" >&5
$as_echo_n "checking for dcNewCallVM in -ldyncall_s... " >&6; }

View File

@ -172,6 +172,7 @@ AC_CHECK_FUNCS([gettimeofday settimeofday clock_gettime clock_settime getitimer
AC_CHECK_FUNCS([backtrace backtrace_symbols])
AC_CHECK_FUNCS([makecontext swapcontext getcontext setcontext])
AC_CHECK_FUNCS([snprintf _vsnprintf _vsnwprintf])
AC_CHECK_FUNCS([accept4])
AC_CHECK_LIB([dyncall_s], [dcNewCallVM],
[

View File

@ -457,6 +457,8 @@ error -> exception
(n asString & ' bytes read') dump.
data dump.
}.
sck writeBytes: #[ $h, $e, $l, $l, $o, $., $., $., C'\n' ].
}
while (true).
].

View File

@ -3,6 +3,9 @@
/* Define if building universal (internal helper macro) */
#undef AC_APPLE_UNIVERSAL_BUILD
/* Define to 1 if you have the `accept4' function. */
#undef HAVE_ACCEPT4
/* Define to 1 if you have the `acosq' function. */
#undef HAVE_ACOSQ

View File

@ -150,7 +150,7 @@ static moo_pfrc_t pf_accept_socket (moo_t* moo, moo_ooi_t nargs)
oop_sck_t sck, newsck;
moo_oop_t arg;
sck_len_t addrlen;
int fd, newfd;
int fd, newfd, oldfl;
sck = (oop_sck_t)MOO_STACK_GETRCV(moo, nargs);
arg = MOO_STACK_GETARG(moo, nargs, 0);
@ -169,7 +169,17 @@ static moo_pfrc_t pf_accept_socket (moo_t* moo, moo_ooi_t nargs)
}
addrlen = MOO_OBJ_GET_SIZE(arg);
#if defined(SOCK_NONBLOCK) && defined(SOCK_CLOEXEC) && defined(HAVE_ACCEPT4)
newfd = accept4(fd, (struct sockaddr*)MOO_OBJ_GET_BYTE_SLOT(arg), &addrlen, SOCK_NONBLOCK | SOCK_CLOEXEC);
#else
oldfl = fcntl(fd, F_GETFL, 0);
if (oldfl == -1 || fcntl(fd, F_SETFL, oldfl | O_NONBLOCK | O_CLOEXEC) == -1)
{
moo_seterrwithsyserr (moo, errno);
return MOO_PF_FAILURE;
}
newfd = accept(fd, (struct sockaddr*)MOO_OBJ_GET_BYTE_SLOT(arg), &addrlen);
#endif
if (newfd == -1)
{
moo_seterrwithsyserr (moo, errno);