touched up code for renewal
This commit is contained in:
parent
27695e69cd
commit
b30bbf8063
12
mio/configure
vendored
12
mio/configure
vendored
@ -17940,6 +17940,18 @@ _ACEOF
|
|||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
for ac_func in accept4 sendmsg recvmsg writev readv
|
||||||
|
do :
|
||||||
|
as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
|
||||||
|
ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
|
||||||
|
if eval test \"x\$"$as_ac_var"\" = x"yes"; then :
|
||||||
|
cat >>confdefs.h <<_ACEOF
|
||||||
|
#define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1
|
||||||
|
_ACEOF
|
||||||
|
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
|
||||||
OLDLIBS="$LIBS"
|
OLDLIBS="$LIBS"
|
||||||
LIBS="$LIBM $LIBS"
|
LIBS="$LIBM $LIBS"
|
||||||
|
@ -160,6 +160,7 @@ AC_CHECK_FUNCS([backtrace backtrace_symbols])
|
|||||||
AC_CHECK_FUNCS([fork vfork posix_spawn gettid nanosleep select])
|
AC_CHECK_FUNCS([fork vfork posix_spawn gettid nanosleep select])
|
||||||
AC_CHECK_FUNCS([makecontext swapcontext getcontext setcontext])
|
AC_CHECK_FUNCS([makecontext swapcontext getcontext setcontext])
|
||||||
AC_CHECK_FUNCS([snprintf _vsnprintf _vsnwprintf])
|
AC_CHECK_FUNCS([snprintf _vsnprintf _vsnwprintf])
|
||||||
|
AC_CHECK_FUNCS([accept4 sendmsg recvmsg writev readv])
|
||||||
|
|
||||||
OLDLIBS="$LIBS"
|
OLDLIBS="$LIBS"
|
||||||
LIBS="$LIBM $LIBS"
|
LIBS="$LIBM $LIBS"
|
||||||
|
@ -44,7 +44,7 @@ bin_PROGRAMS = mio
|
|||||||
mio_SOURCES = main.c
|
mio_SOURCES = main.c
|
||||||
mio_CPPFLAGS = $(CPPFLAGS_LIB_COMMON)
|
mio_CPPFLAGS = $(CPPFLAGS_LIB_COMMON)
|
||||||
mio_LDFLAGS = $(LDFLAGS_LIB_COMMON)
|
mio_LDFLAGS = $(LDFLAGS_LIB_COMMON)
|
||||||
mio_LDADD = $(LIBADD_LIB_COMMON) -lmio
|
mio_LDADD = $(LIBADD_LIB_COMMON) -lmio $(SSL_LIBS)
|
||||||
|
|
||||||
install-data-hook:
|
install-data-hook:
|
||||||
@echo "#ifndef _MIO_CFG_H_" > "$(DESTDIR)$(includedir)/mio-cfg.h"
|
@echo "#ifndef _MIO_CFG_H_" > "$(DESTDIR)$(includedir)/mio-cfg.h"
|
||||||
|
@ -154,7 +154,7 @@ libmio_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
|
|||||||
PROGRAMS = $(bin_PROGRAMS)
|
PROGRAMS = $(bin_PROGRAMS)
|
||||||
am_mio_OBJECTS = mio-main.$(OBJEXT)
|
am_mio_OBJECTS = mio-main.$(OBJEXT)
|
||||||
mio_OBJECTS = $(am_mio_OBJECTS)
|
mio_OBJECTS = $(am_mio_OBJECTS)
|
||||||
mio_DEPENDENCIES = $(am__DEPENDENCIES_2)
|
mio_DEPENDENCIES = $(am__DEPENDENCIES_2) $(am__DEPENDENCIES_1)
|
||||||
mio_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
|
mio_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
|
||||||
$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
|
$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
|
||||||
$(mio_LDFLAGS) $(LDFLAGS) -o $@
|
$(mio_LDFLAGS) $(LDFLAGS) -o $@
|
||||||
@ -411,7 +411,7 @@ libmio_la_LIBADD = $(LIBADD_LIB_COMMON) $(SSL_LIBS)
|
|||||||
mio_SOURCES = main.c
|
mio_SOURCES = main.c
|
||||||
mio_CPPFLAGS = $(CPPFLAGS_LIB_COMMON)
|
mio_CPPFLAGS = $(CPPFLAGS_LIB_COMMON)
|
||||||
mio_LDFLAGS = $(LDFLAGS_LIB_COMMON)
|
mio_LDFLAGS = $(LDFLAGS_LIB_COMMON)
|
||||||
mio_LDADD = $(LIBADD_LIB_COMMON) -lmio
|
mio_LDADD = $(LIBADD_LIB_COMMON) -lmio $(SSL_LIBS)
|
||||||
all: mio-cfg.h
|
all: mio-cfg.h
|
||||||
$(MAKE) $(AM_MAKEFLAGS) all-am
|
$(MAKE) $(AM_MAKEFLAGS) all-am
|
||||||
|
|
||||||
|
@ -299,6 +299,11 @@ static int arp_sck_on_write (mio_dev_sck_t* dev, mio_iolen_t wrlen, void* wrctx,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void arp_sck_on_connect (mio_dev_sck_t* dev)
|
||||||
|
{
|
||||||
|
printf ("STARTING UP ARP SOCKET %d...\n", dev->sck);
|
||||||
|
}
|
||||||
|
|
||||||
static void arp_sck_on_disconnect (mio_dev_sck_t* dev)
|
static void arp_sck_on_disconnect (mio_dev_sck_t* dev)
|
||||||
{
|
{
|
||||||
printf ("SHUTTING DOWN ARP SOCKET %d...\n", dev->sck);
|
printf ("SHUTTING DOWN ARP SOCKET %d...\n", dev->sck);
|
||||||
@ -316,6 +321,7 @@ static int setup_arp_tester (mio_t* mio)
|
|||||||
//sck_make.type = MIO_DEV_SCK_ARP_DGRAM;
|
//sck_make.type = MIO_DEV_SCK_ARP_DGRAM;
|
||||||
sck_make.on_write = arp_sck_on_write;
|
sck_make.on_write = arp_sck_on_write;
|
||||||
sck_make.on_read = arp_sck_on_read;
|
sck_make.on_read = arp_sck_on_read;
|
||||||
|
sck_make.on_connect = arp_sck_on_connect;
|
||||||
sck_make.on_disconnect = arp_sck_on_disconnect;
|
sck_make.on_disconnect = arp_sck_on_disconnect;
|
||||||
sck = mio_dev_sck_make (mio, 0, &sck_make);
|
sck = mio_dev_sck_make (mio, 0, &sck_make);
|
||||||
if (!sck)
|
if (!sck)
|
||||||
@ -325,7 +331,9 @@ static int setup_arp_tester (mio_t* mio)
|
|||||||
}
|
}
|
||||||
|
|
||||||
//mio_sckaddr_initforeth (ðdst, if_nametoindex("enp0s25.3"), (mio_ethaddr_t*)"\xFF\xFF\xFF\xFF\xFF\xFF");
|
//mio_sckaddr_initforeth (ðdst, if_nametoindex("enp0s25.3"), (mio_ethaddr_t*)"\xFF\xFF\xFF\xFF\xFF\xFF");
|
||||||
mio_sckaddr_initforeth (ðdst, if_nametoindex("enp0s25.3"), (mio_ethaddr_t*)"\xAA\xBB\xFF\xCC\xDD\xFF");
|
//mio_sckaddr_initforeth (ðdst, if_nametoindex("enp0s25.3"), (mio_ethaddr_t*)"\xAA\xBB\xFF\xCC\xDD\xFF");
|
||||||
|
|
||||||
|
mio_sckaddr_initforeth (ðdst, if_nametoindex("wlan0"), (mio_ethaddr_t*)"\xAA\xBB\xFF\xCC\xDD\xFF");
|
||||||
|
|
||||||
memset (ðarp, 0, sizeof(etharp));
|
memset (ðarp, 0, sizeof(etharp));
|
||||||
|
|
||||||
@ -542,7 +550,7 @@ static void handle_signal (int sig)
|
|||||||
if (g_mio) mio_stop (g_mio, MIO_STOPREQ_TERMINATION);
|
if (g_mio) mio_stop (g_mio, MIO_STOPREQ_TERMINATION);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main ()
|
int main (int argc, char* argv[])
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
@ -602,6 +610,7 @@ int main ()
|
|||||||
tcp_make.type = MIO_DEV_SCK_TCP4;
|
tcp_make.type = MIO_DEV_SCK_TCP4;
|
||||||
tcp_make.on_write = tcp_sck_on_write;
|
tcp_make.on_write = tcp_sck_on_write;
|
||||||
tcp_make.on_read = tcp_sck_on_read;
|
tcp_make.on_read = tcp_sck_on_read;
|
||||||
|
tcp_make.on_connect = tcp_sck_on_connect;
|
||||||
tcp_make.on_disconnect = tcp_sck_on_disconnect;
|
tcp_make.on_disconnect = tcp_sck_on_disconnect;
|
||||||
tcp[0] = mio_dev_sck_make(mio, MIO_SIZEOF(tcp_server_t), &tcp_make);
|
tcp[0] = mio_dev_sck_make(mio, MIO_SIZEOF(tcp_server_t), &tcp_make);
|
||||||
if (!tcp[0])
|
if (!tcp[0])
|
||||||
@ -621,7 +630,6 @@ int main ()
|
|||||||
}
|
}
|
||||||
|
|
||||||
mio_inittime (&tcp_conn.connect_tmout, 5, 0);
|
mio_inittime (&tcp_conn.connect_tmout, 5, 0);
|
||||||
tcp_conn.on_connect = tcp_sck_on_connect;
|
|
||||||
tcp_conn.options = MIO_DEV_SCK_CONNECT_SSL;
|
tcp_conn.options = MIO_DEV_SCK_CONNECT_SSL;
|
||||||
if (mio_dev_sck_connect (tcp[0], &tcp_conn) <= -1)
|
if (mio_dev_sck_connect (tcp[0], &tcp_conn) <= -1)
|
||||||
{
|
{
|
||||||
@ -634,6 +642,7 @@ int main ()
|
|||||||
tcp_make.type = MIO_DEV_SCK_TCP4;
|
tcp_make.type = MIO_DEV_SCK_TCP4;
|
||||||
tcp_make.on_write = tcp_sck_on_write;
|
tcp_make.on_write = tcp_sck_on_write;
|
||||||
tcp_make.on_read = tcp_sck_on_read;
|
tcp_make.on_read = tcp_sck_on_read;
|
||||||
|
tcp_make.on_connect = tcp_sck_on_connect;
|
||||||
tcp_make.on_disconnect = tcp_sck_on_disconnect;
|
tcp_make.on_disconnect = tcp_sck_on_disconnect;
|
||||||
|
|
||||||
tcp[1] = mio_dev_sck_make(mio, MIO_SIZEOF(tcp_server_t), &tcp_make);
|
tcp[1] = mio_dev_sck_make(mio, MIO_SIZEOF(tcp_server_t), &tcp_make);
|
||||||
@ -651,16 +660,15 @@ int main ()
|
|||||||
|
|
||||||
if (mio_dev_sck_bind (tcp[1],&tcp_bind) <= -1)
|
if (mio_dev_sck_bind (tcp[1],&tcp_bind) <= -1)
|
||||||
{
|
{
|
||||||
printf ("mio_dev_sck_bind() failed....\n");
|
printf ("tcp[1] mio_dev_sck_bind() failed....\n");
|
||||||
goto oops;
|
goto oops;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
tcp_lstn.backlogs = 100;
|
tcp_lstn.backlogs = 100;
|
||||||
tcp_lstn.on_connect = tcp_sck_on_connect;
|
|
||||||
if (mio_dev_sck_listen (tcp[1], &tcp_lstn) <= -1)
|
if (mio_dev_sck_listen (tcp[1], &tcp_lstn) <= -1)
|
||||||
{
|
{
|
||||||
printf ("mio_dev_sck_listen() failed....\n");
|
printf ("tcp[1] mio_dev_sck_listen() failed....\n");
|
||||||
goto oops;
|
goto oops;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -669,6 +677,7 @@ int main ()
|
|||||||
tcp_make.type = MIO_DEV_SCK_TCP4;
|
tcp_make.type = MIO_DEV_SCK_TCP4;
|
||||||
tcp_make.on_write = tcp_sck_on_write;
|
tcp_make.on_write = tcp_sck_on_write;
|
||||||
tcp_make.on_read = tcp_sck_on_read;
|
tcp_make.on_read = tcp_sck_on_read;
|
||||||
|
tcp_make.on_connect = tcp_sck_on_connect;
|
||||||
tcp_make.on_disconnect = tcp_sck_on_disconnect;
|
tcp_make.on_disconnect = tcp_sck_on_disconnect;
|
||||||
|
|
||||||
tcp[2] = mio_dev_sck_make (mio, MIO_SIZEOF(tcp_server_t), &tcp_make);
|
tcp[2] = mio_dev_sck_make (mio, MIO_SIZEOF(tcp_server_t), &tcp_make);
|
||||||
@ -689,15 +698,14 @@ int main ()
|
|||||||
|
|
||||||
if (mio_dev_sck_bind(tcp[2], &tcp_bind) <= -1)
|
if (mio_dev_sck_bind(tcp[2], &tcp_bind) <= -1)
|
||||||
{
|
{
|
||||||
printf ("mio_dev_sck_bind() failed....\n");
|
printf ("tcp[2] mio_dev_sck_bind() failed....\n");
|
||||||
goto oops;
|
goto oops;
|
||||||
}
|
}
|
||||||
|
|
||||||
tcp_lstn.backlogs = 100;
|
tcp_lstn.backlogs = 100;
|
||||||
tcp_lstn.on_connect = tcp_sck_on_connect;
|
|
||||||
if (mio_dev_sck_listen(tcp[2], &tcp_lstn) <= -1)
|
if (mio_dev_sck_listen(tcp[2], &tcp_lstn) <= -1)
|
||||||
{
|
{
|
||||||
printf ("mio_dev_sck_listen() failed....\n");
|
printf ("tcp[2] mio_dev_sck_listen() failed....\n");
|
||||||
goto oops;
|
goto oops;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -706,7 +714,6 @@ int main ()
|
|||||||
if (setup_arp_tester(mio) <= -1) goto oops;
|
if (setup_arp_tester(mio) <= -1) goto oops;
|
||||||
if (setup_ping4_tester(mio) <= -1) goto oops;
|
if (setup_ping4_tester(mio) <= -1) goto oops;
|
||||||
|
|
||||||
|
|
||||||
for (i = 0; i < 5; i++)
|
for (i = 0; i < 5; i++)
|
||||||
{
|
{
|
||||||
mio_dev_pro_t* pro;
|
mio_dev_pro_t* pro;
|
||||||
@ -753,3 +760,47 @@ oops:
|
|||||||
#endif
|
#endif
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
int main (int argc, char* argv[])
|
||||||
|
{
|
||||||
|
mio_t* mio = MIO_NULL;
|
||||||
|
mio_dev_sck_t* tcpsvr;
|
||||||
|
|
||||||
|
mio = mio_open (&mmgr, 0, 512, MIO_NULL);
|
||||||
|
if (!mio)
|
||||||
|
{
|
||||||
|
printf ("Cannot open mio\n");
|
||||||
|
goto oops;
|
||||||
|
}
|
||||||
|
|
||||||
|
memset (&tcp_make, 0, MIO_SIZEOF(&tcp_make));
|
||||||
|
tcp_make.type = MIO_DEV_SCK_TCP4;
|
||||||
|
tcp_make.on_write = tcp_sck_on_write;
|
||||||
|
tcp_make.on_read = tcp_sck_on_read;
|
||||||
|
tcp_make.on_connect = tcp_sck_on_connect;
|
||||||
|
tcp_make.on_disconnect = tcp_sck_on_disconnect;
|
||||||
|
tcpsvr = mio_dev_sck_make(mio, MIO_SIZEOF(tcp_server_t), &tcp_make);
|
||||||
|
if (!tcpsvr)
|
||||||
|
{
|
||||||
|
printf ("Cannot make a tcp server\n");
|
||||||
|
goto oops;
|
||||||
|
}
|
||||||
|
|
||||||
|
ts = (tcp_server_t*)(tcpsvr + 1);
|
||||||
|
ts->tally = 0;
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
mio_exec (mio);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
mio_loop (mio);
|
||||||
|
|
||||||
|
oops:
|
||||||
|
if (mio) mio_close (mio);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
@ -3,6 +3,9 @@
|
|||||||
/* Define if building universal (internal helper macro) */
|
/* Define if building universal (internal helper macro) */
|
||||||
#undef AC_APPLE_UNIVERSAL_BUILD
|
#undef AC_APPLE_UNIVERSAL_BUILD
|
||||||
|
|
||||||
|
/* Define to 1 if you have the `accept4' function. */
|
||||||
|
#undef HAVE_ACCEPT4
|
||||||
|
|
||||||
/* Define to 1 if you have the `acos' function. */
|
/* Define to 1 if you have the `acos' function. */
|
||||||
#undef HAVE_ACOS
|
#undef HAVE_ACOS
|
||||||
|
|
||||||
@ -385,6 +388,12 @@
|
|||||||
/* Define to 1 if you have the `readdir64' function. */
|
/* Define to 1 if you have the `readdir64' function. */
|
||||||
#undef HAVE_READDIR64
|
#undef HAVE_READDIR64
|
||||||
|
|
||||||
|
/* Define to 1 if you have the `readv' function. */
|
||||||
|
#undef HAVE_READV
|
||||||
|
|
||||||
|
/* Define to 1 if you have the `recvmsg' function. */
|
||||||
|
#undef HAVE_RECVMSG
|
||||||
|
|
||||||
/* Define to 1 if you have the `round' function. */
|
/* Define to 1 if you have the `round' function. */
|
||||||
#undef HAVE_ROUND
|
#undef HAVE_ROUND
|
||||||
|
|
||||||
@ -412,6 +421,9 @@
|
|||||||
/* Define to 1 if you have the `sendfilev64' function. */
|
/* Define to 1 if you have the `sendfilev64' function. */
|
||||||
#undef HAVE_SENDFILEV64
|
#undef HAVE_SENDFILEV64
|
||||||
|
|
||||||
|
/* Define to 1 if you have the `sendmsg' function. */
|
||||||
|
#undef HAVE_SENDMSG
|
||||||
|
|
||||||
/* Define to 1 if you have the `setcontext' function. */
|
/* Define to 1 if you have the `setcontext' function. */
|
||||||
#undef HAVE_SETCONTEXT
|
#undef HAVE_SETCONTEXT
|
||||||
|
|
||||||
@ -687,6 +699,9 @@
|
|||||||
/* Define to 1 if you have the <wctype.h> header file. */
|
/* Define to 1 if you have the <wctype.h> header file. */
|
||||||
#undef HAVE_WCTYPE_H
|
#undef HAVE_WCTYPE_H
|
||||||
|
|
||||||
|
/* Define to 1 if you have the `writev' function. */
|
||||||
|
#undef HAVE_WRITEV
|
||||||
|
|
||||||
/* Define to 1 if you have the `_vsnprintf' function. */
|
/* Define to 1 if you have the `_vsnprintf' function. */
|
||||||
#undef HAVE__VSNPRINTF
|
#undef HAVE__VSNPRINTF
|
||||||
|
|
||||||
|
@ -74,60 +74,64 @@
|
|||||||
|
|
||||||
|
|
||||||
/* ========================================================================= */
|
/* ========================================================================= */
|
||||||
void mio_closeasyncsck (mio_t* mio, mio_sckhnd_t sck)
|
|
||||||
{
|
|
||||||
#if defined(_WIN32)
|
|
||||||
closesocket (sck);
|
|
||||||
#else
|
|
||||||
close (sck);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
int mio_makesckasync (mio_t* mio, mio_sckhnd_t sck)
|
int mio_makesckasync (mio_t* mio, mio_sckhnd_t sck)
|
||||||
{
|
{
|
||||||
return mio_makesyshndasync (mio, (mio_syshnd_t)sck);
|
return mio_makesyshndasync (mio, (mio_syshnd_t)sck);
|
||||||
}
|
}
|
||||||
|
|
||||||
mio_sckhnd_t mio_openasyncsck (mio_t* mio, int domain, int type, int proto)
|
static void close_async_socket (mio_t* mio, mio_sckhnd_t sck)
|
||||||
{
|
{
|
||||||
mio_sckhnd_t sck;
|
close (sck);
|
||||||
|
|
||||||
#if defined(_WIN32)
|
|
||||||
sck = WSASocket (domain, type, proto, NULL, 0, WSA_FLAG_OVERLAPPED | WSA_FLAG_NO_HANDLE_INHERIT);
|
|
||||||
if (sck == MIO_SCKHND_INVALID)
|
|
||||||
{
|
|
||||||
/* mio_seterrnum (dev->mio, MIO_ESYSERR); or translate errno to mio errnum */
|
|
||||||
return MIO_SCKHND_INVALID;
|
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
|
static mio_sckhnd_t open_async_socket (mio_t* mio, int domain, int type, int proto)
|
||||||
|
{
|
||||||
|
mio_sckhnd_t sck = MIO_SCKHND_INVALID;
|
||||||
|
int flags;
|
||||||
|
|
||||||
|
#if defined(SOCK_NONBLOCK) && defined(SOCK_CLOEXEC)
|
||||||
|
type |= SOCK_NONBLOCK;
|
||||||
|
type |= SOCK_CLOEXEC;
|
||||||
|
open_socket:
|
||||||
|
#endif
|
||||||
sck = socket(domain, type, proto);
|
sck = socket(domain, type, proto);
|
||||||
if (sck == MIO_SCKHND_INVALID)
|
if (sck == MIO_SCKHND_INVALID)
|
||||||
{
|
{
|
||||||
mio->errnum = mio_syserrtoerrnum(errno);
|
#if defined(SOCK_NONBLOCK) && defined(SOCK_CLOEXEC)
|
||||||
return MIO_SCKHND_INVALID;
|
if (errno == EINVAL && (type & (SOCK_NONBLOCK | SOCK_CLOEXEC)))
|
||||||
|
{
|
||||||
|
type &= ~(SOCK_NONBLOCK | SOCK_CLOEXEC);
|
||||||
|
goto open_socket;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
goto oops;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
#if defined(SOCK_NONBLOCK) && defined(SOCK_CLOEXEC)
|
||||||
|
if (type & (SOCK_NONBLOCK | SOCK_CLOEXEC)) goto done;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
flags = fcntl(sck, F_GETFD, 0);
|
||||||
|
if (flags == -1) goto oops;
|
||||||
#if defined(FD_CLOEXEC)
|
#if defined(FD_CLOEXEC)
|
||||||
{
|
flags |= FD_CLOEXEC;
|
||||||
int flags = fcntl (sck, F_GETFD, 0);
|
#endif
|
||||||
if (fcntl (sck, F_SETFD, flags | FD_CLOEXEC) == -1)
|
#if defined(O_NONBLOCK)
|
||||||
{
|
flags |= O_NONBLOCK;
|
||||||
|
#endif
|
||||||
|
if (fcntl(sck, F_SETFD, flags) == -1) goto oops;
|
||||||
|
|
||||||
|
done:
|
||||||
|
return sck;
|
||||||
|
|
||||||
|
oops:
|
||||||
|
if (sck != MIO_SCKHND_INVALID) close (sck);
|
||||||
mio->errnum = mio_syserrtoerrnum(errno);
|
mio->errnum = mio_syserrtoerrnum(errno);
|
||||||
return MIO_SCKHND_INVALID;
|
return MIO_SCKHND_INVALID;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (mio_makesckasync (mio, sck) <= -1)
|
|
||||||
{
|
|
||||||
close (sck);
|
|
||||||
return MIO_SCKHND_INVALID;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return sck;
|
|
||||||
}
|
|
||||||
|
|
||||||
int mio_getsckaddrinfo (mio_t* mio, const mio_sckaddr_t* addr, mio_scklen_t* len, mio_sckfam_t* family)
|
int mio_getsckaddrinfo (mio_t* mio, const mio_sckaddr_t* addr, mio_scklen_t* len, mio_sckfam_t* family)
|
||||||
{
|
{
|
||||||
@ -421,12 +425,13 @@ static int dev_sck_make (mio_dev_t* dev, void* ctx)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
rdev->sck = mio_openasyncsck (dev->mio, sck_type_map[arg->type].domain, sck_type_map[arg->type].type, sck_type_map[arg->type].proto);
|
rdev->sck = open_async_socket(dev->mio, sck_type_map[arg->type].domain, sck_type_map[arg->type].type, sck_type_map[arg->type].proto);
|
||||||
if (rdev->sck == MIO_SCKHND_INVALID) goto oops;
|
if (rdev->sck == MIO_SCKHND_INVALID) goto oops;
|
||||||
|
|
||||||
rdev->dev_capa = MIO_DEV_CAPA_IN | MIO_DEV_CAPA_OUT | sck_type_map[arg->type].extra_dev_capa;
|
rdev->dev_capa = MIO_DEV_CAPA_IN | MIO_DEV_CAPA_OUT | sck_type_map[arg->type].extra_dev_capa;
|
||||||
rdev->on_write = arg->on_write;
|
rdev->on_write = arg->on_write;
|
||||||
rdev->on_read = arg->on_read;
|
rdev->on_read = arg->on_read;
|
||||||
|
rdev->on_connect = arg->on_connect;
|
||||||
rdev->on_disconnect = arg->on_disconnect;
|
rdev->on_disconnect = arg->on_disconnect;
|
||||||
rdev->type = arg->type;
|
rdev->type = arg->type;
|
||||||
rdev->tmrjob_index = MIO_TMRIDX_INVALID;
|
rdev->tmrjob_index = MIO_TMRIDX_INVALID;
|
||||||
@ -436,7 +441,7 @@ static int dev_sck_make (mio_dev_t* dev, void* ctx)
|
|||||||
oops:
|
oops:
|
||||||
if (rdev->sck != MIO_SCKHND_INVALID)
|
if (rdev->sck != MIO_SCKHND_INVALID)
|
||||||
{
|
{
|
||||||
mio_closeasyncsck (rdev->mio, rdev->sck);
|
close_async_socket (rdev->mio, rdev->sck);
|
||||||
rdev->sck = MIO_SCKHND_INVALID;
|
rdev->sck = MIO_SCKHND_INVALID;
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
@ -447,7 +452,9 @@ static int dev_sck_make_client (mio_dev_t* dev, void* ctx)
|
|||||||
mio_dev_sck_t* rdev = (mio_dev_sck_t*)dev;
|
mio_dev_sck_t* rdev = (mio_dev_sck_t*)dev;
|
||||||
mio_syshnd_t* sck = (mio_syshnd_t*)ctx;
|
mio_syshnd_t* sck = (mio_syshnd_t*)ctx;
|
||||||
|
|
||||||
/* nothing special is done here except setting the sock et handle.
|
/* create a socket device that is made of a socket connection
|
||||||
|
* on a listening socket.
|
||||||
|
* nothing special is done here except setting the socket handle.
|
||||||
* most of the initialization is done by the listening socket device
|
* most of the initialization is done by the listening socket device
|
||||||
* after a client socket has been created. */
|
* after a client socket has been created. */
|
||||||
|
|
||||||
@ -512,7 +519,7 @@ static int dev_sck_kill (mio_dev_t* dev, int force)
|
|||||||
|
|
||||||
if (rdev->sck != MIO_SCKHND_INVALID)
|
if (rdev->sck != MIO_SCKHND_INVALID)
|
||||||
{
|
{
|
||||||
mio_closeasyncsck (rdev->mio, rdev->sck);
|
close_async_socket (rdev->mio, rdev->sck);
|
||||||
rdev->sck = MIO_SCKHND_INVALID;
|
rdev->sck = MIO_SCKHND_INVALID;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1013,7 +1020,6 @@ fcntl (rdev->sck, F_SETFL, flags | O_NONBLOCK);
|
|||||||
}
|
}
|
||||||
|
|
||||||
rdev->remoteaddr = conn->remoteaddr;
|
rdev->remoteaddr = conn->remoteaddr;
|
||||||
rdev->on_connect = conn->on_connect;
|
|
||||||
#if defined(USE_SSL)
|
#if defined(USE_SSL)
|
||||||
rdev->ssl_ctx = ssl_ctx;
|
rdev->ssl_ctx = ssl_ctx;
|
||||||
#endif
|
#endif
|
||||||
@ -1040,7 +1046,6 @@ fcntl (rdev->sck, F_SETFL, flags | O_NONBLOCK);
|
|||||||
{
|
{
|
||||||
/* connected immediately */
|
/* connected immediately */
|
||||||
rdev->remoteaddr = conn->remoteaddr;
|
rdev->remoteaddr = conn->remoteaddr;
|
||||||
rdev->on_connect = conn->on_connect;
|
|
||||||
|
|
||||||
sl = MIO_SIZEOF(localaddr);
|
sl = MIO_SIZEOF(localaddr);
|
||||||
if (getsockname(rdev->sck, (struct sockaddr*)&localaddr, &sl) == 0) rdev->localaddr = localaddr;
|
if (getsockname(rdev->sck, (struct sockaddr*)&localaddr, &sl) == 0) rdev->localaddr = localaddr;
|
||||||
@ -1134,7 +1139,6 @@ fcntl (rdev->sck, F_SETFL, flags | O_NONBLOCK);
|
|||||||
}
|
}
|
||||||
|
|
||||||
MIO_DEV_SCK_SET_PROGRESS (rdev, MIO_DEV_SCK_LISTENING);
|
MIO_DEV_SCK_SET_PROGRESS (rdev, MIO_DEV_SCK_LISTENING);
|
||||||
rdev->on_connect = lstn->on_connect;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1274,9 +1278,34 @@ static int accept_incoming_connection (mio_dev_sck_t* rdev)
|
|||||||
mio_sckaddr_t remoteaddr;
|
mio_sckaddr_t remoteaddr;
|
||||||
mio_scklen_t addrlen;
|
mio_scklen_t addrlen;
|
||||||
mio_dev_sck_t* clidev;
|
mio_dev_sck_t* clidev;
|
||||||
|
int flags;
|
||||||
|
|
||||||
/* this is a server(lisening) socket */
|
/* this is a server(lisening) socket */
|
||||||
|
|
||||||
|
#if defined(SOCK_NONBLOCK) && defined(SOCK_CLOEXEC) && defined(HAVE_ACCEPT4)
|
||||||
|
flags = SOCK_NONBLOCK | SOCK_CLOEXEC;
|
||||||
|
|
||||||
|
addrlen = MIO_SIZEOF(remoteaddr);
|
||||||
|
clisck = accept4(rdev->sck, (struct sockaddr*)&remoteaddr, &addrlen, flags);
|
||||||
|
if (clisck == MIO_SCKHND_INVALID)
|
||||||
|
{
|
||||||
|
if (errno != ENOSYS)
|
||||||
|
{
|
||||||
|
if (errno == EINPROGRESS || errno == EWOULDBLOCK || errno == EAGAIN) return 0;
|
||||||
|
if (errno == EINTR) return 0; /* if interrupted by a signal, treat it as if it's EINPROGRESS */
|
||||||
|
|
||||||
|
rdev->mio->errnum = mio_syserrtoerrnum(errno);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// go on for the normal 3-parameter accept
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
goto accept_done;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
addrlen = MIO_SIZEOF(remoteaddr);
|
addrlen = MIO_SIZEOF(remoteaddr);
|
||||||
clisck = accept(rdev->sck, (struct sockaddr*)&remoteaddr, &addrlen);
|
clisck = accept(rdev->sck, (struct sockaddr*)&remoteaddr, &addrlen);
|
||||||
if (clisck == MIO_SCKHND_INVALID)
|
if (clisck == MIO_SCKHND_INVALID)
|
||||||
@ -1288,6 +1317,8 @@ static int accept_incoming_connection (mio_dev_sck_t* rdev)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
accept_done:
|
||||||
/* use rdev->dev_size when instantiating a client sck device
|
/* use rdev->dev_size when instantiating a client sck device
|
||||||
* instead of MIO_SIZEOF(mio_dev_sck_t). therefore, the
|
* instead of MIO_SIZEOF(mio_dev_sck_t). therefore, the
|
||||||
* extension area as big as that of the master sck device
|
* extension area as big as that of the master sck device
|
||||||
|
@ -349,6 +349,7 @@ struct mio_dev_sck_make_t
|
|||||||
mio_dev_sck_type_t type;
|
mio_dev_sck_type_t type;
|
||||||
mio_dev_sck_on_write_t on_write;
|
mio_dev_sck_on_write_t on_write;
|
||||||
mio_dev_sck_on_read_t on_read;
|
mio_dev_sck_on_read_t on_read;
|
||||||
|
mio_dev_sck_on_connect_t on_connect;
|
||||||
mio_dev_sck_on_disconnect_t on_disconnect;
|
mio_dev_sck_on_disconnect_t on_disconnect;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -390,14 +391,12 @@ struct mio_dev_sck_connect_t
|
|||||||
int options;
|
int options;
|
||||||
mio_sckaddr_t remoteaddr;
|
mio_sckaddr_t remoteaddr;
|
||||||
mio_ntime_t connect_tmout;
|
mio_ntime_t connect_tmout;
|
||||||
mio_dev_sck_on_connect_t on_connect;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct mio_dev_sck_listen_t mio_dev_sck_listen_t;
|
typedef struct mio_dev_sck_listen_t mio_dev_sck_listen_t;
|
||||||
struct mio_dev_sck_listen_t
|
struct mio_dev_sck_listen_t
|
||||||
{
|
{
|
||||||
int backlogs;
|
int backlogs;
|
||||||
mio_dev_sck_on_connect_t on_connect; /* optional, but new connections are dropped immediately without this */
|
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct mio_dev_sck_accept_t mio_dev_sck_accept_t;
|
typedef struct mio_dev_sck_accept_t mio_dev_sck_accept_t;
|
||||||
@ -463,18 +462,6 @@ struct mio_dev_sck_t
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
MIO_EXPORT mio_sckhnd_t mio_openasyncsck (
|
|
||||||
mio_t* mio,
|
|
||||||
int domain,
|
|
||||||
int type,
|
|
||||||
int proto
|
|
||||||
);
|
|
||||||
|
|
||||||
MIO_EXPORT void mio_closeasyncsck (
|
|
||||||
mio_t* mio,
|
|
||||||
mio_sckhnd_t sck
|
|
||||||
);
|
|
||||||
|
|
||||||
MIO_EXPORT int mio_makesckasync (
|
MIO_EXPORT int mio_makesckasync (
|
||||||
mio_t* mio,
|
mio_t* mio,
|
||||||
mio_sckhnd_t sck
|
mio_sckhnd_t sck
|
||||||
|
@ -208,6 +208,7 @@ mio_uint128_t mio_hton128 (mio_uint128_t x)
|
|||||||
|
|
||||||
/* ========================================================================= */
|
/* ========================================================================= */
|
||||||
|
|
||||||
|
#define MIO_MT(x) (x)
|
||||||
#define IS_MSPACE(x) ((x) == MIO_MT(' ') || (x) == MIO_MT('\t') || (x) == MIO_MT('\n') || (x) == MIO_MT('\r'))
|
#define IS_MSPACE(x) ((x) == MIO_MT(' ') || (x) == MIO_MT('\t') || (x) == MIO_MT('\n') || (x) == MIO_MT('\r'))
|
||||||
|
|
||||||
mio_bch_t* mio_mbsdup (mio_t* mio, const mio_bch_t* src)
|
mio_bch_t* mio_mbsdup (mio_t* mio, const mio_bch_t* src)
|
||||||
@ -522,3 +523,4 @@ int mio_mbsspl (
|
|||||||
{
|
{
|
||||||
return mio_mbsspltrn (s, delim, lquote, rquote, escape, MIO_NULL);
|
return mio_mbsspltrn (s, delim, lquote, rquote, escape, MIO_NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user