switched to check SSL_new instead of SSL_library_init in configure.ac

fixed a bug of not honoring precision specified with %.* in computing string length given for 's' and 'S'
renamed DEV_CAPA/dev_capa to DEV_CAP/dev_capa
This commit is contained in:
hyung-hwan 2019-01-31 09:16:44 +00:00
parent 4aa0da2011
commit ac65312bf2
15 changed files with 275 additions and 316 deletions

View File

@ -347,7 +347,6 @@ pdfdir = @pdfdir@
prefix = @prefix@
program_transform_name = @program_transform_name@
psdir = @psdir@
runstatedir = @runstatedir@
sbindir = @sbindir@
sharedstatedir = @sharedstatedir@
srcdir = @srcdir@
@ -578,7 +577,7 @@ distdir: $(DISTFILES)
! -type d ! -perm -444 -exec $(install_sh) -c -m a+r {} {} \; \
|| chmod -R a+r "$(distdir)"
dist-gzip: distdir
tardir=$(distdir) && $(am__tar) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).tar.gz
tardir=$(distdir) && $(am__tar) | eval GZIP= gzip $(GZIP_ENV) -c >$(distdir).tar.gz
$(am__post_remove_distdir)
dist-bzip2: distdir
@ -604,7 +603,7 @@ dist-shar: distdir
@echo WARNING: "Support for shar distribution archives is" \
"deprecated." >&2
@echo WARNING: "It will be removed altogether in Automake 2.0" >&2
shar $(distdir) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).shar.gz
shar $(distdir) | eval GZIP= gzip $(GZIP_ENV) -c >$(distdir).shar.gz
$(am__post_remove_distdir)
dist-zip: distdir
@ -622,7 +621,7 @@ dist dist-all:
distcheck: dist
case '$(DIST_ARCHIVES)' in \
*.tar.gz*) \
GZIP=$(GZIP_ENV) gzip -dc $(distdir).tar.gz | $(am__untar) ;;\
eval GZIP= gzip $(GZIP_ENV) -dc $(distdir).tar.gz | $(am__untar) ;;\
*.tar.bz2*) \
bzip2 -dc $(distdir).tar.bz2 | $(am__untar) ;;\
*.tar.lz*) \
@ -632,7 +631,7 @@ distcheck: dist
*.tar.Z*) \
uncompress -c $(distdir).tar.Z | $(am__untar) ;;\
*.shar.gz*) \
GZIP=$(GZIP_ENV) gzip -dc $(distdir).shar.gz | unshar ;;\
eval GZIP= gzip $(GZIP_ENV) -dc $(distdir).shar.gz | unshar ;;\
*.zip*) \
unzip $(distdir).zip ;;\
esac

150
mio/configure vendored
View File

@ -771,7 +771,6 @@ infodir
docdir
oldincludedir
includedir
runstatedir
localstatedir
sharedstatedir
sysconfdir
@ -862,7 +861,6 @@ datadir='${datarootdir}'
sysconfdir='${prefix}/etc'
sharedstatedir='${prefix}/com'
localstatedir='${prefix}/var'
runstatedir='${localstatedir}/run'
includedir='${prefix}/include'
oldincludedir='/usr/include'
docdir='${datarootdir}/doc/${PACKAGE_TARNAME}'
@ -1115,15 +1113,6 @@ do
| -silent | --silent | --silen | --sile | --sil)
silent=yes ;;
-runstatedir | --runstatedir | --runstatedi | --runstated \
| --runstate | --runstat | --runsta | --runst | --runs \
| --run | --ru | --r)
ac_prev=runstatedir ;;
-runstatedir=* | --runstatedir=* | --runstatedi=* | --runstated=* \
| --runstate=* | --runstat=* | --runsta=* | --runst=* | --runs=* \
| --run=* | --ru=* | --r=*)
runstatedir=$ac_optarg ;;
-sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb)
ac_prev=sbindir ;;
-sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \
@ -1261,7 +1250,7 @@ fi
for ac_var in exec_prefix prefix bindir sbindir libexecdir datarootdir \
datadir sysconfdir sharedstatedir localstatedir includedir \
oldincludedir docdir infodir htmldir dvidir pdfdir psdir \
libdir localedir mandir runstatedir
libdir localedir mandir
do
eval ac_val=\$$ac_var
# Remove trailing slashes.
@ -1414,7 +1403,6 @@ Fine tuning of the installation directories:
--sysconfdir=DIR read-only single-machine data [PREFIX/etc]
--sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com]
--localstatedir=DIR modifiable single-machine data [PREFIX/var]
--runstatedir=DIR modifiable per-process data [LOCALSTATEDIR/run]
--libdir=DIR object code libraries [EPREFIX/lib]
--includedir=DIR C header files [PREFIX/include]
--oldincludedir=DIR C header files for non-gcc [/usr/include]
@ -18546,39 +18534,27 @@ fi
done
for ac_func in SSL_library_init
for ac_func in SSL_new
do :
ac_fn_c_check_func "$LINENO" "SSL_library_init" "ac_cv_func_SSL_library_init"
if test "x$ac_cv_func_SSL_library_init" = xyes; then :
ac_fn_c_check_func "$LINENO" "SSL_new" "ac_cv_func_SSL_new"
if test "x$ac_cv_func_SSL_new" = xyes; then :
cat >>confdefs.h <<_ACEOF
#define HAVE_SSL_LIBRARY_INIT 1
#define HAVE_SSL_NEW 1
_ACEOF
fi
done
for ac_func in OPENSSL_init_ssl
do :
ac_fn_c_check_func "$LINENO" "OPENSSL_init_ssl" "ac_cv_func_OPENSSL_init_ssl"
if test "x$ac_cv_func_OPENSSL_init_ssl" = xyes; then :
cat >>confdefs.h <<_ACEOF
#define HAVE_OPENSSL_INIT_SSL 1
_ACEOF
fi
done
if test "x$ac_cv_func_SSL_library_init" = "xyes" -o "x$ac_cv_func_OPENSSL_init_ssl" = "xyes"
if test "x$ac_cv_func_SSL_new" = "xyes"
then
$as_echo "#define HAVE_SSL 1" >>confdefs.h
else
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for SSL_library_init in -lssl" >&5
$as_echo_n "checking for SSL_library_init in -lssl... " >&6; }
if ${ac_cv_lib_ssl_SSL_library_init+:} false; then :
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for SSL_new in -lssl" >&5
$as_echo_n "checking for SSL_new in -lssl... " >&6; }
if ${ac_cv_lib_ssl_SSL_new+:} false; then :
$as_echo_n "(cached) " >&6
else
ac_check_lib_save_LIBS=$LIBS
@ -18592,27 +18568,27 @@ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
#ifdef __cplusplus
extern "C"
#endif
char SSL_library_init ();
char SSL_new ();
int
main ()
{
return SSL_library_init ();
return SSL_new ();
;
return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"; then :
ac_cv_lib_ssl_SSL_library_init=yes
ac_cv_lib_ssl_SSL_new=yes
else
ac_cv_lib_ssl_SSL_library_init=no
ac_cv_lib_ssl_SSL_new=no
fi
rm -f core conftest.err conftest.$ac_objext \
conftest$ac_exeext conftest.$ac_ext
LIBS=$ac_check_lib_save_LIBS
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_ssl_SSL_library_init" >&5
$as_echo "$ac_cv_lib_ssl_SSL_library_init" >&6; }
if test "x$ac_cv_lib_ssl_SSL_library_init" = xyes; then :
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_ssl_SSL_new" >&5
$as_echo "$ac_cv_lib_ssl_SSL_new" >&6; }
if test "x$ac_cv_lib_ssl_SSL_new" = xyes; then :
SSL_LIBS="-lssl"
@ -18662,99 +18638,7 @@ if test "x$ac_cv_lib_crypto_ERR_get_error" = xyes; then :
fi
$as_echo "#define HAVE_SSL_LIBRARY_INIT 1" >>confdefs.h
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for OPENSSL_init_ssl in -lssl" >&5
$as_echo_n "checking for OPENSSL_init_ssl in -lssl... " >&6; }
if ${ac_cv_lib_ssl_OPENSSL_init_ssl+:} false; then :
$as_echo_n "(cached) " >&6
else
ac_check_lib_save_LIBS=$LIBS
LIBS="-lssl $LIBS"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
/* Override any GCC internal prototype to avoid an error.
Use char because int might match the return type of a GCC
builtin and then its argument prototype would still apply. */
#ifdef __cplusplus
extern "C"
#endif
char OPENSSL_init_ssl ();
int
main ()
{
return OPENSSL_init_ssl ();
;
return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"; then :
ac_cv_lib_ssl_OPENSSL_init_ssl=yes
else
ac_cv_lib_ssl_OPENSSL_init_ssl=no
fi
rm -f core conftest.err conftest.$ac_objext \
conftest$ac_exeext conftest.$ac_ext
LIBS=$ac_check_lib_save_LIBS
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_ssl_OPENSSL_init_ssl" >&5
$as_echo "$ac_cv_lib_ssl_OPENSSL_init_ssl" >&6; }
if test "x$ac_cv_lib_ssl_OPENSSL_init_ssl" = xyes; then :
SSL_LIBS="-lssl"
$as_echo "#define HAVE_SSL 1" >>confdefs.h
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for ERR_get_error in -lcrypto" >&5
$as_echo_n "checking for ERR_get_error in -lcrypto... " >&6; }
if ${ac_cv_lib_crypto_ERR_get_error+:} false; then :
$as_echo_n "(cached) " >&6
else
ac_check_lib_save_LIBS=$LIBS
LIBS="-lcrypto $LIBS"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
/* Override any GCC internal prototype to avoid an error.
Use char because int might match the return type of a GCC
builtin and then its argument prototype would still apply. */
#ifdef __cplusplus
extern "C"
#endif
char ERR_get_error ();
int
main ()
{
return ERR_get_error ();
;
return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"; then :
ac_cv_lib_crypto_ERR_get_error=yes
else
ac_cv_lib_crypto_ERR_get_error=no
fi
rm -f core conftest.err conftest.$ac_objext \
conftest$ac_exeext conftest.$ac_ext
LIBS=$ac_check_lib_save_LIBS
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_crypto_ERR_get_error" >&5
$as_echo "$ac_cv_lib_crypto_ERR_get_error" >&6; }
if test "x$ac_cv_lib_crypto_ERR_get_error" = xyes; then :
SSL_LIBS="${SSL_LIBS} -lcrypto"
fi
$as_echo "#define HAVE_OPENSSL_INIT_SSL 1" >>confdefs.h
$as_echo "#define HAVE_SSL_NEW 1" >>confdefs.h
fi

View File

@ -277,17 +277,18 @@ then
AC_CHECK_HEADERS([openssl/ssl.h openssl/err.h openssl/engine.h])
dnl check for an SSL library
AC_CHECK_FUNCS([SSL_library_init])
dnl SSL_library_init is a macro aliasing OPENSSL_init_ssl in openssl 1.1.0 or later
dnl i used SSL_library_init at first.
dnl starting from openssl 1.1.0, SSL_library_init was made to a macro
dnl aliasing OPENSSL_init_ssl.
dnl #define SSL_library_init() OPENSSL_init_ssl(0, NULL)
AC_CHECK_FUNCS([OPENSSL_init_ssl])
dnl instead of checking both, now i use SSL_new.
AC_CHECK_FUNCS([SSL_new])
if test "x$ac_cv_func_SSL_library_init" = "xyes" -o "x$ac_cv_func_OPENSSL_init_ssl" = "xyes"
if test "x$ac_cv_func_SSL_new" = "xyes"
then
AC_DEFINE(HAVE_SSL, 1, [ssl support])
else
AC_CHECK_LIB([ssl], [SSL_library_init], [
AC_CHECK_LIB([ssl], [SSL_new], [
SSL_LIBS="-lssl"
AC_DEFINE(HAVE_SSL, 1, [ssl support])
@ -297,20 +298,7 @@ then
])
dnl only for consistency with AC_CHECK_FUNCS
AC_DEFINE(HAVE_SSL_LIBRARY_INIT, 1)
])
AC_CHECK_LIB([ssl], [OPENSSL_init_ssl], [
SSL_LIBS="-lssl"
AC_DEFINE(HAVE_SSL, 1, [ssl support])
dnl additional check
AC_CHECK_LIB([crypto], [ERR_get_error], [
SSL_LIBS="${SSL_LIBS} -lcrypto"
])
dnl only for consistency with AC_CHECK_FUNCS
AC_DEFINE(HAVE_OPENSSL_INIT_SSL, 1)
AC_DEFINE(HAVE_SSL_NEW, 1)
])
fi

View File

@ -365,7 +365,6 @@ pdfdir = @pdfdir@
prefix = @prefix@
program_transform_name = @program_transform_name@
psdir = @psdir@
runstatedir = @runstatedir@
sbindir = @sbindir@
sharedstatedir = @sharedstatedir@
srcdir = @srcdir@

View File

@ -460,12 +460,19 @@ static int fmtoutv (mio_t* mio, const fmtchar_t* fmt, mio_fmtout_data_t* data, v
#endif
lowercase_s:
bsp = va_arg (ap, mio_bch_t*);
bsp = va_arg(ap, mio_bch_t*);
if (bsp == MIO_NULL) bsp = bch_nullstr;
#if defined(MIO_OOCH_IS_UCH)
/* get the length */
for (bslen = 0; bsp[bslen]; bslen++);
if (flagc & FLAGC_DOT)
{
for (bslen = 0; bslen < precision && bsp[bslen]; bslen++);
}
else
{
for (bslen = 0; bsp[bslen]; bslen++);
}
if (mio_conv_bchars_to_uchars_with_cmgr(bsp, &bslen, MIO_NULL, &slen, mio->cmgr, 0) <= -1) goto oops;
@ -534,7 +541,14 @@ static int fmtoutv (mio_t* mio, const fmtchar_t* fmt, mio_fmtout_data_t* data, v
#if defined(MIO_OOCH_IS_BCH)
/* get the length */
for (uslen = 0; usp[uslen]; uslen++);
if (flagc & FLAGC_DOT)
{
for (uslen = 0; uslen < precision && usp[uslen]; uslen++);
}
else
{
for (uslen = 0; usp[uslen]; uslen++);
}
if (mio_conv_uchars_to_bchars_with_cmgr(usp, &uslen, MIO_NULL, &slen, mio->cmgr) <= -1) goto oops;

View File

@ -179,7 +179,7 @@ static void tcp_sck_on_connect (mio_dev_sck_t* tcp)
}
else if (tcp->state & MIO_DEV_SCK_ACCEPTED)
{
MIO_INFO5 (tcp->mio, "DEVICE accepted client device... .LOCAL %s:%d REMOTE %s:%d\n",
MIO_INFO5 (tcp->mio, "DEVICE accepted client device... .LOCAL %hs:%d REMOTE %hs:%d\n",
buf1, mio_getsckaddrport(&tcp->localaddr), buf2, mio_getsckaddrport(&tcp->remoteaddr), tcp->sck);
}
@ -227,7 +227,6 @@ static int tcp_sck_on_write (mio_dev_sck_t* tcp, mio_iolen_t wrlen, void* wrctx,
static int tcp_sck_on_read (mio_dev_sck_t* tcp, const void* buf, mio_iolen_t len, const mio_sckaddr_t* srcaddr)
{
int n;
static int x = 0;
if (len <= -1)
{
@ -277,21 +276,54 @@ static int x = 0;
/* ========================================================================= */
static void pro_on_close (mio_dev_pro_t* dev, mio_dev_pro_sid_t sid)
static void pro_on_close (mio_dev_pro_t* pro, mio_dev_pro_sid_t sid)
{
printf (">>>>>>>>>>>>> ON CLOSE OF SLAVE %d.\n", sid);
mio_t* mio = pro->mio;
if (sid == MIO_DEV_PRO_MASTER)
MIO_INFO1 (mio, "PROCESS(%d) CLOSE MASTER\n", (int)pro->child_pid);
else
MIO_INFO2 (mio, "PROCESS(%d) CLOSE SLAVE[%d]\n", (int)pro->child_pid, sid);
}
static int pro_on_read (mio_dev_pro_t* dev, const void* data, mio_iolen_t dlen, mio_dev_pro_sid_t sid)
static int pro_on_read (mio_dev_pro_t* pro, mio_dev_pro_sid_t sid, const void* data, mio_iolen_t dlen)
{
printf ("PROCESS READ DATA on SLAVE[%d]... [%.*s]\n", (int)sid, (int)dlen, (char*)data);
mio_t* mio = pro->mio;
if (dlen <= -1)
{
MIO_INFO1 (mio, "PROCESS(%d): READ TIMED OUT...\n", (int)pro->child_pid);
mio_dev_pro_halt (pro);
return 0;
}
else if (dlen <= 0)
{
MIO_INFO1 (mio, "PROCESS(%d): EOF RECEIVED...\n", (int)pro->child_pid);
/* no outstanding request. but EOF */
mio_dev_pro_halt (pro);
return 0;
}
MIO_INFO5 (mio, "PROCESS(%d) READ DATA ON SLAVE[%d] len=%d [%.*hs]\n", (int)pro->child_pid, (int)sid, (int)dlen, dlen, (char*)data);
if (sid == MIO_DEV_PRO_OUT)
{
mio_dev_pro_read (pro, sid, 0);
mio_dev_pro_write (pro, "HELLO\n", 6, MIO_NULL);
}
return 0;
}
static int pro_on_write (mio_dev_pro_t* dev, mio_iolen_t wrlen, void* wrctx)
static int pro_on_write (mio_dev_pro_t* pro, mio_iolen_t wrlen, void* wrctx)
{
printf ("PROCESS WROTE DATA...\n");
mio_t* mio = pro->mio;
if (wrlen <= -1)
{
MIO_INFO1 (mio, "PROCESS(%d): WRITE TIMED OUT...\n", (int)pro->child_pid);
mio_dev_pro_halt (pro);
return 0;
}
MIO_DEBUG2 (mio, "PROCESS(%d) wrote data of %d bytes\n", (int)pro->child_pid, (int)wrlen);
mio_dev_pro_read (pro, MIO_DEV_PRO_OUT, 1);
return 0;
}
@ -747,8 +779,8 @@ for (i = 0; i < 5; i++)
memset (&pro_make, 0, MIO_SIZEOF(pro_make));
pro_make.flags = MIO_DEV_PRO_READOUT | MIO_DEV_PRO_READERR | MIO_DEV_PRO_WRITEIN /*| MIO_DEV_PRO_FORGET_CHILD*/;
//pro_make.cmd = "/bin/ls -laF /usr/bin";
pro_make.cmd = "/bin/ls -laF";
//pro_make.cmd = "./a";
//pro_make.cmd = "/bin/ls -laF";
pro_make.cmd = "./a";
pro_make.on_read = pro_on_read;
pro_make.on_write = pro_on_write;
pro_make.on_close = pro_on_close;
@ -759,6 +791,8 @@ for (i = 0; i < 5; i++)
MIO_INFO1 (mio, "CANNOT CREATE PROCESS PIPE - %js\n", mio_geterrmsg(mio));
goto oops;
}
mio_dev_pro_read (pro, MIO_DEV_PRO_OUT, 0);
//mio_dev_pro_read (pro, MIO_DEV_PRO_ERR, 0);
mio_dev_pro_write (pro, "MY MIO LIBRARY\n", 16, MIO_NULL);
//mio_dev_pro_killchild (pro);

View File

@ -370,9 +370,6 @@
/* Define to 1 if you have the <openssl/err.h> header file. */
#undef HAVE_OPENSSL_ERR_H
/* Define to 1 if you have the `OPENSSL_init_ssl' function. */
#undef HAVE_OPENSSL_INIT_SSL
/* Define to 1 if you have the <openssl/ssl.h> header file. */
#undef HAVE_OPENSSL_SSL_H
@ -496,8 +493,8 @@
/* ssl support */
#undef HAVE_SSL
/* Define to 1 if you have the `SSL_library_init' function. */
#undef HAVE_SSL_LIBRARY_INIT
/* Define to 1 if you have the `SSL_new' function. */
#undef HAVE_SSL_NEW
/* Define to 1 if you have the `stat64' function. */
#undef HAVE_STAT64

View File

@ -38,7 +38,7 @@ struct slave_info_t
{
mio_dev_pro_make_t* mi;
mio_syshnd_t pfd;
int dev_capa;
int dev_cap;
mio_dev_pro_sid_t id;
};
@ -328,7 +328,7 @@ static int dev_pro_make_master (mio_dev_t* dev, void* ctx)
si.mi = info;
si.pfd = pfds[1];
si.dev_capa = MIO_DEV_CAPA_OUT | MIO_DEV_CAPA_OUT_QUEUED | MIO_DEV_CAPA_STREAM;
si.dev_cap = MIO_DEV_CAP_OUT | MIO_DEV_CAP_STREAM;
si.id = MIO_DEV_PRO_IN;
rdev->slave[MIO_DEV_PRO_IN] = make_slave(mio, &si);
@ -345,7 +345,7 @@ static int dev_pro_make_master (mio_dev_t* dev, void* ctx)
si.mi = info;
si.pfd = pfds[2];
si.dev_capa = MIO_DEV_CAPA_IN | MIO_DEV_CAPA_STREAM;
si.dev_cap = MIO_DEV_CAP_IN | MIO_DEV_CAP_STREAM;
si.id = MIO_DEV_PRO_OUT;
rdev->slave[MIO_DEV_PRO_OUT] = make_slave(mio, &si);
@ -362,7 +362,7 @@ static int dev_pro_make_master (mio_dev_t* dev, void* ctx)
si.mi = info;
si.pfd = pfds[4];
si.dev_capa = MIO_DEV_CAPA_IN | MIO_DEV_CAPA_STREAM;
si.dev_cap = MIO_DEV_CAP_IN | MIO_DEV_CAP_STREAM;
si.id = MIO_DEV_PRO_ERR;
rdev->slave[MIO_DEV_PRO_ERR] = make_slave(mio, &si);
@ -377,7 +377,7 @@ static int dev_pro_make_master (mio_dev_t* dev, void* ctx)
if (rdev->slave[i]) rdev->slave[i]->master = rdev;
}
rdev->dev_capa = MIO_DEV_CAPA_VIRTUAL; /* the master device doesn't perform I/O */
rdev->dev_cap = MIO_DEV_CAP_VIRTUAL; /* the master device doesn't perform I/O */
rdev->flags = info->flags;
rdev->on_read = info->on_read;
rdev->on_write = info->on_write;
@ -415,7 +415,7 @@ static int dev_pro_make_slave (mio_dev_t* dev, void* ctx)
mio_dev_pro_slave_t* rdev = (mio_dev_pro_slave_t*)dev;
slave_info_t* si = (slave_info_t*)ctx;
rdev->dev_capa = si->dev_capa;
rdev->dev_cap = si->dev_cap;
rdev->id = si->id;
rdev->pfd = si->pfd;
/* keep rdev->master to MIO_NULL. it's set to the right master
@ -715,13 +715,13 @@ static int pro_ready_slave (mio_dev_t* dev, int events)
static int pro_on_read_slave_out (mio_dev_t* dev, const void* data, mio_iolen_t len, const mio_devaddr_t* srcaddr)
{
mio_dev_pro_slave_t* pro = (mio_dev_pro_slave_t*)dev;
return pro->master->on_read(pro->master, data, len, MIO_DEV_PRO_OUT);
return pro->master->on_read(pro->master, MIO_DEV_PRO_OUT, data, len);
}
static int pro_on_read_slave_err (mio_dev_t* dev, const void* data, mio_iolen_t len, const mio_devaddr_t* srcaddr)
{
mio_dev_pro_slave_t* pro = (mio_dev_pro_slave_t*)dev;
return pro->master->on_read(pro->master, data, len, MIO_DEV_PRO_ERR);
return pro->master->on_read(pro->master, MIO_DEV_PRO_ERR, data, len);
}
static int pro_on_write_slave (mio_dev_t* dev, mio_iolen_t wrlen, void* wrctx, const mio_devaddr_t* dstaddr)
@ -785,16 +785,49 @@ mio_dev_pro_t* mio_dev_pro_make (mio_t* mio, mio_oow_t xtnsize, const mio_dev_pr
&dev_pro_methods, &dev_pro_event_callbacks, (void*)info);
}
void mio_dev_pro_kill (mio_dev_pro_t* dev)
void mio_dev_pro_halt (mio_dev_pro_t* dev)
{
mio_killdev (dev->mio, (mio_dev_t*)dev);
mio_dev_halt ((mio_dev_t*)dev);
}
int mio_dev_pro_read (mio_dev_pro_t* dev, mio_dev_pro_sid_t sid, int enabled)
{
mio_t* mio = dev->mio;
MIO_ASSERT (mio, sid == MIO_DEV_PRO_OUT || sid == MIO_DEV_PRO_ERR);
if (dev->slave[sid])
{
return mio_dev_read((mio_dev_t*)dev->slave[sid], enabled);
}
else
{
mio_seterrnum (dev->mio, MIO_ENOCAPA); /* TODO: is it the right error number? */
return -1;
}
}
int mio_dev_pro_timedread (mio_dev_pro_t* dev, mio_dev_pro_sid_t sid, int enabled, const mio_ntime_t* tmout)
{
mio_t* mio = dev->mio;
MIO_ASSERT (mio, sid == MIO_DEV_PRO_OUT || sid == MIO_DEV_PRO_ERR);
if (dev->slave[sid])
{
return mio_dev_timedread((mio_dev_t*)dev->slave[sid], enabled, tmout);
}
else
{
mio_seterrnum (mio, MIO_ENOCAPA); /* TODO: is it the right error number? */
return -1;
}
}
int mio_dev_pro_write (mio_dev_pro_t* dev, const void* data, mio_iolen_t dlen, void* wrctx)
{
if (dev->slave[0])
if (dev->slave[MIO_DEV_PRO_IN])
{
return mio_dev_write((mio_dev_t*)dev->slave[0], data, dlen, wrctx, MIO_NULL);
return mio_dev_write((mio_dev_t*)dev->slave[MIO_DEV_PRO_IN], data, dlen, wrctx, MIO_NULL);
}
else
{
@ -805,9 +838,9 @@ int mio_dev_pro_write (mio_dev_pro_t* dev, const void* data, mio_iolen_t dlen, v
int mio_dev_pro_timedwrite (mio_dev_pro_t* dev, const void* data, mio_iolen_t dlen, const mio_ntime_t* tmout, void* wrctx)
{
if (dev->slave[0])
if (dev->slave[MIO_DEV_PRO_IN])
{
return mio_dev_timedwrite((mio_dev_t*)dev->slave[0], data, dlen, tmout, wrctx, MIO_NULL);
return mio_dev_timedwrite((mio_dev_t*)dev->slave[MIO_DEV_PRO_IN], data, dlen, tmout, wrctx, MIO_NULL);
}
else
{

View File

@ -32,16 +32,16 @@
enum mio_dev_pro_sid_t
{
MIO_DEV_PRO_MASTER = -1,
MIO_DEV_PRO_IN = 0,
MIO_DEV_PRO_OUT = 1,
MIO_DEV_PRO_ERR = 2
MIO_DEV_PRO_IN = 0, /* input of the child process */
MIO_DEV_PRO_OUT = 1, /* output of the child process */
MIO_DEV_PRO_ERR = 2 /* error output of the child process */
};
typedef enum mio_dev_pro_sid_t mio_dev_pro_sid_t;
typedef struct mio_dev_pro_t mio_dev_pro_t;
typedef struct mio_dev_pro_slave_t mio_dev_pro_slave_t;
typedef int (*mio_dev_pro_on_read_t) (mio_dev_pro_t* dev, const void* data, mio_iolen_t len, mio_dev_pro_sid_t sid);
typedef int (*mio_dev_pro_on_read_t) (mio_dev_pro_t* dev, mio_dev_pro_sid_t sid, const void* data, mio_iolen_t len);
typedef int (*mio_dev_pro_on_write_t) (mio_dev_pro_t* dev, mio_iolen_t wrlen, void* wrctx);
typedef void (*mio_dev_pro_on_close_t) (mio_dev_pro_t* dev, mio_dev_pro_sid_t sid);
@ -124,27 +124,40 @@ extern "C" {
MIO_EXPORT mio_dev_pro_t* mio_dev_pro_make (
mio_t* mio,
mio_oow_t xtnsize,
mio_oow_t xtnsize,
const mio_dev_pro_make_t* data
);
MIO_EXPORT void mio_dev_pro_kill (
MIO_EXPORT void mio_dev_pro_halt (
mio_dev_pro_t* pro
);
MIO_EXPORT int mio_dev_pro_read (
mio_dev_pro_t* pro,
mio_dev_pro_sid_t sid, /**< either #MIO_DEV_PRO_OUT or #MIO_DEV_PRO_ERR */
int enabled
);
MIO_EXPORT int mio_dev_pro_timedread (
mio_dev_pro_t* pro,
mio_dev_pro_sid_t sid, /**< either #MIO_DEV_PRO_OUT or #MIO_DEV_PRO_ERR */
int enabled,
const mio_ntime_t* tmout
);
MIO_EXPORT int mio_dev_pro_write (
mio_dev_pro_t* pro,
const void* data,
const void* data,
mio_iolen_t len,
void* wrctx
void* wrctx
);
MIO_EXPORT int mio_dev_pro_timedwrite (
mio_dev_pro_t* pro,
const void* data,
const void* data,
mio_iolen_t len,
const mio_ntime_t* tmout,
void* wrctx
void* wrctx
);
MIO_EXPORT int mio_dev_pro_close (

View File

@ -167,7 +167,7 @@ int mio_sys_ctrlmux (
mio_t* mio,
mio_sys_mux_cmd_t cmd,
mio_dev_t* dev,
int dev_capa
int dev_cap
);
int mio_sys_waitmux (

View File

@ -288,23 +288,23 @@ static MIO_INLINE mio_sckaddr_t* devaddr_to_sckaddr (mio_dev_sck_t* dev, const m
/* ========================================================================= */
#define IS_STATEFUL(sck) ((sck)->dev_capa & MIO_DEV_CAPA_STREAM)
#define IS_STATEFUL(sck) ((sck)->dev_cap & MIO_DEV_CAP_STREAM)
struct sck_type_map_t
{
int domain;
int type;
int proto;
int extra_dev_capa;
int extra_dev_cap;
};
static struct sck_type_map_t sck_type_map[] =
{
/* MIO_DEV_SCK_TCP4 */
{ AF_INET, SOCK_STREAM, 0, MIO_DEV_CAPA_STREAM | MIO_DEV_CAPA_OUT_QUEUED },
{ AF_INET, SOCK_STREAM, 0, MIO_DEV_CAP_STREAM },
/* MIO_DEV_SCK_TCP6 */
{ AF_INET6, SOCK_STREAM, 0, MIO_DEV_CAPA_STREAM | MIO_DEV_CAPA_OUT_QUEUED },
{ AF_INET6, SOCK_STREAM, 0, MIO_DEV_CAP_STREAM },
/* MIO_DEV_SCK_UPD4 */
{ AF_INET, SOCK_DGRAM, 0, 0 },
@ -437,7 +437,7 @@ static int dev_sck_make (mio_dev_t* dev, void* ctx)
rdev->sck = open_async_socket(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;
rdev->dev_capa = MIO_DEV_CAPA_IN | MIO_DEV_CAPA_OUT | sck_type_map[arg->type].extra_dev_capa;
rdev->dev_cap = MIO_DEV_CAP_IN | MIO_DEV_CAP_OUT | sck_type_map[arg->type].extra_dev_cap;
rdev->on_write = arg->on_write;
rdev->on_read = arg->on_read;
rdev->on_connect = arg->on_connect;
@ -1359,7 +1359,7 @@ accept_done:
MIO_ASSERT (mio, clidev->sck == clisck);
clidev->dev_capa |= MIO_DEV_CAPA_IN | MIO_DEV_CAPA_OUT | MIO_DEV_CAPA_STREAM | MIO_DEV_CAPA_OUT_QUEUED;
clidev->dev_cap |= MIO_DEV_CAP_IN | MIO_DEV_CAP_OUT | MIO_DEV_CAP_STREAM;
clidev->remoteaddr = remoteaddr;
addrlen = MIO_SIZEOF(clidev->localaddr);
@ -1697,7 +1697,7 @@ mio_dev_sck_t* mio_dev_sck_make (mio_t* mio, mio_oow_t xtnsize, const mio_dev_sc
return MIO_NULL;
}
if (sck_type_map[info->type].extra_dev_capa & MIO_DEV_CAPA_STREAM) /* can't use the IS_STATEFUL() macro yet */
if (sck_type_map[info->type].extra_dev_cap & MIO_DEV_CAP_STREAM) /* can't use the IS_STATEFUL() macro yet */
{
rdev = (mio_dev_sck_t*)mio_makedev(
mio, MIO_SIZEOF(mio_dev_sck_t) + xtnsize,

View File

@ -26,7 +26,7 @@
#include "mio-prv.h"
#define DEV_CAPA_ALL_WATCHED (MIO_DEV_CAPA_IN_WATCHED | MIO_DEV_CAPA_OUT_WATCHED | MIO_DEV_CAPA_PRI_WATCHED)
#define DEV_CAP_ALL_WATCHED (MIO_DEV_CAP_IN_WATCHED | MIO_DEV_CAP_OUT_WATCHED | MIO_DEV_CAP_PRI_WATCHED)
static int schedule_kill_zombie_job (mio_dev_t* dev);
static int kill_and_free_device (mio_dev_t* dev, int force);
@ -173,7 +173,7 @@ void mio_fini (mio_t* mio)
/* remove the device from the zombie device list */
UNLINK_DEVICE_FROM_LIST (&mio->zmbdev, dev);
dev->dev_capa &= ~MIO_DEV_CAPA_ZOMBIE;
dev->dev_cap &= ~MIO_DEV_CAP_ZOMBIE;
/* put it to a private list for aborting */
APPEND_DEVICE_TO_LIST (&diehard, dev);
@ -189,7 +189,7 @@ void mio_fini (mio_t* mio)
* because the device is freed regardless of the failure when 2
* is given to kill_and_free_device(). */
dev = diehard.head;
MIO_ASSERT (mio, !(dev->dev_capa & (MIO_DEV_CAPA_ACTIVE | MIO_DEV_CAPA_HALTED | MIO_DEV_CAPA_ZOMBIE)));
MIO_ASSERT (mio, !(dev->dev_cap & (MIO_DEV_CAP_ACTIVE | MIO_DEV_CAP_HALTED | MIO_DEV_CAP_ZOMBIE)));
UNLINK_DEVICE_FROM_LIST (&diehard, dev);
kill_and_free_device (dev, 2);
}
@ -270,7 +270,7 @@ static MIO_INLINE void handle_event (mio_t* mio, mio_dev_t* dev, int events, int
{
MIO_ASSERT (mio, mio == dev->mio);
dev->dev_capa &= ~MIO_DEV_CAPA_RENEW_REQUIRED;
dev->dev_cap &= ~MIO_DEV_CAP_RENEW_REQUIRED;
MIO_ASSERT (mio, mio == dev->mio);
@ -342,12 +342,12 @@ static MIO_INLINE void handle_event (mio_t* mio, mio_dev_t* dev, int events, int
/* finished writing a single write request */
int y, out_closed = 0;
if (q->len <= 0 && (dev->dev_capa & MIO_DEV_CAPA_STREAM))
if (q->len <= 0 && (dev->dev_cap & MIO_DEV_CAP_STREAM))
{
/* it was a zero-length write request.
* for a stream, it is to close the output. */
dev->dev_capa |= MIO_DEV_CAPA_OUT_CLOSED;
dev->dev_capa |= MIO_DEV_CAPA_RENEW_REQUIRED;
dev->dev_cap |= MIO_DEV_CAP_OUT_CLOSED;
dev->dev_cap |= MIO_DEV_CAP_RENEW_REQUIRED;
out_closed = 1;
}
@ -382,15 +382,15 @@ static MIO_INLINE void handle_event (mio_t* mio, mio_dev_t* dev, int events, int
if (dev && MIO_WQ_ISEMPTY(&dev->wq))
{
/* no pending request to write */
if ((dev->dev_capa & MIO_DEV_CAPA_IN_CLOSED) &&
(dev->dev_capa & MIO_DEV_CAPA_OUT_CLOSED))
if ((dev->dev_cap & MIO_DEV_CAP_IN_CLOSED) &&
(dev->dev_cap & MIO_DEV_CAP_OUT_CLOSED))
{
mio_dev_halt (dev);
dev = MIO_NULL;
}
else
{
dev->dev_capa |= MIO_DEV_CAPA_RENEW_REQUIRED;
dev->dev_cap |= MIO_DEV_CAP_RENEW_REQUIRED;
}
}
}
@ -441,16 +441,16 @@ static MIO_INLINE void handle_event (mio_t* mio, mio_dev_t* dev, int events, int
}
else /*if (x >= 1) */
{
if (len <= 0 && (dev->dev_capa & MIO_DEV_CAPA_STREAM))
if (len <= 0 && (dev->dev_cap & MIO_DEV_CAP_STREAM))
{
/* EOF received. for a stream device, a zero-length
* read is interpreted as EOF. */
dev->dev_capa |= MIO_DEV_CAPA_IN_CLOSED;
dev->dev_capa |= MIO_DEV_CAPA_RENEW_REQUIRED;
dev->dev_cap |= MIO_DEV_CAP_IN_CLOSED;
dev->dev_cap |= MIO_DEV_CAP_RENEW_REQUIRED;
/* call the on_read callback to report EOF */
if (dev->dev_evcb->on_read(dev, mio->bigbuf, len, &srcaddr) <= -1 ||
(dev->dev_capa & MIO_DEV_CAPA_OUT_CLOSED))
(dev->dev_cap & MIO_DEV_CAP_OUT_CLOSED))
{
/* 1. input ended and its reporting failed or
* 2. input ended and no writing is possible */
@ -494,8 +494,8 @@ static MIO_INLINE void handle_event (mio_t* mio, mio_dev_t* dev, int events, int
* halt the device. this check is performed after
* EPOLLIN or EPOLLOUT check because EPOLLERR or EPOLLHUP
* can be set together with EPOLLIN or EPOLLOUT. */
dev->dev_capa |= MIO_DEV_CAPA_IN_CLOSED | MIO_DEV_CAPA_OUT_CLOSED;
dev->dev_capa |= MIO_DEV_CAPA_RENEW_REQUIRED;
dev->dev_cap |= MIO_DEV_CAP_IN_CLOSED | MIO_DEV_CAP_OUT_CLOSED;
dev->dev_cap |= MIO_DEV_CAP_RENEW_REQUIRED;
}
else if (dev && rdhup)
{
@ -506,13 +506,13 @@ static MIO_INLINE void handle_event (mio_t* mio, mio_dev_t* dev, int events, int
}
else
{
dev->dev_capa |= MIO_DEV_CAPA_IN_CLOSED | MIO_DEV_CAPA_OUT_CLOSED;
dev->dev_capa |= MIO_DEV_CAPA_RENEW_REQUIRED;
dev->dev_cap |= MIO_DEV_CAP_IN_CLOSED | MIO_DEV_CAP_OUT_CLOSED;
dev->dev_cap |= MIO_DEV_CAP_RENEW_REQUIRED;
}
}
if ((dev->dev_capa & MIO_DEV_CAPA_IN_CLOSED) &&
(dev->dev_capa & MIO_DEV_CAPA_OUT_CLOSED))
if ((dev->dev_cap & MIO_DEV_CAP_IN_CLOSED) &&
(dev->dev_cap & MIO_DEV_CAP_OUT_CLOSED))
{
mio_dev_halt (dev);
dev = MIO_NULL;
@ -520,7 +520,7 @@ static MIO_INLINE void handle_event (mio_t* mio, mio_dev_t* dev, int events, int
}
skip_evcb:
if (dev && (dev->dev_capa & MIO_DEV_CAPA_RENEW_REQUIRED) && mio_dev_watch(dev, MIO_DEV_WATCH_RENEW, 0) <= -1)
if (dev && (dev->dev_cap & MIO_DEV_CAP_RENEW_REQUIRED) && mio_dev_watch(dev, MIO_DEV_WATCH_RENEW, 0) <= -1)
{
mio_dev_halt (dev);
dev = MIO_NULL;
@ -630,7 +630,7 @@ mio_dev_t* mio_makedev (mio_t* mio, mio_oow_t dev_size, mio_dev_mth_t* dev_mth,
dev->dev_size = dev_size;
/* default capability. dev->dev_mth->make() can change this.
* mio_dev_watch() is affected by the capability change. */
dev->dev_capa = MIO_DEV_CAPA_IN | MIO_DEV_CAPA_OUT;
dev->dev_cap = MIO_DEV_CAP_IN | MIO_DEV_CAP_OUT;
dev->dev_mth = dev_mth;
dev->dev_evcb = dev_evcb;
MIO_INIT_NTIME (&dev->rtmout, 0, 0);
@ -654,15 +654,15 @@ mio_dev_t* mio_makedev (mio_t* mio, mio_oow_t dev_size, mio_dev_mth_t* dev_mth,
/* set some internal capability bits according to the capabilities
* removed by the device making callback for convenience sake. */
dev->dev_capa &= MIO_DEV_CAPA_ALL_MASK; /* keep valid capability bits only. drop all internal-use bits */
if (!(dev->dev_capa & MIO_DEV_CAPA_IN)) dev->dev_capa |= MIO_DEV_CAPA_IN_CLOSED;
if (!(dev->dev_capa & MIO_DEV_CAPA_OUT)) dev->dev_capa |= MIO_DEV_CAPA_OUT_CLOSED;
dev->dev_cap &= MIO_DEV_CAP_ALL_MASK; /* keep valid capability bits only. drop all internal-use bits */
if (!(dev->dev_cap & MIO_DEV_CAP_IN)) dev->dev_cap |= MIO_DEV_CAP_IN_CLOSED;
if (!(dev->dev_cap & MIO_DEV_CAP_OUT)) dev->dev_cap |= MIO_DEV_CAP_OUT_CLOSED;
if (mio_dev_watch(dev, MIO_DEV_WATCH_START, 0) <= -1) goto oops_after_make;
/* and place the new device object at the back of the active device list */
APPEND_DEVICE_TO_LIST (&mio->actdev, dev);
dev->dev_capa |= MIO_DEV_CAPA_ACTIVE;
dev->dev_cap |= MIO_DEV_CAP_ACTIVE;
return dev;
@ -702,29 +702,29 @@ static int kill_and_free_device (mio_dev_t* dev, int force)
{
mio_t* mio = dev->mio;
MIO_ASSERT (mio, !(dev->dev_capa & MIO_DEV_CAPA_ACTIVE));
MIO_ASSERT (mio, !(dev->dev_capa & MIO_DEV_CAPA_HALTED));
MIO_ASSERT (mio, !(dev->dev_cap & MIO_DEV_CAP_ACTIVE));
MIO_ASSERT (mio, !(dev->dev_cap & MIO_DEV_CAP_HALTED));
if (dev->dev_mth->kill(dev, force) <= -1)
{
if (force >= 2) goto free_device;
if (!(dev->dev_capa & MIO_DEV_CAPA_ZOMBIE))
if (!(dev->dev_cap & MIO_DEV_CAP_ZOMBIE))
{
APPEND_DEVICE_TO_LIST (&mio->zmbdev, dev);
dev->dev_capa |= MIO_DEV_CAPA_ZOMBIE;
dev->dev_cap |= MIO_DEV_CAP_ZOMBIE;
}
return -1;
}
free_device:
if (dev->dev_capa & MIO_DEV_CAPA_ZOMBIE)
if (dev->dev_cap & MIO_DEV_CAP_ZOMBIE)
{
/* detach it from the zombie device list */
UNLINK_DEVICE_FROM_LIST (&mio->zmbdev, dev);
dev->dev_capa &= ~MIO_DEV_CAPA_ZOMBIE;
dev->dev_cap &= ~MIO_DEV_CAP_ZOMBIE;
}
mio_freemem (mio, dev);
@ -735,7 +735,7 @@ static void kill_zombie_job_handler (mio_t* mio, const mio_ntime_t* now, mio_tmr
{
mio_dev_t* dev = (mio_dev_t*)job->ctx;
MIO_ASSERT (mio, dev->dev_capa & MIO_DEV_CAPA_ZOMBIE);
MIO_ASSERT (mio, dev->dev_cap & MIO_DEV_CAP_ZOMBIE);
if (kill_and_free_device(dev, 0) <= -1)
{
@ -779,7 +779,7 @@ void mio_killdev (mio_t* mio, mio_dev_t* dev)
{
MIO_ASSERT (mio, mio == dev->mio);
if (dev->dev_capa & MIO_DEV_CAPA_ZOMBIE)
if (dev->dev_cap & MIO_DEV_CAP_ZOMBIE)
{
MIO_ASSERT (mio, MIO_WQ_ISEMPTY(&dev->wq));
MIO_ASSERT (mio, dev->cw_count == 0);
@ -819,18 +819,18 @@ void mio_killdev (mio_t* mio, mio_dev_t* dev)
mio_freemem (mio, q);
}
if (dev->dev_capa & MIO_DEV_CAPA_HALTED)
if (dev->dev_cap & MIO_DEV_CAP_HALTED)
{
/* this device is in the halted state.
* unlink it from the halted device list */
UNLINK_DEVICE_FROM_LIST (&mio->hltdev, dev);
dev->dev_capa &= ~MIO_DEV_CAPA_HALTED;
dev->dev_cap &= ~MIO_DEV_CAP_HALTED;
}
else
{
MIO_ASSERT (mio, dev->dev_capa & MIO_DEV_CAPA_ACTIVE);
MIO_ASSERT (mio, dev->dev_cap & MIO_DEV_CAP_ACTIVE);
UNLINK_DEVICE_FROM_LIST (&mio->actdev, dev);
dev->dev_capa &= ~MIO_DEV_CAPA_ACTIVE;
dev->dev_cap &= ~MIO_DEV_CAP_ACTIVE;
}
mio_dev_watch (dev, MIO_DEV_WATCH_STOP, 0);
@ -838,7 +838,7 @@ void mio_killdev (mio_t* mio, mio_dev_t* dev)
kill_device:
if (kill_and_free_device(dev, 0) <= -1)
{
MIO_ASSERT (mio, dev->dev_capa & MIO_DEV_CAPA_ZOMBIE);
MIO_ASSERT (mio, dev->dev_cap & MIO_DEV_CAP_ZOMBIE);
if (schedule_kill_zombie_job (dev) <= -1)
{
/* i have to choice but to free up the devide by force */
@ -861,15 +861,15 @@ void mio_dev_halt (mio_dev_t* dev)
{
mio_t* mio = dev->mio;
if (dev->dev_capa & MIO_DEV_CAPA_ACTIVE)
if (dev->dev_cap & MIO_DEV_CAP_ACTIVE)
{
/* delink the device object from the active device list */
UNLINK_DEVICE_FROM_LIST (&mio->actdev, dev);
dev->dev_capa &= ~MIO_DEV_CAPA_ACTIVE;
dev->dev_cap &= ~MIO_DEV_CAP_ACTIVE;
/* place it at the back of the halted device list */
APPEND_DEVICE_TO_LIST (&mio->hltdev, dev);
dev->dev_capa |= MIO_DEV_CAPA_HALTED;
dev->dev_cap |= MIO_DEV_CAP_HALTED;
}
}
@ -890,21 +890,21 @@ int mio_dev_watch (mio_dev_t* dev, mio_dev_watch_cmd_t cmd, int events)
{
mio_t* mio = dev->mio;
int mux_cmd;
int dev_capa;
int dev_cap;
/* the virtual device doesn't perform actual I/O.
* it's different from not hanving MIO_DEV_CAPA_IN and MIO_DEV_CAPA_OUT.
* it's different from not hanving MIO_DEV_CAP_IN and MIO_DEV_CAP_OUT.
* a non-virtual device without the capabilities still gets attention
* of the system multiplexer for hangup and error. */
if (dev->dev_capa & MIO_DEV_CAPA_VIRTUAL) return 0;
if (dev->dev_cap & MIO_DEV_CAP_VIRTUAL) return 0;
/*ev.data.ptr = dev;*/
switch (cmd)
{
case MIO_DEV_WATCH_START:
/* request input watching when a device is started.
* if the device is set with MIO_DEV_CAPA_IN_DISABLED and/or
* is not set with MIO_DEV_CAPA_IN, input wathcing is excluded
* if the device is set with MIO_DEV_CAP_IN_DISABLED and/or
* is not set with MIO_DEV_CAP_IN, input wathcing is excluded
* after this 'switch' block */
events = MIO_DEV_EVENT_IN;
mux_cmd = MIO_SYS_MUX_CMD_INSERT;
@ -932,37 +932,37 @@ int mio_dev_watch (mio_dev_t* dev, mio_dev_watch_cmd_t cmd, int events)
return -1;
}
dev_capa = dev->dev_capa;
dev_capa &= ~(DEV_CAPA_ALL_WATCHED);
dev_cap = dev->dev_cap;
dev_cap &= ~(DEV_CAP_ALL_WATCHED);
/* this function honors MIO_DEV_EVENT_IN and MIO_DEV_EVENT_OUT only
* as valid input event bits. it intends to provide simple abstraction
* by reducing the variety of event bits that the caller has to handle. */
if ((events & MIO_DEV_EVENT_IN) && !(dev->dev_capa & (MIO_DEV_CAPA_IN_CLOSED | MIO_DEV_CAPA_IN_DISABLED)))
if ((events & MIO_DEV_EVENT_IN) && !(dev->dev_cap & (MIO_DEV_CAP_IN_CLOSED | MIO_DEV_CAP_IN_DISABLED)))
{
if (dev->dev_capa & MIO_DEV_CAPA_IN)
if (dev->dev_cap & MIO_DEV_CAP_IN)
{
if (dev->dev_capa & MIO_DEV_CAPA_PRI) dev_capa |= MIO_DEV_CAPA_PRI_WATCHED;
dev_capa |= MIO_DEV_CAPA_IN_WATCHED;
if (dev->dev_cap & MIO_DEV_CAP_PRI) dev_cap |= MIO_DEV_CAP_PRI_WATCHED;
dev_cap |= MIO_DEV_CAP_IN_WATCHED;
}
}
if ((events & MIO_DEV_EVENT_OUT) && !(dev->dev_capa & MIO_DEV_CAPA_OUT_CLOSED))
if ((events & MIO_DEV_EVENT_OUT) && !(dev->dev_cap & MIO_DEV_CAP_OUT_CLOSED))
{
if (dev->dev_capa & MIO_DEV_CAPA_OUT) dev_capa |= MIO_DEV_CAPA_OUT_WATCHED;
if (dev->dev_cap & MIO_DEV_CAP_OUT) dev_cap |= MIO_DEV_CAP_OUT_WATCHED;
}
if (mux_cmd == MIO_SYS_MUX_CMD_UPDATE && (dev_capa & DEV_CAPA_ALL_WATCHED) == (dev->dev_capa & DEV_CAPA_ALL_WATCHED))
if (mux_cmd == MIO_SYS_MUX_CMD_UPDATE && (dev_cap & DEV_CAP_ALL_WATCHED) == (dev->dev_cap & DEV_CAP_ALL_WATCHED))
{
/* no change in the device capacity. skip calling epoll_ctl */
}
else
{
if (mio_sys_ctrlmux(mio, mux_cmd, dev, dev_capa) <= -1) return -1;
if (mio_sys_ctrlmux(mio, mux_cmd, dev, dev_cap) <= -1) return -1;
}
dev->dev_capa = dev_capa;
dev->dev_cap = dev_cap;
return 0;
}
@ -985,7 +985,7 @@ static int __dev_read (mio_dev_t* dev, int enabled, const mio_ntime_t* tmout, vo
{
mio_t* mio = dev->mio;
if (dev->dev_capa & MIO_DEV_CAPA_IN_CLOSED)
if (dev->dev_cap & MIO_DEV_CAP_IN_CLOSED)
{
mio_seterrbfmt (mio, MIO_ENOCAPA, "unable to read closed device");
return -1;
@ -993,16 +993,16 @@ static int __dev_read (mio_dev_t* dev, int enabled, const mio_ntime_t* tmout, vo
if (enabled)
{
dev->dev_capa &= ~MIO_DEV_CAPA_IN_DISABLED;
if (!(dev->dev_capa & MIO_DEV_CAPA_IN_WATCHED)) goto renew_watch_now;
dev->dev_cap &= ~MIO_DEV_CAP_IN_DISABLED;
if (!(dev->dev_cap & MIO_DEV_CAP_IN_WATCHED)) goto renew_watch_now;
}
else
{
dev->dev_capa |= MIO_DEV_CAPA_IN_DISABLED;
if ((dev->dev_capa & MIO_DEV_CAPA_IN_WATCHED)) goto renew_watch_now;
dev->dev_cap |= MIO_DEV_CAP_IN_DISABLED;
if ((dev->dev_cap & MIO_DEV_CAP_IN_WATCHED)) goto renew_watch_now;
}
dev->dev_capa |= MIO_DEV_CAPA_RENEW_REQUIRED;
dev->dev_cap |= MIO_DEV_CAP_RENEW_REQUIRED;
goto update_timer;
renew_watch_now:
@ -1078,7 +1078,7 @@ static int __dev_write (mio_dev_t* dev, const void* data, mio_iolen_t len, const
mio_oow_t cwq_extra_aligned, cwqfl_index;
int x;
if (dev->dev_capa & MIO_DEV_CAPA_OUT_CLOSED)
if (dev->dev_cap & MIO_DEV_CAP_OUT_CLOSED)
{
mio_seterrbfmt (mio, MIO_ENOCAPA, "unable to write to closed device");
return -1;
@ -1094,7 +1094,7 @@ static int __dev_write (mio_dev_t* dev, const void* data, mio_iolen_t len, const
goto enqueue_data;
}
if (dev->dev_capa & MIO_DEV_CAPA_STREAM)
if (dev->dev_cap & MIO_DEV_CAP_STREAM)
{
/* use the do..while() loop to be able to send a zero-length data */
do
@ -1123,7 +1123,7 @@ static int __dev_write (mio_dev_t* dev, const void* data, mio_iolen_t len, const
if (len <= 0) /* original length */
{
/* a zero-length writing request is to close the writing end */
dev->dev_capa |= MIO_DEV_CAPA_OUT_CLOSED;
dev->dev_cap |= MIO_DEV_CAP_OUT_CLOSED;
}
/* if i trigger the write completion callback here, the performance
@ -1152,15 +1152,12 @@ static int __dev_write (mio_dev_t* dev, const void* data, mio_iolen_t len, const
return 1; /* written immediately and called on_write callback */
enqueue_data:
#if 0
/* TODO: DO WE REALLY NEED THIS CAPABILITY CHECK? If not, undefine MIO_DEV_CAPA_OUT_QUEUED */
if (!(dev->dev_capa & MIO_DEV_CAPA_OUT_QUEUED))
if (dev->dev_cap & MIO_DEV_CAP_OUT_UNQUEUEABLE)
{
/* writing queuing is not requested. so return failure */
mio_seterrbfmt (mio, MIO_ENOCAPA, "device incapable of queuing");
return -1;
}
#endif
/* queue the remaining data*/
q = (mio_wq_t*)mio_allocmem(mio, MIO_SIZEOF(*q) + (dstaddr? dstaddr->len: 0) + urem);
@ -1206,7 +1203,7 @@ enqueue_data:
}
MIO_WQ_ENQ (&dev->wq, q);
if (!(dev->dev_capa & MIO_DEV_CAPA_OUT_WATCHED))
if (!(dev->dev_cap & MIO_DEV_CAP_OUT_WATCHED))
{
/* if output is not being watched, arrange to do so */
if (mio_dev_watch(dev, MIO_DEV_WATCH_RENEW, 0) <= -1)

View File

@ -317,7 +317,7 @@ struct mio_wq_t
#define MIO_DEV_HEADERS \
mio_t* mio; \
mio_oow_t dev_size; \
int dev_capa; \
int dev_cap; \
mio_dev_mth_t* dev_mth; \
mio_dev_evcb_t* dev_evcb; \
mio_ntime_t rtmout; \
@ -332,32 +332,32 @@ struct mio_dev_t
MIO_DEV_HEADERS;
};
enum mio_dev_capa_t
enum mio_dev_cap_t
{
MIO_DEV_CAPA_VIRTUAL = (1 << 0),
MIO_DEV_CAPA_IN = (1 << 1),
MIO_DEV_CAPA_OUT = (1 << 2),
MIO_DEV_CAPA_PRI = (1 << 3), /* meaningful only if #MIO_DEV_CAPA_IN is set */
MIO_DEV_CAPA_STREAM = (1 << 4),
MIO_DEV_CAPA_IN_DISABLED = (1 << 5),
MIO_DEV_CAPA_OUT_QUEUED = (1 << 6),
MIO_DEV_CAPA_ALL_MASK = (MIO_DEV_CAPA_VIRTUAL | MIO_DEV_CAPA_IN | MIO_DEV_CAPA_OUT | MIO_DEV_CAPA_PRI | MIO_DEV_CAPA_STREAM | MIO_DEV_CAPA_IN_DISABLED | MIO_DEV_CAPA_OUT_QUEUED),
MIO_DEV_CAP_VIRTUAL = (1 << 0),
MIO_DEV_CAP_IN = (1 << 1),
MIO_DEV_CAP_OUT = (1 << 2),
MIO_DEV_CAP_PRI = (1 << 3), /* meaningful only if #MIO_DEV_CAP_IN is set */
MIO_DEV_CAP_STREAM = (1 << 4),
MIO_DEV_CAP_IN_DISABLED = (1 << 5),
MIO_DEV_CAP_OUT_UNQUEUEABLE = (1 << 6),
MIO_DEV_CAP_ALL_MASK = (MIO_DEV_CAP_VIRTUAL | MIO_DEV_CAP_IN | MIO_DEV_CAP_OUT | MIO_DEV_CAP_PRI | MIO_DEV_CAP_STREAM | MIO_DEV_CAP_IN_DISABLED | MIO_DEV_CAP_OUT_UNQUEUEABLE),
/* -------------------------------------------------------------------
* the followings bits are for internal use only.
* never set these bits to the dev_capa field.
* never set these bits to the dev_cap field.
* ------------------------------------------------------------------- */
MIO_DEV_CAPA_IN_CLOSED = (1 << 10),
MIO_DEV_CAPA_OUT_CLOSED = (1 << 11),
MIO_DEV_CAPA_IN_WATCHED = (1 << 12),
MIO_DEV_CAPA_OUT_WATCHED = (1 << 13),
MIO_DEV_CAPA_PRI_WATCHED = (1 << 14), /**< can be set only if MIO_DEV_CAPA_IN_WATCHED is set */
MIO_DEV_CAPA_ACTIVE = (1 << 15),
MIO_DEV_CAPA_HALTED = (1 << 16),
MIO_DEV_CAPA_ZOMBIE = (1 << 17),
MIO_DEV_CAPA_RENEW_REQUIRED = (1 << 18)
MIO_DEV_CAP_IN_CLOSED = (1 << 10),
MIO_DEV_CAP_OUT_CLOSED = (1 << 11),
MIO_DEV_CAP_IN_WATCHED = (1 << 12),
MIO_DEV_CAP_OUT_WATCHED = (1 << 13),
MIO_DEV_CAP_PRI_WATCHED = (1 << 14), /**< can be set only if MIO_DEV_CAP_IN_WATCHED is set */
MIO_DEV_CAP_ACTIVE = (1 << 15),
MIO_DEV_CAP_HALTED = (1 << 16),
MIO_DEV_CAP_ZOMBIE = (1 << 17),
MIO_DEV_CAP_RENEW_REQUIRED = (1 << 18)
};
typedef enum mio_dev_capa_t mio_dev_capa_t;
typedef enum mio_dev_cap_t mio_dev_cap_t;
enum mio_dev_watch_cmd_t
{
@ -693,6 +693,10 @@ MIO_EXPORT void mio_killdev (
mio_dev_t* dev
);
MIO_EXPORT void mio_dev_halt (
mio_dev_t* dev
);
MIO_EXPORT int mio_dev_ioctl (
mio_dev_t* dev,
int cmd,
@ -744,9 +748,6 @@ MIO_EXPORT int mio_dev_timedwrite (
const mio_devaddr_t* dstaddr
);
MIO_EXPORT void mio_dev_halt (
mio_dev_t* dev
);
/* =========================================================================
* TIMER MANAGEMENT

View File

@ -59,7 +59,7 @@ void mio_sys_finimux (mio_t* mio)
#endif
}
int mio_sys_ctrlmux (mio_t* mio, mio_sys_mux_cmd_t cmd, mio_dev_t* dev, int dev_capa)
int mio_sys_ctrlmux (mio_t* mio, mio_sys_mux_cmd_t cmd, mio_dev_t* dev, int dev_cap)
{
#if defined(USE_POLL)
mio_sys_mux_t* mux = &mio->sysdep->mux;
@ -137,8 +137,8 @@ int mio_sys_ctrlmux (mio_t* mio, mio_sys_mux_cmd_t cmd, mio_dev_t* dev, int dev_
mux->pd.pfd[idx].fd = hnd;
mux->pd.pfd[idx].events = 0;
if (dev_capa & MIO_DEV_CAPA_IN_WATCHED) mux->pd.pfd[idx].events |= POLLIN;
if (dev_capa & MIO_DEV_CAPA_OUT_WATCHED) mux->pd.pfd[idx].events |= POLLOUT;
if (dev_cap & MIO_DEV_CAP_IN_WATCHED) mux->pd.pfd[idx].events |= POLLIN;
if (dev_cap & MIO_DEV_CAP_OUT_WATCHED) mux->pd.pfd[idx].events |= POLLOUT;
mux->pd.pfd[idx].revents = 0;
mux->pd.dptr[idx] = dev;
@ -149,8 +149,8 @@ int mio_sys_ctrlmux (mio_t* mio, mio_sys_mux_cmd_t cmd, mio_dev_t* dev, int dev_
case MIO_SYS_MUX_CMD_UPDATE:
MIO_ASSERT (mio, mux->pd.dptr[idx] == dev);
mux->pd.pfd[idx].events = 0;
if (dev_capa & MIO_DEV_CAPA_IN_WATCHED) mux->pd.pfd[idx].events |= POLLIN;
if (dev_capa & MIO_DEV_CAPA_OUT_WATCHED) mux->pd.pfd[idx].events |= POLLOUT;
if (dev_cap & MIO_DEV_CAP_IN_WATCHED) mux->pd.pfd[idx].events |= POLLIN;
if (dev_cap & MIO_DEV_CAP_OUT_WATCHED) mux->pd.pfd[idx].events |= POLLOUT;
return 0;
case MIO_SYS_MUX_CMD_DELETE:
@ -194,16 +194,16 @@ int mio_sys_ctrlmux (mio_t* mio, mio_sys_mux_cmd_t cmd, mio_dev_t* dev, int dev_
ev.data.ptr = dev;
ev.events = EPOLLHUP | EPOLLERR /*| EPOLLET*/;
if (dev_capa & MIO_DEV_CAPA_IN_WATCHED)
if (dev_cap & MIO_DEV_CAP_IN_WATCHED)
{
ev.events |= EPOLLIN;
#if defined(EPOLLRDHUP)
ev.events |= EPOLLRDHUP;
#endif
if (dev_capa & MIO_DEV_CAPA_PRI_WATCHED) ev.events |= EPOLLPRI;
if (dev_cap & MIO_DEV_CAP_PRI_WATCHED) ev.events |= EPOLLPRI;
}
if (dev_capa & MIO_DEV_CAPA_OUT_WATCHED) ev.events |= EPOLLOUT;
if (dev_cap & MIO_DEV_CAP_OUT_WATCHED) ev.events |= EPOLLOUT;
if (epoll_ctl(mux->hnd, epoll_cmd[cmd], dev->dev_mth->getsyshnd(dev), &ev) == -1)
{

View File

@ -675,7 +675,7 @@ MIO_INLINE int mio_conv_bchars_to_uchars_with_cmgr (
break;
}
n = cmgr->bctouc (p, mlen, q);
n = cmgr->bctouc(p, mlen, q);
if (n == 0)
{
/* invalid sequence */
@ -731,7 +731,7 @@ MIO_INLINE int mio_conv_bchars_to_uchars_with_cmgr (
{
mio_oow_t n;
n = cmgr->bctouc (p, mlen, &w);
n = cmgr->bctouc(p, mlen, &w);
if (n == 0)
{
/* invalid sequence */