From 487a0d19a034e3e8e197b0db85513c6fbdabed32 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Sat, 17 Jul 2021 20:05:16 +0000 Subject: [PATCH] defined MIO_FEATURE_MUX and MIO_FEATURE_LOG --- mio/bin/execd.c | 2 +- mio/bin/t01.c | 2 +- mio/bin/t02.c | 2 +- mio/bin/t03.c | 2 +- mio/bin/t04.c | 2 +- mio/bin/t06.c | 4 ++-- mio/lib/fmt.c | 8 ++++++++ mio/lib/mio.c | 20 +++++++++++++++----- mio/lib/mio.h | 13 +++++++++++++ mio/lib/sys-mux.c | 2 +- mio/lib/sys.c | 18 ++++++++++++------ 11 files changed, 56 insertions(+), 19 deletions(-) diff --git a/mio/bin/execd.c b/mio/bin/execd.c index 96328c3..935cf12 100644 --- a/mio/bin/execd.c +++ b/mio/bin/execd.c @@ -341,7 +341,7 @@ int main (int argc, char* argv[]) mio_dev_sck_connect_t tcp_conn; tcp_server_t* ts; - mio = mio_open(&mmgr, 0, MIO_NULL, 512, MIO_NULL); + mio = mio_open(&mmgr, 0, MIO_NULL, MIO_FEATURE_ALL, 512, MIO_NULL); if (!mio) { printf ("Cannot open mio\n"); diff --git a/mio/bin/t01.c b/mio/bin/t01.c index c5c46dc..0829a02 100644 --- a/mio/bin/t01.c +++ b/mio/bin/t01.c @@ -1025,7 +1025,7 @@ int main (int argc, char* argv[]) SSL_library_init (); #endif - mio = mio_open(&mmgr, 0, MIO_NULL, 512, MIO_NULL); + mio = mio_open(&mmgr, 0, MIO_NULL, MIO_FEATURE_ALL, 512, MIO_NULL); if (!mio) { printf ("Cannot open mio\n"); diff --git a/mio/bin/t02.c b/mio/bin/t02.c index 036a53c..bc2d6b2 100644 --- a/mio/bin/t02.c +++ b/mio/bin/t02.c @@ -215,7 +215,7 @@ int main (int argc, char* argv[]) fprintf (stderr, "Usage: %s ipaddr:port\n", argv[0]); return -1; } - mio = mio_open(&mmgr, 0, MIO_NULL, 512, MIO_NULL); + mio = mio_open(&mmgr, 0, MIO_NULL, MIO_FEATURE_ALL, 512, MIO_NULL); if (!mio) { printf ("Cannot open mio\n"); diff --git a/mio/bin/t03.c b/mio/bin/t03.c index e9aff40..f967d11 100644 --- a/mio/bin/t03.c +++ b/mio/bin/t03.c @@ -161,7 +161,7 @@ int main (int argc, char* argv[]) if (strcmp(argv[i], "--line-comment") == 0) o |= MIO_JSON_LINE_COMMENT; } - mio = mio_open(MIO_NULL, 0, MIO_NULL, 512, MIO_NULL); + mio = mio_open(MIO_NULL, 0, MIO_NULL, MIO_FEATURE_ALL, 512, MIO_NULL); if (!mio) { printf ("Cannot open mio\n"); diff --git a/mio/bin/t04.c b/mio/bin/t04.c index fe13a1b..fa332f7 100644 --- a/mio/bin/t04.c +++ b/mio/bin/t04.c @@ -73,7 +73,7 @@ int main (int argc, char* argv[]) return -1; } - mio = mio_open(MIO_NULL, 0, MIO_NULL, 512, MIO_NULL); + mio = mio_open(MIO_NULL, 0, MIO_NULL, MIO_FEATURE_ALL, 512, MIO_NULL); if (!mio) { printf ("Cannot open mio\n"); diff --git a/mio/bin/t06.c b/mio/bin/t06.c index ad27e33..ca8f6a0 100644 --- a/mio/bin/t06.c +++ b/mio/bin/t06.c @@ -218,7 +218,7 @@ void* thr_func (void* arg) mio_svc_htts_t* htts = MIO_NULL; mio_dev_sck_bind_t htts_bind_info; - mio = mio_open(MIO_NULL, 0, MIO_NULL, 512, MIO_NULL); + mio = mio_open(MIO_NULL, 0, MIO_NULL, MIO_FEATURE_ALL, 512, MIO_NULL); if (!mio) { printf ("Cannot open mio\n"); @@ -570,7 +570,7 @@ int main (int argc, char* argv[]) XX_MQ_INIT (&xx_mq); xx_tmridx = MIO_TMRIDX_INVALID; - mio = mio_open(MIO_NULL, 0, MIO_NULL, 512, MIO_NULL); + mio = mio_open(MIO_NULL, 0, MIO_NULL, MIO_FEATURE_ALL, 512, MIO_NULL); if (!mio) { printf ("Cannot open mio\n"); diff --git a/mio/lib/fmt.c b/mio/lib/fmt.c index c608fb6..d3aa796 100644 --- a/mio/lib/fmt.c +++ b/mio/lib/fmt.c @@ -1527,6 +1527,10 @@ mio_ooi_t mio_logbfmtv (mio_t* mio, mio_bitmask_t mask, const mio_bch_t* fmt, va int x; mio_fmtout_t fo; + /* there may internal log calls even if this feature is disabled. + * the explicit check is required */ + if (MIO_UNLIKELY(!(mio->_features & MIO_FEATURE_LOG))) return -1; + if (mio->log.default_type_mask & MIO_LOG_ALL_TYPES) { /* if a type is given, it's not untyped any more. @@ -1594,6 +1598,10 @@ mio_ooi_t mio_logufmtv (mio_t* mio, mio_bitmask_t mask, const mio_uch_t* fmt, va int x; mio_fmtout_t fo; + /* there may internal log calls even if this feature is disabled. + * the explicit check is required */ + if (MIO_UNLIKELY(!(mio->_features & MIO_FEATURE_LOG))) return -1; + if (mio->log.default_type_mask & MIO_LOG_ALL_TYPES) { /* if a type is given, it's not untyped any more. diff --git a/mio/lib/mio.c b/mio/lib/mio.c index a5f4398..5bd9f41 100644 --- a/mio/lib/mio.c +++ b/mio/lib/mio.c @@ -71,7 +71,7 @@ static mio_mmgr_t default_mmgr = /* ========================================================================= */ -mio_t* mio_open (mio_mmgr_t* mmgr, mio_oow_t xtnsize, mio_cmgr_t* cmgr, mio_oow_t tmrcapa, mio_errinf_t* errinfo) +mio_t* mio_open (mio_mmgr_t* mmgr, mio_oow_t xtnsize, mio_cmgr_t* cmgr, mio_bitmask_t features, mio_oow_t tmrcapa, mio_errinf_t* errinfo) { mio_t* mio; @@ -81,7 +81,7 @@ mio_t* mio_open (mio_mmgr_t* mmgr, mio_oow_t xtnsize, mio_cmgr_t* cmgr, mio_oow_ mio = (mio_t*)MIO_MMGR_ALLOC(mmgr, MIO_SIZEOF(mio_t) + xtnsize); if (mio) { - if (mio_init(mio, mmgr, cmgr, tmrcapa) <= -1) + if (mio_init(mio, mmgr, cmgr, features, tmrcapa) <= -1) { if (errinfo) mio_geterrinf (mio, errinfo); MIO_MMGR_FREE (mmgr, mio); @@ -104,7 +104,7 @@ void mio_close (mio_t* mio) MIO_MMGR_FREE (mio->_mmgr, mio); } -int mio_init (mio_t* mio, mio_mmgr_t* mmgr, mio_cmgr_t* cmgr, mio_oow_t tmrcapa) +int mio_init (mio_t* mio, mio_mmgr_t* mmgr, mio_cmgr_t* cmgr, mio_bitmask_t features, mio_oow_t tmrcapa) { int sys_inited = 0; @@ -112,6 +112,7 @@ int mio_init (mio_t* mio, mio_mmgr_t* mmgr, mio_cmgr_t* cmgr, mio_oow_t tmrcapa) mio->_instsize = MIO_SIZEOF(*mio); mio->_mmgr = mmgr; mio->_cmgr = cmgr; + mio->_features = features; /* initialize data for logging support */ mio->option.log_mask = MIO_LOG_ALL_LEVELS | MIO_LOG_ALL_TYPES; @@ -744,7 +745,7 @@ static void kill_all_halted_devices (mio_t* mio) } } -int mio_exec (mio_t* mio) +static MIO_INLINE int __exec (mio_t* mio) { int ret = 0; @@ -790,14 +791,23 @@ int mio_exec (mio_t* mio) return ret; } +int mio_exec (mio_t* mio) +{ + MIO_ASSERT (mio, (MIO_FEATURE_ALL & MIO_FEATURE_MUX)); /* never call this if you disableed this feature */ + return __exec(mio); +} + void mio_stop (mio_t* mio, mio_stopreq_t stopreq) { + MIO_ASSERT (mio, (MIO_FEATURE_ALL & MIO_FEATURE_MUX)); /* never call this if you disableed this feature */ mio->stopreq = stopreq; mio_sys_intrmux (mio); } int mio_loop (mio_t* mio) { + MIO_ASSERT (mio, (MIO_FEATURE_ALL & MIO_FEATURE_MUX)); /* never call this if you disableed this feature */ + if (MIO_DEVL_IS_EMPTY(&mio->actdev)) return 0; mio->stopreq = MIO_STOPREQ_NONE; @@ -806,7 +816,7 @@ int mio_loop (mio_t* mio) while (mio->stopreq == MIO_STOPREQ_NONE && !MIO_DEVL_IS_EMPTY(&mio->actdev)) { - if (mio_exec(mio) <= -1) break; + if (__exec(mio) <= -1) break; /* you can do other things here */ } diff --git a/mio/lib/mio.h b/mio/lib/mio.h index 3eb32d5..0c86fce 100644 --- a/mio/lib/mio.h +++ b/mio/lib/mio.h @@ -120,6 +120,15 @@ struct mio_errinf_t }; typedef struct mio_errinf_t mio_errinf_t; +enum mio_feature_t +{ + MIO_FEATURE_LOG = ((mio_bitmask_t)1 << 0), + MIO_FEATURE_MUX = ((mio_bitmask_t)1 << 1), + + MIO_FEATURE_ALL = (MIO_FEATURE_LOG | MIO_FEATURE_MUX) +}; +typedef enum mio_feature_t mio_feature_t; + enum mio_option_t { MIO_TRAIT, @@ -634,6 +643,8 @@ struct mio_t mio_oow_t len; } errmsg; + mio_bitmask_t _features; + unsigned short int _shuterr; unsigned short int _fini_in_progress; @@ -699,6 +710,7 @@ MIO_EXPORT mio_t* mio_open ( mio_mmgr_t* mmgr, mio_oow_t xtnsize, mio_cmgr_t* cmgr, + mio_bitmask_t features, mio_oow_t tmrcapa, /**< initial timer capacity */ mio_errinf_t* errinf ); @@ -711,6 +723,7 @@ MIO_EXPORT int mio_init ( mio_t* mio, mio_mmgr_t* mmgr, mio_cmgr_t* cmgr, + mio_bitmask_t features, mio_oow_t tmrcapa ); diff --git a/mio/lib/sys-mux.c b/mio/lib/sys-mux.c index 1ea7e48..0882595 100644 --- a/mio/lib/sys-mux.c +++ b/mio/lib/sys-mux.c @@ -157,8 +157,8 @@ void mio_sys_finimux (mio_t* mio) void mio_sys_intrmux (mio_t* mio) { - mio_sys_mux_t* mux = &mio->sysdep->mux; /* for now, thie only use of the control pipe is to interrupt the multiplexer */ + mio_sys_mux_t* mux = &mio->sysdep->mux; if (mux->ctrlp[1] != MIO_SYSHND_INVALID) write (mux->ctrlp[1], "Q", 1); } diff --git a/mio/lib/sys.c b/mio/lib/sys.c index eef38b5..b7d220b 100644 --- a/mio/lib/sys.c +++ b/mio/lib/sys.c @@ -35,11 +35,17 @@ int mio_sys_init (mio_t* mio) mio->sysdep = (mio_sys_t*)mio_callocmem(mio, MIO_SIZEOF(*mio->sysdep)); if (!mio->sysdep) return -1; - if (mio_sys_initlog(mio) <= -1) goto oops; - log_inited = 1; + if (mio->_features & MIO_FEATURE_LOG) + { + if (mio_sys_initlog(mio) <= -1) goto oops; + log_inited = 1; + } - if (mio_sys_initmux(mio) <= -1) goto oops; - mux_inited = 1; + if (mio->_features & MIO_FEATURE_MUX) + { + if (mio_sys_initmux(mio) <= -1) goto oops; + mux_inited = 1; + } if (mio_sys_inittime(mio) <= -1) goto oops; time_inited = 1; @@ -61,8 +67,8 @@ oops: void mio_sys_fini (mio_t* mio) { mio_sys_finitime (mio); - mio_sys_finimux (mio); - mio_sys_finilog (mio); + if (mio->_features & MIO_FEATURE_MUX) mio_sys_finimux (mio); + if (mio->_features & MIO_FEATURE_LOG) mio_sys_finilog (mio); mio_freemem (mio, mio->sysdep); mio->sysdep = MIO_NULL;