diff --git a/moo/configure b/moo/configure index 50e7c82..3ee3c21 100755 --- a/moo/configure +++ b/moo/configure @@ -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; } diff --git a/moo/configure.ac b/moo/configure.ac index 98d38ee..4404a4b 100644 --- a/moo/configure.ac +++ b/moo/configure.ac @@ -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], [ diff --git a/moo/kernel/Socket.moo b/moo/kernel/Socket.moo index c4210ee..74f12ce 100644 --- a/moo/kernel/Socket.moo +++ b/moo/kernel/Socket.moo @@ -457,6 +457,8 @@ error -> exception (n asString & ' bytes read') dump. data dump. }. + + sck writeBytes: #[ $h, $e, $l, $l, $o, $., $., $., C'\n' ]. } while (true). ]. diff --git a/moo/lib/moo-cfg.h.in b/moo/lib/moo-cfg.h.in index 1db8551..5f9916b 100644 --- a/moo/lib/moo-cfg.h.in +++ b/moo/lib/moo-cfg.h.in @@ -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 diff --git a/moo/mod/sck.c b/moo/mod/sck.c index 6e132b0..b0aa2c5 100644 --- a/moo/mod/sck.c +++ b/moo/mod/sck.c @@ -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);