diff --git a/moo/configure b/moo/configure index 2dbd9b6..50e7c82 100755 --- a/moo/configure +++ b/moo/configure @@ -21047,7 +21047,6 @@ cat >>confdefs.h <<_ACEOF _ACEOF - if test ${ac_cv_sizeof_socklen_t} -gt 0 then @@ -21085,6 +21084,85 @@ $as_echo "$ac_res" >&6; } $as_echo "#define MOO_SOCKLEN_T_IS_SIGNED 1" >>confdefs.h + elif eval "test \"\${ax_cv_decl_${typename}_signed}\" = \"no\""; then + $as_echo_n "" + fi + + fi + + # The cast to long int works around a bug in the HP C Compiler +# version HP92453-01 B.11.11.23709.GP, which incorrectly rejects +# declarations like `int a3[[(sizeof (unsigned char)) >= 0]];'. +# This bug is HP SR number 8606223364. +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking size of sa_family_t" >&5 +$as_echo_n "checking size of sa_family_t... " >&6; } +if ${ac_cv_sizeof_sa_family_t+:} false; then : + $as_echo_n "(cached) " >&6 +else + if ac_fn_c_compute_int "$LINENO" "(long int) (sizeof (sa_family_t))" "ac_cv_sizeof_sa_family_t" " + #include + #include +"; then : + +else + if test "$ac_cv_type_sa_family_t" = yes; then + { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} +as_fn_error 77 "cannot compute sizeof (sa_family_t) +See \`config.log' for more details" "$LINENO" 5; } + else + ac_cv_sizeof_sa_family_t=0 + fi +fi + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_sizeof_sa_family_t" >&5 +$as_echo "$ac_cv_sizeof_sa_family_t" >&6; } + + + +cat >>confdefs.h <<_ACEOF +#define SIZEOF_SA_FAMILY_T $ac_cv_sizeof_sa_family_t +_ACEOF + + + if test ${ac_cv_sizeof_sa_family_t} -gt 0 + then + + typename=`echo sa_family_t | sed "s/[^a-zA-Z0-9_]/_/g"` + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether sa_family_t is signed" >&5 +$as_echo_n "checking whether sa_family_t is signed... " >&6; } +if eval \${ax_cv_decl_${typename}_signed+:} false; then : + $as_echo_n "(cached) " >&6 +else + + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include + #include +int +main () +{ + int foo [ 1 - 2 * !(((sa_family_t) -1) < 0) ] + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + eval "ax_cv_decl_${typename}_signed=\"yes\"" +else + eval "ax_cv_decl_${typename}_signed=\"no\"" +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi +eval ac_res=\$ax_cv_decl_${typename}_signed + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +$as_echo "$ac_res" >&6; } + symbolname=`echo sa_family_t | sed "s/[^a-zA-Z0-9_]/_/g" | tr "a-z" "A-Z"` + if eval "test \"\${ax_cv_decl_${typename}_signed}\" = \"yes\""; then + +$as_echo "#define MOO_SA_FAMILY_T_IS_SIGNED 1" >>confdefs.h + elif eval "test \"\${ax_cv_decl_${typename}_signed}\" = \"no\""; then $as_echo_n "" fi @@ -21272,6 +21350,8 @@ cat >>confdefs.h <<_ACEOF _ACEOF + + # The cast to long int works around a bug in the HP C Compiler # version HP92453-01 B.11.11.23709.GP, which incorrectly rejects # declarations like `int a3[[(sizeof (unsigned char)) >= 0]];'. @@ -21281,9 +21361,7 @@ $as_echo_n "checking size of socklen_t... " >&6; } if ${ac_cv_sizeof_socklen_t+:} false; then : $as_echo_n "(cached) " >&6 else - if ac_fn_c_compute_int "$LINENO" "(long int) (sizeof (socklen_t))" "ac_cv_sizeof_socklen_t" " - #include - #include + if ac_fn_c_compute_int "$LINENO" "(long int) (sizeof (socklen_t))" "ac_cv_sizeof_socklen_t" "#include "; then : else @@ -21308,7 +21386,6 @@ cat >>confdefs.h <<_ACEOF _ACEOF - if test ${ac_cv_sizeof_socklen_t} -gt 0 then @@ -21345,6 +21422,84 @@ $as_echo "$ac_res" >&6; } $as_echo "#define MOO_SOCKLEN_T_IS_SIGNED 1" >>confdefs.h + elif eval "test \"\${ax_cv_decl_${typename}_signed}\" = \"no\""; then + $as_echo_n "" + fi + + fi + + # The cast to long int works around a bug in the HP C Compiler +# version HP92453-01 B.11.11.23709.GP, which incorrectly rejects +# declarations like `int a3[[(sizeof (unsigned char)) >= 0]];'. +# This bug is HP SR number 8606223364. +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking size of sa_family_t" >&5 +$as_echo_n "checking size of sa_family_t... " >&6; } +if ${ac_cv_sizeof_sa_family_t+:} false; then : + $as_echo_n "(cached) " >&6 +else + if ac_fn_c_compute_int "$LINENO" "(long int) (sizeof (sa_family_t))" "ac_cv_sizeof_sa_family_t" " + #include + #include +"; then : + +else + if test "$ac_cv_type_sa_family_t" = yes; then + { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} +as_fn_error 77 "cannot compute sizeof (sa_family_t) +See \`config.log' for more details" "$LINENO" 5; } + else + ac_cv_sizeof_sa_family_t=0 + fi +fi + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_sizeof_sa_family_t" >&5 +$as_echo "$ac_cv_sizeof_sa_family_t" >&6; } + + + +cat >>confdefs.h <<_ACEOF +#define SIZEOF_SA_FAMILY_T $ac_cv_sizeof_sa_family_t +_ACEOF + + + if test ${ac_cv_sizeof_sa_family_t} -gt 0 + then + + typename=`echo sa_family_t | sed "s/[^a-zA-Z0-9_]/_/g"` + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether sa_family_t is signed" >&5 +$as_echo_n "checking whether sa_family_t is signed... " >&6; } +if eval \${ax_cv_decl_${typename}_signed+:} false; then : + $as_echo_n "(cached) " >&6 +else + + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +int +main () +{ + int foo [ 1 - 2 * !(((sa_family_t) -1) < 0) ] + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + eval "ax_cv_decl_${typename}_signed=\"yes\"" +else + eval "ax_cv_decl_${typename}_signed=\"no\"" +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi +eval ac_res=\$ax_cv_decl_${typename}_signed + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +$as_echo "$ac_res" >&6; } + symbolname=`echo sa_family_t | sed "s/[^a-zA-Z0-9_]/_/g" | tr "a-z" "A-Z"` + if eval "test \"\${ax_cv_decl_${typename}_signed}\" = \"yes\""; then + +$as_echo "#define MOO_SA_FAMILY_T_IS_SIGNED 1" >>confdefs.h + elif eval "test \"\${ax_cv_decl_${typename}_signed}\" = \"no\""; then $as_echo_n "" fi @@ -21687,6 +21842,16 @@ _ACEOF +cat >>confdefs.h <<_ACEOF +#define MOO_SIZEOF_SOCKLEN_T ${ac_cv_sizeof_socklen_t} +_ACEOF + + +cat >>confdefs.h <<_ACEOF +#define MOO_SIZEOF_SA_FAMILY_T ${ac_cv_sizeof_sa_family_t} +_ACEOF + + moo_package_version_major="`echo ${PACKAGE_VERSION} | cut -d. -f1`" moo_package_version_minor="`echo ${PACKAGE_VERSION} | cut -d. -f2`" moo_package_version_patch="`echo ${PACKAGE_VERSION} | cut -d. -f3`" diff --git a/moo/configure.ac b/moo/configure.ac index ed4b004..98d38ee 100644 --- a/moo/configure.ac +++ b/moo/configure.ac @@ -304,7 +304,6 @@ then AC_CHECK_SIZEOF(socklen_t,, [ #include #include ]) - if test ${ac_cv_sizeof_socklen_t} -gt 0 then AX_CHECK_SIGN([socklen_t], @@ -313,6 +312,18 @@ then [#include #include ]) fi + + AC_CHECK_SIZEOF(sa_family_t,, [ + #include + #include ]) + if test ${ac_cv_sizeof_sa_family_t} -gt 0 + then + AX_CHECK_SIGN([sa_family_t], + [ AC_DEFINE(MOO_SA_FAMILY_T_IS_SIGNED, 1, [Define if sa_family_t is signed]) ], + [ AS_ECHO_N("") ], + [#include + #include ]) + fi else AC_CHECK_SIZEOF(struct sockaddr_in,,[ #include @@ -330,10 +341,9 @@ else #include #include #include ]) - AC_CHECK_SIZEOF(socklen_t,, [ - #include - #include ]) + + AC_CHECK_SIZEOF(socklen_t,, [#include ]) if test ${ac_cv_sizeof_socklen_t} -gt 0 then AX_CHECK_SIGN([socklen_t], @@ -341,6 +351,17 @@ else [ AS_ECHO_N("") ], [#include ]) fi + + AC_CHECK_SIZEOF(sa_family_t,, [ + #include + #include ]) + if test ${ac_cv_sizeof_sa_family_t} -gt 0 + then + AX_CHECK_SIGN([sa_family_t], + [ AC_DEFINE(MOO_SA_FAMILY_T_IS_SIGNED, 1, [Define if sa_family_t is signed]) ], + [ AS_ECHO_N("") ], + [#include ]) + fi fi dnl gcc 3.4.3 on opensolaris x86 gave this warning without -msse or @@ -476,6 +497,8 @@ AC_DEFINE_UNQUOTED(MOO_SIZEOF_STRUCT_SOCKADDR_LL, ${ac_cv_sizeof_struct_sockaddr AC_DEFINE_UNQUOTED(MOO_SIZEOF_STRUCT_SOCKADDR_UN, ${ac_cv_sizeof_struct_sockaddr_un}, [sizeof(struct sockaddr_un)]) AC_DEFINE_UNQUOTED(MOO_SIZEOF_STRUCT_SOCKADDR_DL, ${ac_cv_sizeof_struct_sockaddr_dl}, [sizeof(struct sockaddr_dl)]) +AC_DEFINE_UNQUOTED(MOO_SIZEOF_SOCKLEN_T, ${ac_cv_sizeof_socklen_t}, [sizeof(socklen_t)]) +AC_DEFINE_UNQUOTED(MOO_SIZEOF_SA_FAMILY_T, ${ac_cv_sizeof_sa_family_t}, [sizeof(sa_family_t)]) moo_package_version_major="`echo ${PACKAGE_VERSION} | cut -d. -f1`" moo_package_version_minor="`echo ${PACKAGE_VERSION} | cut -d. -f2`" diff --git a/moo/lib/moo-cfg.h.in b/moo/lib/moo-cfg.h.in index 63debf3..1db8551 100644 --- a/moo/lib/moo-cfg.h.in +++ b/moo/lib/moo-cfg.h.in @@ -413,6 +413,9 @@ /* Patch level */ #undef MOO_PACKAGE_VERSION_PATCH +/* Define if sa_family_t is signed */ +#undef MOO_SA_FAMILY_T_IS_SIGNED + /* sizeof(char) */ #undef MOO_SIZEOF_CHAR @@ -443,9 +446,15 @@ /* sizeof(off_t) */ #undef MOO_SIZEOF_OFF_T +/* sizeof(sa_family_t) */ +#undef MOO_SIZEOF_SA_FAMILY_T + /* sizeof(short) */ #undef MOO_SIZEOF_SHORT +/* sizeof(socklen_t) */ +#undef MOO_SIZEOF_SOCKLEN_T + /* sizeof(struct sockaddr_dl) */ #undef MOO_SIZEOF_STRUCT_SOCKADDR_DL @@ -555,6 +564,9 @@ /* The size of `off_t', as computed by sizeof. */ #undef SIZEOF_OFF_T +/* The size of `sa_family_t', as computed by sizeof. */ +#undef SIZEOF_SA_FAMILY_T + /* The size of `short', as computed by sizeof. */ #undef SIZEOF_SHORT diff --git a/moo/mod/_sck.h b/moo/mod/_sck.h index 00a228f..b1dfd78 100644 --- a/moo/mod/_sck.h +++ b/moo/mod/_sck.h @@ -38,6 +38,76 @@ struct sck_t /* there are more fields in the actual object */ }; +#if (MOO_SIZEOF_SOCKLEN_T > 0) +//#error x +#endif + +#if (MOO_SIZEOF_INT8_T > 0) +#error x +#endif + +#if (MOO_SIZEOF_SOCKLEN_T == 1) + #if defined(MOO_SOCKLEN_T_IS_SIGNED) + typedef moo_int8_t sck_len_t; + #else + typedef moo_uint8_t sck_len_t; + #endif +#elif (MOO_SIZEOF_SOCKLEN_T == 2) + #if defined(MOO_SOCKLEN_T_IS_SIGNED) + typedef moo_int16_t sck_len_t; + #else + typedef moo_uint16_t sck_len_t; + #endif +#elif (MOO_SIZEOF_SOCKLEN_T == 4) + #if defined(MOO_SOCKLEN_T_IS_SIGNED) + typedef moo_int32_t sck_len_t; + #else + typedef moo_uint32_t sck_len_t; + #endif +#elif (MOO_SIZEOF_SOCKLEN_T == 8) + #if defined(MOO_SOCKLEN_T_IS_SIGNED) + typedef moo_int64_t sck_len_t; + #else + typedef moo_uint64_t sck_len_t; + #endif +#else +# error UNSUPPORT sck_len_t size +#endif + +#if (MOO_SIZEOF_SA_FAMILY_T == 1) + #if defined(MOO_SA_FAMILY_T_IS_SIGNED) + typedef moo_int8_t sck_addr_family_t; + #else + typedef moo_uint8_t sck_addr_family_t; + #endif +#elif (MOO_SIZEOF_SA_FAMILY_T == 2) + #if defined(MOO_SA_FAMILY_T_IS_SIGNED) + typedef moo_int16_t sck_addr_family_t; + #else + typedef moo_uint16_t sck_addr_family_t; + #endif +#elif (MOO_SIZEOF_SA_FAMILY_T == 4) + #if defined(MOO_SA_FAMILY_T_IS_SIGNED) + typedef moo_int32_t sck_addr_family_t; + #else + typedef moo_uint32_t sck_addr_family_t; + #endif +#elif (MOO_SIZEOF_SA_FAMILY_T == 8) + #if defined(MOO_SA_FAMILY_T_IS_SIGNED) + typedef moo_int64_t sck_addr_family_t; + #else + typedef moo_uint64_t sck_addr_family_t; + #endif +#else +# error UNSUPPORT sck_addr_family_t size +#endif + +struct sck_addr_t +{ + sck_addr_family_t family; + moo_uint8_t data[1]; +}; +typedef struct sck_addr_t sck_addr_t; #if defined(__cplusplus) extern "C" { diff --git a/moo/mod/sck-addr.c b/moo/mod/sck-addr.c index 1648f1d..0197b1c 100644 --- a/moo/mod/sck-addr.c +++ b/moo/mod/sck-addr.c @@ -400,7 +400,7 @@ TODO: moo_seterrbfmt (moo, MOO_EINVAL, "scope id too large"); return -1; /* overflow */ } - nwad->in6.sin6_scope_id= x; + nwad->in6.sin6_scope_id = x; p++; } while (p < end && *p >= '0' && *p <= '9'); diff --git a/moo/mod/sck.c b/moo/mod/sck.c index 1d335bf..50d27b6 100644 --- a/moo/mod/sck.c +++ b/moo/mod/sck.c @@ -143,31 +143,28 @@ static moo_pfrc_t pf_connect (moo_t* moo, moo_ooi_t nargs) oop_sck_t sck; int fd, oldfl, n; moo_errnum_t errnum; + moo_oop_t arg; sck = (oop_sck_t)MOO_STACK_GETRCV(moo, nargs); + arg = MOO_STACK_GETARG(moo, nargs, 1); + MOO_PF_CHECK_RCV (moo, MOO_OOP_IS_POINTER(sck) && MOO_OBJ_BYTESOF(sck) >= (MOO_SIZEOF(*sck) - MOO_SIZEOF(moo_obj_t)) && MOO_OOP_IS_SMOOI(sck->handle)); + MOO_PF_CHECK_ARGS (moo, nargs, MOO_OBJ_IS_BYTE_POINTER(arg)); fd = MOO_OOP_TO_SMOOI(sck->handle); oldfl = fcntl(fd, F_GETFL, 0); if (oldfl == -1 || fcntl(fd, F_SETFL, oldfl | O_NONBLOCK) == -1) goto oops_syserr; -{ - -struct sockaddr_in sin; -memset (&sin, 0, sizeof(sin)); -sin.sin_family = AF_INET; -sin.sin_addr.s_addr = inet_addr ("192.168.1.145"); -sin.sin_port = htons(12345); do { - n = connect(fd, (struct sockaddr*)&sin, sizeof(sin)); + //n = connect(fd, (struct sockaddr*)MOO_OBJ_GET_BYTE_SLOT(arg), addrlen); } while (n == -1 && errno == EINTR); -} + if (n == -1 && errno != EINPROGRESS) {