defined MIO_FEATURE_MUX and MIO_FEATURE_LOG

This commit is contained in:
hyung-hwan 2021-07-17 20:05:16 +00:00
parent b0040b8454
commit 487a0d19a0
11 changed files with 56 additions and 19 deletions

View File

@ -341,7 +341,7 @@ int main (int argc, char* argv[])
mio_dev_sck_connect_t tcp_conn; mio_dev_sck_connect_t tcp_conn;
tcp_server_t* ts; 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) if (!mio)
{ {
printf ("Cannot open mio\n"); printf ("Cannot open mio\n");

View File

@ -1025,7 +1025,7 @@ int main (int argc, char* argv[])
SSL_library_init (); SSL_library_init ();
#endif #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) if (!mio)
{ {
printf ("Cannot open mio\n"); printf ("Cannot open mio\n");

View File

@ -215,7 +215,7 @@ int main (int argc, char* argv[])
fprintf (stderr, "Usage: %s ipaddr:port\n", argv[0]); fprintf (stderr, "Usage: %s ipaddr:port\n", argv[0]);
return -1; 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) if (!mio)
{ {
printf ("Cannot open mio\n"); printf ("Cannot open mio\n");

View File

@ -161,7 +161,7 @@ int main (int argc, char* argv[])
if (strcmp(argv[i], "--line-comment") == 0) o |= MIO_JSON_LINE_COMMENT; 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) if (!mio)
{ {
printf ("Cannot open mio\n"); printf ("Cannot open mio\n");

View File

@ -73,7 +73,7 @@ int main (int argc, char* argv[])
return -1; 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) if (!mio)
{ {
printf ("Cannot open mio\n"); printf ("Cannot open mio\n");

View File

@ -218,7 +218,7 @@ void* thr_func (void* arg)
mio_svc_htts_t* htts = MIO_NULL; mio_svc_htts_t* htts = MIO_NULL;
mio_dev_sck_bind_t htts_bind_info; 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) if (!mio)
{ {
printf ("Cannot open mio\n"); printf ("Cannot open mio\n");
@ -570,7 +570,7 @@ int main (int argc, char* argv[])
XX_MQ_INIT (&xx_mq); XX_MQ_INIT (&xx_mq);
xx_tmridx = MIO_TMRIDX_INVALID; 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) if (!mio)
{ {
printf ("Cannot open mio\n"); printf ("Cannot open mio\n");

View File

@ -1527,6 +1527,10 @@ mio_ooi_t mio_logbfmtv (mio_t* mio, mio_bitmask_t mask, const mio_bch_t* fmt, va
int x; int x;
mio_fmtout_t fo; 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 (mio->log.default_type_mask & MIO_LOG_ALL_TYPES)
{ {
/* if a type is given, it's not untyped any more. /* 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; int x;
mio_fmtout_t fo; 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 (mio->log.default_type_mask & MIO_LOG_ALL_TYPES)
{ {
/* if a type is given, it's not untyped any more. /* if a type is given, it's not untyped any more.

View File

@ -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; 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); mio = (mio_t*)MIO_MMGR_ALLOC(mmgr, MIO_SIZEOF(mio_t) + xtnsize);
if (mio) 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); if (errinfo) mio_geterrinf (mio, errinfo);
MIO_MMGR_FREE (mmgr, mio); MIO_MMGR_FREE (mmgr, mio);
@ -104,7 +104,7 @@ void mio_close (mio_t* mio)
MIO_MMGR_FREE (mio->_mmgr, 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; 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->_instsize = MIO_SIZEOF(*mio);
mio->_mmgr = mmgr; mio->_mmgr = mmgr;
mio->_cmgr = cmgr; mio->_cmgr = cmgr;
mio->_features = features;
/* initialize data for logging support */ /* initialize data for logging support */
mio->option.log_mask = MIO_LOG_ALL_LEVELS | MIO_LOG_ALL_TYPES; 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; int ret = 0;
@ -790,14 +791,23 @@ int mio_exec (mio_t* mio)
return ret; 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) 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->stopreq = stopreq;
mio_sys_intrmux (mio); mio_sys_intrmux (mio);
} }
int mio_loop (mio_t* 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; if (MIO_DEVL_IS_EMPTY(&mio->actdev)) return 0;
mio->stopreq = MIO_STOPREQ_NONE; 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)) 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 */ /* you can do other things here */
} }

View File

@ -120,6 +120,15 @@ struct mio_errinf_t
}; };
typedef struct mio_errinf_t 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 enum mio_option_t
{ {
MIO_TRAIT, MIO_TRAIT,
@ -634,6 +643,8 @@ struct mio_t
mio_oow_t len; mio_oow_t len;
} errmsg; } errmsg;
mio_bitmask_t _features;
unsigned short int _shuterr; unsigned short int _shuterr;
unsigned short int _fini_in_progress; unsigned short int _fini_in_progress;
@ -699,6 +710,7 @@ MIO_EXPORT mio_t* mio_open (
mio_mmgr_t* mmgr, mio_mmgr_t* mmgr,
mio_oow_t xtnsize, mio_oow_t xtnsize,
mio_cmgr_t* cmgr, mio_cmgr_t* cmgr,
mio_bitmask_t features,
mio_oow_t tmrcapa, /**< initial timer capacity */ mio_oow_t tmrcapa, /**< initial timer capacity */
mio_errinf_t* errinf mio_errinf_t* errinf
); );
@ -711,6 +723,7 @@ MIO_EXPORT int mio_init (
mio_t* mio, mio_t* mio,
mio_mmgr_t* mmgr, mio_mmgr_t* mmgr,
mio_cmgr_t* cmgr, mio_cmgr_t* cmgr,
mio_bitmask_t features,
mio_oow_t tmrcapa mio_oow_t tmrcapa
); );

View File

@ -157,8 +157,8 @@ void mio_sys_finimux (mio_t* mio)
void mio_sys_intrmux (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 */ /* 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); if (mux->ctrlp[1] != MIO_SYSHND_INVALID) write (mux->ctrlp[1], "Q", 1);
} }

View File

@ -35,11 +35,17 @@ int mio_sys_init (mio_t* mio)
mio->sysdep = (mio_sys_t*)mio_callocmem(mio, MIO_SIZEOF(*mio->sysdep)); mio->sysdep = (mio_sys_t*)mio_callocmem(mio, MIO_SIZEOF(*mio->sysdep));
if (!mio->sysdep) return -1; if (!mio->sysdep) return -1;
if (mio_sys_initlog(mio) <= -1) goto oops; if (mio->_features & MIO_FEATURE_LOG)
log_inited = 1; {
if (mio_sys_initlog(mio) <= -1) goto oops;
log_inited = 1;
}
if (mio_sys_initmux(mio) <= -1) goto oops; if (mio->_features & MIO_FEATURE_MUX)
mux_inited = 1; {
if (mio_sys_initmux(mio) <= -1) goto oops;
mux_inited = 1;
}
if (mio_sys_inittime(mio) <= -1) goto oops; if (mio_sys_inittime(mio) <= -1) goto oops;
time_inited = 1; time_inited = 1;
@ -61,8 +67,8 @@ oops:
void mio_sys_fini (mio_t* mio) void mio_sys_fini (mio_t* mio)
{ {
mio_sys_finitime (mio); mio_sys_finitime (mio);
mio_sys_finimux (mio); if (mio->_features & MIO_FEATURE_MUX) mio_sys_finimux (mio);
mio_sys_finilog (mio); if (mio->_features & MIO_FEATURE_LOG) mio_sys_finilog (mio);
mio_freemem (mio, mio->sysdep); mio_freemem (mio, mio->sysdep);
mio->sysdep = MIO_NULL; mio->sysdep = MIO_NULL;