renamed MIO_LOG_TARGET_B and MIO_LOG_TARGET_U to MIO_LOG_TARGET_BCSTR and MIO_LOG_TARGET_UCSTR respectively

This commit is contained in:
hyung-hwan 2021-07-19 19:04:02 +00:00
parent 9c84647015
commit 3803061baf
3 changed files with 85 additions and 16 deletions

View File

@ -226,7 +226,7 @@ void* thr_func (void* arg)
goto oops; goto oops;
} }
mio_setoption (mio, MIO_LOG_TARGET_B, "/dev/stderr"); mio_setoption (mio, MIO_LOG_TARGET_BCSTR, "/dev/stderr");
memset (&htts_bind_info, 0, MIO_SIZEOF(htts_bind_info)); memset (&htts_bind_info, 0, MIO_SIZEOF(htts_bind_info));
if (g_reuse_port) if (g_reuse_port)
@ -589,7 +589,7 @@ int main (int argc, char* argv[])
goto oops; goto oops;
} }
mio_setoption (mio, MIO_LOG_TARGET_B, "/dev/stderr"); mio_setoption (mio, MIO_LOG_TARGET_BCSTR, "/dev/stderr");
g_mio = mio; g_mio = mio;

View File

@ -272,17 +272,17 @@ int mio_setoption (mio_t* mio, mio_option_t id, const void* value)
{ {
case MIO_TRAIT: case MIO_TRAIT:
mio->option.trait = *(mio_bitmask_t*)value; mio->option.trait = *(mio_bitmask_t*)value;
return 0; break;
case MIO_LOG_MASK: case MIO_LOG_MASK:
mio->option.log_mask = *(mio_bitmask_t*)value; mio->option.log_mask = *(mio_bitmask_t*)value;
return 0; break;
case MIO_LOG_MAXCAPA: case MIO_LOG_MAXCAPA:
mio->option.log_maxcapa = *(mio_oow_t*)value; mio->option.log_maxcapa = *(mio_oow_t*)value;
return 0; break;
case MIO_LOG_TARGET_B: case MIO_LOG_TARGET_BCSTR:
{ {
mio_bch_t* v1; mio_bch_t* v1;
mio_uch_t* v2; mio_uch_t* v2;
@ -301,10 +301,10 @@ int mio_setoption (mio_t* mio, mio_option_t id, const void* value)
mio->option.log_target_b = v1; mio->option.log_target_b = v1;
mio_sys_resetlog (mio); mio_sys_resetlog (mio);
return 0; break;
} }
case MIO_LOG_TARGET_U: case MIO_LOG_TARGET_UCSTR:
{ {
mio_uch_t* v1; mio_uch_t* v1;
mio_bch_t* v2; mio_bch_t* v2;
@ -323,14 +323,66 @@ int mio_setoption (mio_t* mio, mio_option_t id, const void* value)
mio->option.log_target_b = v2; mio->option.log_target_b = v2;
mio_sys_resetlog (mio); mio_sys_resetlog (mio);
return 0; break;
}
case MIO_LOG_TARGET_BCS:
{
mio_bch_t* v1;
mio_uch_t* v2;
mio_bcs_t* v = (mio_bcs_t*)value;
v1 = mio_dupbchars(mio, v->ptr, v->len);
if (MIO_UNLIKELY(!v1)) return -1;
v2 = mio_dupbtouchars(mio, v->ptr, v->len, MIO_NULL, 0);
if (MIO_UNLIKELY(!v2))
{
mio_freemem (mio, v1);
return -1;
}
mio->option.log_target_u = v2;
mio->option.log_target_b = v1;
mio_sys_resetlog (mio);
break;
}
case MIO_LOG_TARGET_UCS:
{
mio_uch_t* v1;
mio_bch_t* v2;
mio_ucs_t* v = (mio_bcs_t*)value;
v1 = mio_dupuchars(mio, v->ptr, v->len);
if (MIO_UNLIKELY(!v1)) return -1;
v2 = mio_duputobchars(mio, v->ptr, v->len, MIO_NULL);
if (MIO_UNLIKELY(!v2))
{
mio_freemem (mio, v1);
return -1;
}
mio->option.log_target_u = v1;
mio->option.log_target_b = v2;
mio_sys_resetlog (mio);
break;
} }
case MIO_LOG_WRITER: case MIO_LOG_WRITER:
mio->option.log_writer = (mio_log_writer_t)value; mio->option.log_writer = (mio_log_writer_t)value;
return 0; break;
default:
goto einval;
} }
return 0;
einval:
mio_seterrnum (mio, MIO_EINVAL); mio_seterrnum (mio, MIO_EINVAL);
return -1; return -1;
} }
@ -351,14 +403,24 @@ int mio_getoption (mio_t* mio, mio_option_t id, void* value)
*(mio_oow_t*)value = mio->option.log_maxcapa; *(mio_oow_t*)value = mio->option.log_maxcapa;
return 0; return 0;
case MIO_LOG_TARGET_B: case MIO_LOG_TARGET_BCSTR:
*(mio_bch_t**)value = mio->option.log_target_b; *(mio_bch_t**)value = mio->option.log_target_b;
return 0; return 0;
case MIO_LOG_TARGET_U: case MIO_LOG_TARGET_UCSTR:
*(mio_uch_t**)value = mio->option.log_target_u; *(mio_uch_t**)value = mio->option.log_target_u;
return 0; return 0;
case MIO_LOG_TARGET_BCS:
((mio_bcs_t*)value)->ptr = mio->option.log_target_b;
((mio_bcs_t*)value)->len = mio_count_bcstr(mio->option.log_target_b);
return 0;
case MIO_LOG_TARGET_UCS:
((mio_ucs_t*)value)->ptr = mio->option.log_target_u;
((mio_ucs_t*)value)->len = mio_count_ucstr(mio->option.log_target_u);
return 0;
case MIO_LOG_WRITER: case MIO_LOG_WRITER:
*(mio_log_writer_t*)value = mio->option.log_writer; *(mio_log_writer_t*)value = mio->option.log_writer;
return 0; return 0;

View File

@ -137,14 +137,21 @@ enum mio_option_t
MIO_LOG_MAXCAPA, MIO_LOG_MAXCAPA,
/* log target for the builtin writer */ /* log target for the builtin writer */
MIO_LOG_TARGET_B, MIO_LOG_TARGET_BCSTR,
MIO_LOG_TARGET_U, MIO_LOG_TARGET_UCSTR,
MIO_LOG_TARGET_BCS,
MIO_LOG_TARGET_UCS,
#if defined(MIO_OOCH_IS_UCH) #if defined(MIO_OOCH_IS_UCH)
# define MIO_LOG_TARGET MIO_LOG_TARGET_U # define MIO_LOG_TARGET MIO_LOG_TARGET_UCSTR
# define MIO_LOG_TARGET_OOCSTR MIO_LOG_TARGET_UCSTR
# define MIO_LOG_TARGET_OOCS MIO_LOG_TARGET_UCS
#else #else
# define MIO_LOG_TARGET MIO_LOG_TARGET_B # define MIO_LOG_TARGET MIO_LOG_TARGET_BCSTR
# define MIO_LOG_TARGET_OOCSTR MIO_LOG_TARGET_BCSTR
# define MIO_LOG_TARGET_OOCS MIO_LOG_TARGET_BCS
#endif #endif
/* user-defined log writer */
MIO_LOG_WRITER MIO_LOG_WRITER
}; };
typedef enum mio_option_t mio_option_t; typedef enum mio_option_t mio_option_t;