changed directory error number setting to mio_seterrxxx() calls

removed mio->renew_watch and moved it to each device by using the MIO_DEV_RENEW_REQUIRED bit
This commit is contained in:
hyung-hwan 2019-01-29 08:38:12 +00:00
parent 470e459781
commit 792e4da4c2
9 changed files with 128 additions and 207 deletions

View File

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

14
mio/configure vendored
View File

@ -771,7 +771,6 @@ infodir
docdir docdir
oldincludedir oldincludedir
includedir includedir
runstatedir
localstatedir localstatedir
sharedstatedir sharedstatedir
sysconfdir sysconfdir
@ -862,7 +861,6 @@ datadir='${datarootdir}'
sysconfdir='${prefix}/etc' sysconfdir='${prefix}/etc'
sharedstatedir='${prefix}/com' sharedstatedir='${prefix}/com'
localstatedir='${prefix}/var' localstatedir='${prefix}/var'
runstatedir='${localstatedir}/run'
includedir='${prefix}/include' includedir='${prefix}/include'
oldincludedir='/usr/include' oldincludedir='/usr/include'
docdir='${datarootdir}/doc/${PACKAGE_TARNAME}' docdir='${datarootdir}/doc/${PACKAGE_TARNAME}'
@ -1115,15 +1113,6 @@ do
| -silent | --silent | --silen | --sile | --sil) | -silent | --silent | --silen | --sile | --sil)
silent=yes ;; 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) -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb)
ac_prev=sbindir ;; ac_prev=sbindir ;;
-sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \ -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \
@ -1261,7 +1250,7 @@ fi
for ac_var in exec_prefix prefix bindir sbindir libexecdir datarootdir \ for ac_var in exec_prefix prefix bindir sbindir libexecdir datarootdir \
datadir sysconfdir sharedstatedir localstatedir includedir \ datadir sysconfdir sharedstatedir localstatedir includedir \
oldincludedir docdir infodir htmldir dvidir pdfdir psdir \ oldincludedir docdir infodir htmldir dvidir pdfdir psdir \
libdir localedir mandir runstatedir libdir localedir mandir
do do
eval ac_val=\$$ac_var eval ac_val=\$$ac_var
# Remove trailing slashes. # Remove trailing slashes.
@ -1414,7 +1403,6 @@ Fine tuning of the installation directories:
--sysconfdir=DIR read-only single-machine data [PREFIX/etc] --sysconfdir=DIR read-only single-machine data [PREFIX/etc]
--sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com] --sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com]
--localstatedir=DIR modifiable single-machine data [PREFIX/var] --localstatedir=DIR modifiable single-machine data [PREFIX/var]
--runstatedir=DIR modifiable per-process data [LOCALSTATEDIR/run]
--libdir=DIR object code libraries [EPREFIX/lib] --libdir=DIR object code libraries [EPREFIX/lib]
--includedir=DIR C header files [PREFIX/include] --includedir=DIR C header files [PREFIX/include]
--oldincludedir=DIR C header files for non-gcc [/usr/include] --oldincludedir=DIR C header files for non-gcc [/usr/include]

View File

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

View File

@ -249,19 +249,18 @@ static int x = 0;
mio_ntime_t tmout; mio_ntime_t tmout;
static char a ='A'; static char a ='A';
char* xxx = malloc (1000000); static char xxx[1000000];
memset (xxx, a++ ,1000000); memset (xxx, a++ , MIO_SIZEOF(xxx));
MIO_INFO2 (tcp->mio, "TCP_SCK_ON_READ(%d) >>> REQUESTING to write data of %d bytes\n", (int)tcp->sck, 1000000); MIO_INFO2 (tcp->mio, "TCP_SCK_ON_READ(%d) >>> REQUESTING to write data of %d bytes\n", (int)tcp->sck, MIO_SIZEOF(xxx));
//return mio_dev_sck_write (tcp, "HELLO", 5, MIO_NULL); //return mio_dev_sck_write (tcp, "HELLO", 5, MIO_NULL);
MIO_INIT_NTIME (&tmout, 5, 0); MIO_INIT_NTIME (&tmout, 5, 0);
n = mio_dev_sck_timedwrite(tcp, xxx, 1000000, &tmout, MIO_NULL, MIO_NULL); n = mio_dev_sck_timedwrite(tcp, xxx, MIO_SIZEOF(xxx), &tmout, MIO_NULL, MIO_NULL);
free (xxx);
if (n <= -1) return -1; if (n <= -1) return -1;
} }
MIO_INFO1 (tcp->mio, "TCP_SCK_ON_READ(%d) - DISABLING READ\n", (int)tcp->sck); MIO_INFO1 (tcp->mio, "TCP_SCK_ON_READ(%d) - REQUESTING TO STOP READ\n", (int)tcp->sck);
mio_dev_sck_read (tcp, 0); mio_dev_sck_read (tcp, 0);
#if 0 #if 0

View File

@ -59,8 +59,8 @@ typedef struct param_t param_t;
static void free_param (mio_t* mio, param_t* param) static void free_param (mio_t* mio, param_t* param)
{ {
if (param->argv && param->argv != param->fixed_argv) if (param->argv && param->argv != param->fixed_argv)
MIO_MMGR_FREE (mio->mmgr, param->argv); mio_freemem (mio, param->argv);
if (param->mcmd) MIO_MMGR_FREE (mio->mmgr, param->mcmd); if (param->mcmd) mio_freemem (mio, param->mcmd);
MIO_MEMSET (param, 0, MIO_SIZEOF(*param)); MIO_MEMSET (param, 0, MIO_SIZEOF(*param));
} }
@ -94,7 +94,7 @@ static int make_param (mio_t* mio, const mio_bch_t* cmd, int flags, param_t* par
if (fcnt <= 0) if (fcnt <= 0)
{ {
/* no field or an error */ /* no field or an error */
mio->errnum = MIO_EINVAL; mio_seterrnum (mio, MIO_EINVAL);
goto oops; goto oops;
} }
@ -104,12 +104,8 @@ static int make_param (mio_t* mio, const mio_bch_t* cmd, int flags, param_t* par
} }
else else
{ {
param->argv = MIO_MMGR_ALLOC (mio->mmgr, (fcnt + 1) * MIO_SIZEOF(argv[0])); param->argv = mio_allocmem(mio, (fcnt + 1) * MIO_SIZEOF(argv[0]));
if (param->argv == MIO_NULL) if (!param->argv) goto oops;
{
mio->errnum = MIO_ESYSMEM;
goto oops;
}
} }
mcmdptr = mcmd; mcmdptr = mcmd;
@ -126,7 +122,7 @@ static int make_param (mio_t* mio, const mio_bch_t* cmd, int flags, param_t* par
return 0; return 0;
oops: oops:
if (mcmd && mcmd != cmd) MIO_MMGR_FREE (mio->mmgr, mcmd); if (mcmd && mcmd != cmd) mio_freemem (mio, mcmd);
return -1; return -1;
} }
@ -223,6 +219,7 @@ static pid_t standard_fork_and_exec (mio_t* mio, int pfds[], int flags, param_t*
static int dev_pro_make_master (mio_dev_t* dev, void* ctx) static int dev_pro_make_master (mio_dev_t* dev, void* ctx)
{ {
mio_t* mio = dev->mio;
mio_dev_pro_t* rdev = (mio_dev_pro_t*)dev; mio_dev_pro_t* rdev = (mio_dev_pro_t*)dev;
mio_dev_pro_make_t* info = (mio_dev_pro_make_t*)ctx; mio_dev_pro_make_t* info = (mio_dev_pro_make_t*)ctx;
mio_syshnd_t pfds[6]; mio_syshnd_t pfds[6];
@ -234,7 +231,7 @@ static int dev_pro_make_master (mio_dev_t* dev, void* ctx)
{ {
if (pipe(&pfds[0]) == -1) if (pipe(&pfds[0]) == -1)
{ {
mio_seterrwithsyserr (dev->mio, 0, errno); mio_seterrwithsyserr (mio, 0, errno);
goto oops; goto oops;
} }
minidx = 0; maxidx = 1; minidx = 0; maxidx = 1;
@ -244,7 +241,7 @@ static int dev_pro_make_master (mio_dev_t* dev, void* ctx)
{ {
if (pipe(&pfds[2]) == -1) if (pipe(&pfds[2]) == -1)
{ {
mio_seterrwithsyserr (dev->mio, 0, errno); mio_seterrwithsyserr (mio, 0, errno);
goto oops; goto oops;
} }
if (minidx == -1) minidx = 2; if (minidx == -1) minidx = 2;
@ -255,7 +252,7 @@ static int dev_pro_make_master (mio_dev_t* dev, void* ctx)
{ {
if (pipe(&pfds[4]) == -1) if (pipe(&pfds[4]) == -1)
{ {
mio_seterrwithsyserr (dev->mio, 0, errno); mio_seterrwithsyserr (mio, 0, errno);
goto oops; goto oops;
} }
if (minidx == -1) minidx = 4; if (minidx == -1) minidx = 4;
@ -264,21 +261,21 @@ static int dev_pro_make_master (mio_dev_t* dev, void* ctx)
if (maxidx == -1) if (maxidx == -1)
{ {
mio_seterrnum (dev->mio, MIO_EINVAL); mio_seterrnum (mio, MIO_EINVAL);
goto oops; goto oops;
} }
if (make_param (rdev->mio, info->cmd, info->flags, &param) <= -1) goto oops; if (make_param(mio, info->cmd, info->flags, &param) <= -1) goto oops;
/* TODO: more advanced fork and exec .. */ /* TODO: more advanced fork and exec .. */
pid = standard_fork_and_exec (rdev->mio, pfds, info->flags, &param); pid = standard_fork_and_exec(mio, pfds, info->flags, &param);
if (pid <= -1) if (pid <= -1)
{ {
free_param (rdev->mio, &param); free_param (mio, &param);
goto oops; goto oops;
} }
free_param (rdev->mio, &param); free_param (mio, &param);
rdev->child_pid = pid; rdev->child_pid = pid;
/* this is the parent process */ /* this is the parent process */
@ -293,7 +290,7 @@ static int dev_pro_make_master (mio_dev_t* dev, void* ctx)
close (pfds[0]); close (pfds[0]);
pfds[0] = MIO_SYSHND_INVALID; pfds[0] = MIO_SYSHND_INVALID;
if (mio_makesyshndasync (dev->mio, pfds[1]) <= -1) goto oops; if (mio_makesyshndasync(mio, pfds[1]) <= -1) goto oops;
} }
if (info->flags & MIO_DEV_PRO_READOUT) if (info->flags & MIO_DEV_PRO_READOUT)
@ -307,7 +304,7 @@ static int dev_pro_make_master (mio_dev_t* dev, void* ctx)
close (pfds[3]); close (pfds[3]);
pfds[3] = MIO_SYSHND_INVALID; pfds[3] = MIO_SYSHND_INVALID;
if (mio_makesyshndasync (dev->mio, pfds[2]) <= -1) goto oops; if (mio_makesyshndasync(mio, pfds[2]) <= -1) goto oops;
} }
if (info->flags & MIO_DEV_PRO_READERR) if (info->flags & MIO_DEV_PRO_READERR)
@ -321,7 +318,7 @@ static int dev_pro_make_master (mio_dev_t* dev, void* ctx)
close (pfds[5]); close (pfds[5]);
pfds[5] = MIO_SYSHND_INVALID; pfds[5] = MIO_SYSHND_INVALID;
if (mio_makesyshndasync (dev->mio, pfds[4]) <= -1) goto oops; if (mio_makesyshndasync(mio, pfds[4]) <= -1) goto oops;
} }
if (pfds[1] != MIO_SYSHND_INVALID) if (pfds[1] != MIO_SYSHND_INVALID)
@ -334,7 +331,7 @@ static int dev_pro_make_master (mio_dev_t* dev, void* ctx)
si.dev_capa = MIO_DEV_CAPA_OUT | MIO_DEV_CAPA_OUT_QUEUED | MIO_DEV_CAPA_STREAM; si.dev_capa = MIO_DEV_CAPA_OUT | MIO_DEV_CAPA_OUT_QUEUED | MIO_DEV_CAPA_STREAM;
si.id = MIO_DEV_PRO_IN; si.id = MIO_DEV_PRO_IN;
rdev->slave[MIO_DEV_PRO_IN] = make_slave (dev->mio, &si); rdev->slave[MIO_DEV_PRO_IN] = make_slave(mio, &si);
if (!rdev->slave[MIO_DEV_PRO_IN]) goto oops; if (!rdev->slave[MIO_DEV_PRO_IN]) goto oops;
pfds[1] = MIO_SYSHND_INVALID; pfds[1] = MIO_SYSHND_INVALID;
@ -351,7 +348,7 @@ static int dev_pro_make_master (mio_dev_t* dev, void* ctx)
si.dev_capa = MIO_DEV_CAPA_IN | MIO_DEV_CAPA_STREAM; si.dev_capa = MIO_DEV_CAPA_IN | MIO_DEV_CAPA_STREAM;
si.id = MIO_DEV_PRO_OUT; si.id = MIO_DEV_PRO_OUT;
rdev->slave[MIO_DEV_PRO_OUT] = make_slave (dev->mio, &si); rdev->slave[MIO_DEV_PRO_OUT] = make_slave(mio, &si);
if (!rdev->slave[MIO_DEV_PRO_OUT]) goto oops; if (!rdev->slave[MIO_DEV_PRO_OUT]) goto oops;
pfds[2] = MIO_SYSHND_INVALID; pfds[2] = MIO_SYSHND_INVALID;
@ -368,7 +365,7 @@ static int dev_pro_make_master (mio_dev_t* dev, void* ctx)
si.dev_capa = MIO_DEV_CAPA_IN | MIO_DEV_CAPA_STREAM; si.dev_capa = MIO_DEV_CAPA_IN | MIO_DEV_CAPA_STREAM;
si.id = MIO_DEV_PRO_ERR; si.id = MIO_DEV_PRO_ERR;
rdev->slave[MIO_DEV_PRO_ERR] = make_slave (dev->mio, &si); rdev->slave[MIO_DEV_PRO_ERR] = make_slave(mio, &si);
if (!rdev->slave[MIO_DEV_PRO_ERR]) goto oops; if (!rdev->slave[MIO_DEV_PRO_ERR]) goto oops;
pfds[4] = MIO_SYSHND_INVALID; pfds[4] = MIO_SYSHND_INVALID;
@ -395,8 +392,8 @@ oops:
if (rdev->mcmd) if (rdev->mcmd)
{ {
MIO_MMGR_FREE (rdev->mio->mmgr, rdev->mcmd); mio_freemem (mio, rdev->mcmd);
free_param (rdev->mio, &param); free_param (mio, &param);
} }
for (i = MIO_COUNTOF(rdev->slave); i > 0; ) for (i = MIO_COUNTOF(rdev->slave); i > 0; )
@ -404,7 +401,7 @@ oops:
i--; i--;
if (rdev->slave[i]) if (rdev->slave[i])
{ {
mio_killdev (rdev->mio, (mio_dev_t*)rdev->slave[i]); mio_killdev (mio, (mio_dev_t*)rdev->slave[i]);
rdev->slave[i] = MIO_NULL; rdev->slave[i] = MIO_NULL;
} }
} }
@ -429,6 +426,7 @@ static int dev_pro_make_slave (mio_dev_t* dev, void* ctx)
static int dev_pro_kill_master (mio_dev_t* dev, int force) static int dev_pro_kill_master (mio_dev_t* dev, int force)
{ {
mio_t* mio = dev->mio;
mio_dev_pro_t* rdev = (mio_dev_pro_t*)dev; mio_dev_pro_t* rdev = (mio_dev_pro_t*)dev;
int i, status; int i, status;
pid_t wpid; pid_t wpid;
@ -447,7 +445,7 @@ static int dev_pro_kill_master (mio_dev_t* dev, int force)
* self-initiated termination or master-driven termination */ * self-initiated termination or master-driven termination */
rdev->slave[i] = MIO_NULL; rdev->slave[i] = MIO_NULL;
mio_killdev (rdev->mio, (mio_dev_t*)sdev); mio_killdev (mio, (mio_dev_t*)sdev);
} }
} }
} }
@ -474,7 +472,7 @@ static int dev_pro_kill_master (mio_dev_t* dev, int force)
else else
{ {
/* child process is still alive */ /* child process is still alive */
rdev->mio->errnum = MIO_EAGAIN; mio_seterrnum (mio, MIO_EAGAIN);
return -1; /* call me again */ return -1; /* call me again */
} }
} }
@ -486,7 +484,7 @@ static int dev_pro_kill_master (mio_dev_t* dev, int force)
*/ */
} }
printf (">>>>>>>>>>>>>>>>>>> REAPED CHILD %d\n", (int)rdev->child_pid); MIO_DEBUG1 (mio, ">>>>>>>>>>>>>>>>>>> REAPED CHILD %d\n", (int)rdev->child_pid);
rdev->child_pid = -1; rdev->child_pid = -1;
} }
@ -496,6 +494,7 @@ printf (">>>>>>>>>>>>>>>>>>> REAPED CHILD %d\n", (int)rdev->child_pid);
static int dev_pro_kill_slave (mio_dev_t* dev, int force) static int dev_pro_kill_slave (mio_dev_t* dev, int force)
{ {
mio_t* mio = dev->mio;
mio_dev_pro_slave_t* rdev = (mio_dev_pro_slave_t*)dev; mio_dev_pro_slave_t* rdev = (mio_dev_pro_slave_t*)dev;
if (rdev->master) if (rdev->master)
@ -508,7 +507,7 @@ static int dev_pro_kill_slave (mio_dev_t* dev, int force)
/* indicate EOF */ /* indicate EOF */
if (master->on_close) master->on_close (master, rdev->id); if (master->on_close) master->on_close (master, rdev->id);
MIO_ASSERT (dev->mio, master->slave_count > 0); MIO_ASSERT (mio, master->slave_count > 0);
master->slave_count--; master->slave_count--;
if (master->slave[rdev->id]) if (master->slave[rdev->id])
@ -517,7 +516,7 @@ static int dev_pro_kill_slave (mio_dev_t* dev, int force)
* if this is the last slave, kill the master also */ * if this is the last slave, kill the master also */
if (master->slave_count <= 0) if (master->slave_count <= 0)
{ {
mio_killdev (rdev->mio, (mio_dev_t*)master); mio_killdev (mio, (mio_dev_t*)master);
/* the master pointer is not valid from this point onwards /* the master pointer is not valid from this point onwards
* as the actual master device object is freed in mio_killdev() */ * as the actual master device object is freed in mio_killdev() */
} }
@ -589,6 +588,7 @@ static mio_syshnd_t dev_pro_getsyshnd_slave (mio_dev_t* dev)
static int dev_pro_ioctl (mio_dev_t* dev, int cmd, void* arg) static int dev_pro_ioctl (mio_dev_t* dev, int cmd, void* arg)
{ {
mio_t* mio = dev->mio;
mio_dev_pro_t* rdev = (mio_dev_pro_t*)dev; mio_dev_pro_t* rdev = (mio_dev_pro_t*)dev;
switch (cmd) switch (cmd)
@ -599,7 +599,7 @@ static int dev_pro_ioctl (mio_dev_t* dev, int cmd, void* arg)
if (sid < MIO_DEV_PRO_IN || sid > MIO_DEV_PRO_ERR) if (sid < MIO_DEV_PRO_IN || sid > MIO_DEV_PRO_ERR)
{ {
rdev->mio->errnum = MIO_EINVAL; mio_seterrnum (mio, MIO_EINVAL);
return -1; return -1;
} }
@ -608,7 +608,7 @@ static int dev_pro_ioctl (mio_dev_t* dev, int cmd, void* arg)
/* unlike dev_pro_kill_master(), i don't nullify rdev->slave[sid]. /* unlike dev_pro_kill_master(), i don't nullify rdev->slave[sid].
* so i treat the closing ioctl as if it's a kill request * so i treat the closing ioctl as if it's a kill request
* initiated by the slave device itself. */ * initiated by the slave device itself. */
mio_killdev (rdev->mio, (mio_dev_t*)rdev->slave[sid]); mio_killdev (mio, (mio_dev_t*)rdev->slave[sid]);
} }
return 0; return 0;
} }
@ -618,7 +618,7 @@ static int dev_pro_ioctl (mio_dev_t* dev, int cmd, void* arg)
{ {
if (kill (rdev->child_pid, SIGKILL) == -1) if (kill (rdev->child_pid, SIGKILL) == -1)
{ {
mio_seterrwithsyserr (rdev->mio, 0, errno); mio_seterrwithsyserr (mio, 0, errno);
return -1; return -1;
} }
} }
@ -626,7 +626,7 @@ static int dev_pro_ioctl (mio_dev_t* dev, int cmd, void* arg)
return 0; return 0;
default: default:
dev->mio->errnum = MIO_EINVAL; mio_seterrnum (mio, MIO_EINVAL);
return -1; return -1;
} }
} }
@ -658,21 +658,21 @@ static mio_dev_mth_t dev_pro_methods_slave =
static int pro_ready (mio_dev_t* dev, int events) static int pro_ready (mio_dev_t* dev, int events)
{ {
/* virtual device. no I/O */ /* virtual device. no I/O */
dev->mio->errnum = MIO_EINTERN; mio_seterrnum (dev->mio, MIO_EINTERN);
return -1; return -1;
} }
static int pro_on_read (mio_dev_t* dev, const void* data, mio_iolen_t len, const mio_devaddr_t* srcaddr) static int pro_on_read (mio_dev_t* dev, const void* data, mio_iolen_t len, const mio_devaddr_t* srcaddr)
{ {
/* virtual device. no I/O */ /* virtual device. no I/O */
dev->mio->errnum = MIO_EINTERN; mio_seterrnum (dev->mio, MIO_EINTERN);
return -1; return -1;
} }
static int pro_on_write (mio_dev_t* dev, mio_iolen_t wrlen, void* wrctx, const mio_devaddr_t* dstaddr) static int pro_on_write (mio_dev_t* dev, mio_iolen_t wrlen, void* wrctx, const mio_devaddr_t* dstaddr)
{ {
/* virtual device. no I/O */ /* virtual device. no I/O */
dev->mio->errnum = MIO_EINTERN; mio_seterrnum (dev->mio, MIO_EINTERN);
return -1; return -1;
} }
@ -687,11 +687,12 @@ static mio_dev_evcb_t dev_pro_event_callbacks =
static int pro_ready_slave (mio_dev_t* dev, int events) static int pro_ready_slave (mio_dev_t* dev, int events)
{ {
mio_t* mio = dev->mio;
mio_dev_pro_t* pro = (mio_dev_pro_t*)dev; mio_dev_pro_t* pro = (mio_dev_pro_t*)dev;
if (events & MIO_DEV_EVENT_ERR) if (events & MIO_DEV_EVENT_ERR)
{ {
pro->mio->errnum = MIO_EDEVERR; mio_seterrnum (mio, MIO_EDEVERR);
return -1; return -1;
} }
@ -703,7 +704,7 @@ static int pro_ready_slave (mio_dev_t* dev, int events)
return 1; return 1;
} }
pro->mio->errnum = MIO_EDEVHUP; mio_seterrnum (mio, MIO_EDEVHUP);
return -1; return -1;
} }

View File

@ -276,7 +276,7 @@ static MIO_INLINE void handle_event (mio_t* mio, mio_dev_t* dev, int events, int
{ {
MIO_ASSERT (mio, mio == dev->mio); MIO_ASSERT (mio, mio == dev->mio);
mio->renew_watch = 0; dev->dev_capa &= ~MIO_DEV_RENEW_REQUIRED;
MIO_ASSERT (mio, mio == dev->mio); MIO_ASSERT (mio, mio == dev->mio);
@ -353,7 +353,7 @@ static MIO_INLINE void handle_event (mio_t* mio, mio_dev_t* dev, int events, int
/* it was a zero-length write request. /* it was a zero-length write request.
* for a stream, it is to close the output. */ * for a stream, it is to close the output. */
dev->dev_capa |= MIO_DEV_CAPA_OUT_CLOSED; dev->dev_capa |= MIO_DEV_CAPA_OUT_CLOSED;
mio->renew_watch = 1; dev->dev_capa |= MIO_DEV_RENEW_REQUIRED;
out_closed = 1; out_closed = 1;
} }
@ -396,7 +396,7 @@ static MIO_INLINE void handle_event (mio_t* mio, mio_dev_t* dev, int events, int
} }
else else
{ {
mio->renew_watch = 1; dev->dev_capa |= MIO_DEV_RENEW_REQUIRED;
} }
} }
} }
@ -447,14 +447,12 @@ static MIO_INLINE void handle_event (mio_t* mio, mio_dev_t* dev, int events, int
} }
else /*if (x >= 1) */ else /*if (x >= 1) */
{ {
if (len <= 0 && (dev->dev_capa & MIO_DEV_CAPA_STREAM)) if (len <= 0 && (dev->dev_capa & MIO_DEV_CAPA_STREAM))
{ {
/* EOF received. for a stream device, a zero-length /* EOF received. for a stream device, a zero-length
* read is interpreted as EOF. */ * read is interpreted as EOF. */
dev->dev_capa |= MIO_DEV_CAPA_IN_CLOSED; dev->dev_capa |= MIO_DEV_CAPA_IN_CLOSED;
mio->renew_watch = 1; dev->dev_capa |= MIO_DEV_RENEW_REQUIRED;
/* call the on_read callback to report EOF */ /* call the on_read callback to report EOF */
if (dev->dev_evcb->on_read(dev, mio->bigbuf, len, &srcaddr) <= -1 || if (dev->dev_evcb->on_read(dev, mio->bigbuf, len, &srcaddr) <= -1 ||
@ -503,7 +501,7 @@ static MIO_INLINE void handle_event (mio_t* mio, mio_dev_t* dev, int events, int
* EPOLLIN or EPOLLOUT check because EPOLLERR or EPOLLHUP * EPOLLIN or EPOLLOUT check because EPOLLERR or EPOLLHUP
* can be set together with EPOLLIN or EPOLLOUT. */ * 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_IN_CLOSED | MIO_DEV_CAPA_OUT_CLOSED;
mio->renew_watch = 1; dev->dev_capa |= MIO_DEV_RENEW_REQUIRED;
} }
else if (dev && rdhup) else if (dev && rdhup)
{ {
@ -515,7 +513,7 @@ static MIO_INLINE void handle_event (mio_t* mio, mio_dev_t* dev, int events, int
else else
{ {
dev->dev_capa |= MIO_DEV_CAPA_IN_CLOSED | MIO_DEV_CAPA_OUT_CLOSED; dev->dev_capa |= MIO_DEV_CAPA_IN_CLOSED | MIO_DEV_CAPA_OUT_CLOSED;
mio->renew_watch = 1; dev->dev_capa |= MIO_DEV_RENEW_REQUIRED;
} }
} }
@ -528,21 +526,17 @@ static MIO_INLINE void handle_event (mio_t* mio, mio_dev_t* dev, int events, int
} }
skip_evcb: skip_evcb:
if (dev && mio->renew_watch && mio_dev_watch(dev, MIO_DEV_WATCH_RENEW, 0) <= -1) if (dev && (dev->dev_capa & MIO_DEV_RENEW_REQUIRED) && mio_dev_watch(dev, MIO_DEV_WATCH_RENEW, 0) <= -1)
{ {
mio_dev_halt (dev); mio_dev_halt (dev);
dev = MIO_NULL; dev = MIO_NULL;
} }
} }
static MIO_INLINE int __exec (mio_t* mio) int mio_exec (mio_t* mio)
{ {
mio_ntime_t tmout;
mio_sys_mux_t* mux;
int ret = 0; int ret = 0;
/*if (!mio->actdev.head) return 0;*/
/* execute callbacks for completed write operations */ /* execute callbacks for completed write operations */
while (!MIO_CWQ_ISEMPTY(&mio->cwq)) while (!MIO_CWQ_ISEMPTY(&mio->cwq))
{ {
@ -572,6 +566,11 @@ static MIO_INLINE int __exec (mio_t* mio)
* multiplexer. the scheduled jobs can safely destroy the devices */ * multiplexer. the scheduled jobs can safely destroy the devices */
mio_firetmrjobs (mio, MIO_NULL, MIO_NULL); mio_firetmrjobs (mio, MIO_NULL, MIO_NULL);
if (mio->actdev.head)
{
/* wait on the multiplexer only if there is at least 1 active device */
mio_ntime_t tmout;
if (mio_gettmrtmout(mio, MIO_NULL, &tmout) <= -1) if (mio_gettmrtmout(mio, MIO_NULL, &tmout) <= -1)
{ {
/* defaults to 1 second if timeout can't be acquired */ /* defaults to 1 second if timeout can't be acquired */
@ -584,6 +583,7 @@ static MIO_INLINE int __exec (mio_t* mio)
MIO_DEBUG0 (mio, "WARNING - Failed to wait on mutiplexer\n"); MIO_DEBUG0 (mio, "WARNING - Failed to wait on mutiplexer\n");
ret = -1; ret = -1;
} }
}
/* kill all halted devices */ /* kill all halted devices */
while (mio->hltdev.head) while (mio->hltdev.head)
@ -596,17 +596,6 @@ static MIO_INLINE int __exec (mio_t* mio)
return ret; return ret;
} }
int mio_exec (mio_t* mio)
{
int n;
mio->in_exec = 1;
n = __exec (mio);
mio->in_exec = 0;
return n;
}
void mio_stop (mio_t* mio, mio_stopreq_t stopreq) void mio_stop (mio_t* mio, mio_stopreq_t stopreq)
{ {
mio->stopreq = stopreq; mio->stopreq = stopreq;
@ -617,7 +606,6 @@ int mio_loop (mio_t* mio)
if (!mio->actdev.head) return 0; if (!mio->actdev.head) return 0;
mio->stopreq = MIO_STOPREQ_NONE; mio->stopreq = MIO_STOPREQ_NONE;
mio->renew_watch = 0;
if (mio_prologue(mio) <= -1) return -1; if (mio_prologue(mio) <= -1) return -1;
@ -637,7 +625,7 @@ mio_dev_t* mio_makedev (mio_t* mio, mio_oow_t dev_size, mio_dev_mth_t* dev_mth,
if (dev_size < MIO_SIZEOF(mio_dev_t)) if (dev_size < MIO_SIZEOF(mio_dev_t))
{ {
mio->errnum = MIO_EINVAL; mio_seterrnum (mio, MIO_EINVAL);
return MIO_NULL; return MIO_NULL;
} }
@ -675,15 +663,7 @@ mio_dev_t* mio_makedev (mio_t* mio, mio_oow_t dev_size, mio_dev_mth_t* dev_mth,
if (!(dev->dev_capa & MIO_DEV_CAPA_IN)) dev->dev_capa |= MIO_DEV_CAPA_IN_CLOSED; 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; if (!(dev->dev_capa & MIO_DEV_CAPA_OUT)) dev->dev_capa |= MIO_DEV_CAPA_OUT_CLOSED;
#if defined(_WIN32)
if (CreateIoCompletionPort((HANDLE)dev->dev_mth->getsyshnd(dev), mio->iocp, MIO_IOCP_KEY, 0) == NULL)
{
/* TODO: set errnum from GetLastError()... */
goto oops_after_make;
}
#else
if (mio_dev_watch(dev, MIO_DEV_WATCH_START, 0) <= -1) goto oops_after_make; if (mio_dev_watch(dev, MIO_DEV_WATCH_START, 0) <= -1) goto oops_after_make;
#endif
/* and place the new device object at the back of the active device list */ /* and place the new device object at the back of the active device list */
APPEND_DEVICE_TO_LIST (&mio->actdev, dev); APPEND_DEVICE_TO_LIST (&mio->actdev, dev);
@ -926,8 +906,7 @@ int mio_dev_watch (mio_dev_t* dev, mio_dev_watch_cmd_t cmd, int events)
switch (cmd) switch (cmd)
{ {
case MIO_DEV_WATCH_START: case MIO_DEV_WATCH_START:
/* upon start, only input watching is requested */ events = 0; /* MIO_DEV_EVENT_IN if you want input watching to be enabled upon device creation */
events = MIO_DEV_EVENT_IN;
mux_cmd = MIO_SYS_MUX_CMD_INSERT; mux_cmd = MIO_SYS_MUX_CMD_INSERT;
break; break;
@ -949,7 +928,7 @@ int mio_dev_watch (mio_dev_t* dev, mio_dev_watch_cmd_t cmd, int events)
break; break;
default: default:
dev->mio->errnum = MIO_EINVAL; mio_seterrnum (dev->mio, MIO_EINVAL);
return -1; return -1;
} }
@ -980,7 +959,7 @@ int mio_dev_watch (mio_dev_t* dev, mio_dev_watch_cmd_t cmd, int events)
} }
else else
{ {
if (mio_sys_ctrlmux(dev->mio, mux_cmd, dev, dev_capa) <= -1) return -1; if (mio_sys_ctrlmux(mio, mux_cmd, dev, dev_capa) <= -1) return -1;
} }
dev->dev_capa = dev_capa; dev->dev_capa = dev_capa;
@ -994,7 +973,7 @@ static void on_read_timeout (mio_t* mio, const mio_ntime_t* now, mio_tmrjob_t* j
dev = (mio_dev_t*)job->ctx; dev = (mio_dev_t*)job->ctx;
dev->mio->errnum = MIO_ETMOUT; mio_seterrnum (mio, MIO_ETMOUT);
x = dev->dev_evcb->on_read(dev, MIO_NULL, -1, MIO_NULL); x = dev->dev_evcb->on_read(dev, MIO_NULL, -1, MIO_NULL);
MIO_ASSERT (mio, dev->rtmridx == MIO_TMRIDX_INVALID); MIO_ASSERT (mio, dev->rtmridx == MIO_TMRIDX_INVALID);
@ -1015,15 +994,15 @@ static int __dev_read (mio_dev_t* dev, int enabled, const mio_ntime_t* tmout, vo
if (enabled) if (enabled)
{ {
dev->dev_capa &= ~MIO_DEV_CAPA_IN_DISABLED; dev->dev_capa &= ~MIO_DEV_CAPA_IN_DISABLED;
if (/*!mio->in_exec && */!(dev->dev_capa & MIO_DEV_CAPA_IN_WATCHED)) goto renew_watch_now; if (!(dev->dev_capa & MIO_DEV_CAPA_IN_WATCHED)) goto renew_watch_now;
} }
else else
{ {
dev->dev_capa |= MIO_DEV_CAPA_IN_DISABLED; dev->dev_capa |= MIO_DEV_CAPA_IN_DISABLED;
if (/*!mio->in_exec && */(dev->dev_capa & MIO_DEV_CAPA_IN_WATCHED)) goto renew_watch_now; if ((dev->dev_capa & MIO_DEV_CAPA_IN_WATCHED)) goto renew_watch_now;
} }
mio->renew_watch = 1; dev->dev_capa |= MIO_DEV_RENEW_REQUIRED;
goto update_timer; goto update_timer;
renew_watch_now: renew_watch_now:
@ -1079,7 +1058,7 @@ static void on_write_timeout (mio_t* mio, const mio_ntime_t* now, mio_tmrjob_t*
q = (mio_wq_t*)job->ctx; q = (mio_wq_t*)job->ctx;
dev = q->dev; dev = q->dev;
dev->mio->errnum = MIO_ETMOUT; mio_seterrnum (mio, MIO_ETMOUT);
x = dev->dev_evcb->on_write(dev, -1, q->ctx, &q->dstaddr); x = dev->dev_evcb->on_write(dev, -1, q->ctx, &q->dstaddr);
MIO_ASSERT (mio, q->tmridx == MIO_TMRIDX_INVALID); MIO_ASSERT (mio, q->tmridx == MIO_TMRIDX_INVALID);
@ -1176,7 +1155,7 @@ enqueue_data:
if (!(dev->dev_capa & MIO_DEV_CAPA_OUT_QUEUED)) if (!(dev->dev_capa & MIO_DEV_CAPA_OUT_QUEUED))
{ {
/* writing queuing is not requested. so return failure */ /* writing queuing is not requested. so return failure */
dev->mio->errnum = MIO_ENOCAPA; mio_seterrbfmt (mio, MIO_ENOCAPA, "device incapable of queuing");
return -1; return -1;
} }
@ -1224,7 +1203,7 @@ enqueue_data:
} }
MIO_WQ_ENQ (&dev->wq, q); MIO_WQ_ENQ (&dev->wq, q);
if (!mio->in_exec && !(dev->dev_capa & MIO_DEV_CAPA_OUT_WATCHED)) if (!(dev->dev_capa & MIO_DEV_CAPA_OUT_WATCHED))
{ {
/* if output is not being watched, arrange to do so */ /* if output is not being watched, arrange to do so */
if (mio_dev_watch(dev, MIO_DEV_WATCH_RENEW, 0) <= -1) if (mio_dev_watch(dev, MIO_DEV_WATCH_RENEW, 0) <= -1)
@ -1234,10 +1213,6 @@ enqueue_data:
return -1; return -1;
} }
} }
else
{
mio->renew_watch = 1;
}
return 0; /* request pused to a write queue. */ return 0; /* request pused to a write queue. */

View File

@ -353,7 +353,10 @@ enum mio_dev_capa_t
MIO_DEV_CAPA_ACTIVE = (1 << 15), MIO_DEV_CAPA_ACTIVE = (1 << 15),
MIO_DEV_CAPA_HALTED = (1 << 16), MIO_DEV_CAPA_HALTED = (1 << 16),
MIO_DEV_CAPA_ZOMBIE = (1 << 17) MIO_DEV_CAPA_ZOMBIE = (1 << 17),
/* internal use only */
MIO_DEV_RENEW_REQUIRED = (1 << 20)
}; };
typedef enum mio_dev_capa_t mio_dev_capa_t; typedef enum mio_dev_capa_t mio_dev_capa_t;
@ -534,9 +537,6 @@ struct mio_t
mio_uint8_t bigbuf[65535]; /* TODO: make this dynamic depending on devices added. device may indicate a buffer size required??? */ mio_uint8_t bigbuf[65535]; /* TODO: make this dynamic depending on devices added. device may indicate a buffer size required??? */
unsigned int renew_watch: 1;
unsigned int in_exec: 1;
struct struct
{ {
mio_oow_t capa; mio_oow_t capa;

View File

@ -91,10 +91,6 @@ struct mio_sys_log_t
} out; } out;
}; };
typedef mio_sys_log_t xtn_t;
#define GET_XTN(mio) ((mio)->sys.log)
enum logfd_flag_t enum logfd_flag_t
{ {
LOGFD_TTY = (1 << 0), LOGFD_TTY = (1 << 0),

View File

@ -63,6 +63,15 @@ struct mio_sys_mux_t
} pd; /* poll data */ } pd; /* poll data */
}; };
#elif defined(USE_EPOLL)
struct mio_sys_mux_t
{
int hnd;
struct epoll_event revs[100]; /* TODO: is it a good size? */
};
#endif
int mio_sys_initmux (mio_t* mio) int mio_sys_initmux (mio_t* mio)
{ {
@ -71,6 +80,16 @@ int mio_sys_initmux (mio_t* mio)
mux = (mio_sys_mux_t*)mio_callocmem(mio, MIO_SIZEOF(*mux)); mux = (mio_sys_mux_t*)mio_callocmem(mio, MIO_SIZEOF(*mux));
if (!mux) return -1; if (!mux) return -1;
#if defined(USE_EPOLL)
mux->hnd = epoll_create(1000); /* TODO: choose proper initial size? */
if (mux->hnd == -1)
{
mio_seterrwithsyserr (mio, 0, errno);
mio_freemem (mio, mux);
return -1;
}
#endif
mio->sys.mux = mux; mio->sys.mux = mux;
return 0; return 0;
} }
@ -79,6 +98,9 @@ void mio_sys_finimux (mio_t* mio)
{ {
if (mio->sys.mux) if (mio->sys.mux)
{ {
#if defined(USE_EPOLL)
close (mio->sys.mux->hnd);
#endif
mio_freemem (mio, mio->sys.mux); mio_freemem (mio, mio->sys.mux);
mio->sys.mux = MIO_NULL; mio->sys.mux = MIO_NULL;
} }
@ -86,31 +108,28 @@ void mio_sys_finimux (mio_t* mio)
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_capa)
{ {
#if defined(USE_POLL)
mio_t* mio = dev->mio; mio_t* mio = dev->mio;
mio_sys_mux_t* mux; mio_sys_mux_t* mux;
mio_oow_t idx; mio_oow_t idx;
mux = (mio_sys_mux_t*)mio->sys.mux; mux = (mio_sys_mux_t*)mio->sys.mux;
if (hnd >= mux->map.capa) if (dev->hnd >= mux->map.capa)
{ {
mio_oow_t new_capa; mio_oow_t new_capa;
mio_oow_t* tmp; mio_oow_t* tmp;
if (cmd != MIO_SYS_MUX_CMD_INSERT) if (cmd != MIO_SYS_MUX_CMD_INSERT)
{ {
mio->errnum = MIO_ENOENT; mio_seterrnum (moo, MIO_ENOENT);
return -1; return -1;
} }
new_capa = MIO_ALIGN_POW2((hnd + 1), 256); new_capa = MIO_ALIGN_POW2((hnd + 1), 256);
tmp = MIO_MMGR_REALLOC(mio->mmgr, mux->map.ptr, new_capa * MIO_SIZEOF(*tmp)); tmp = mio_reallocmem(mio, mux->map.ptr, new_capa * MIO_SIZEOF(*tmp));
if (!tmp) if (!tmp) return -1;
{
mio->errnum = MIO_ESYSMEM;
return -1;
}
for (idx = mux->map.capa; idx < new_capa; idx++) for (idx = mux->map.capa; idx < new_capa; idx++)
tmp[idx] = MUX_INDEX_INVALID; tmp[idx] = MUX_INDEX_INVALID;
@ -124,7 +143,7 @@ int mio_sys_ctrlmux (mio_t* mio, mio_sys_mux_cmd_t cmd, mio_dev_t* dev, int dev_
{ {
if (cmd == MIO_SYS_MUX_CMD_INSERT) if (cmd == MIO_SYS_MUX_CMD_INSERT)
{ {
mio->errnum = MIO_EEXIST; mio_seterrnum (mio, MIO_EEXIST);
return -1; return -1;
} }
} }
@ -132,7 +151,7 @@ int mio_sys_ctrlmux (mio_t* mio, mio_sys_mux_cmd_t cmd, mio_dev_t* dev, int dev_
{ {
if (cmd != MIO_SYS_MUX_CMD_INSERT) if (cmd != MIO_SYS_MUX_CMD_INSERT)
{ {
mio->errnum = MIO_ENOENT; mio_seterrnum (mio, MIO_ENOENT);
return -1; return -1;
} }
} }
@ -149,18 +168,13 @@ int mio_sys_ctrlmux (mio_t* mio, mio_sys_mux_cmd_t cmd, mio_dev_t* dev, int dev_
new_capa = MIO_ALIGN_POW2(mux->pd.size + 1, 256); new_capa = MIO_ALIGN_POW2(mux->pd.size + 1, 256);
tmp1 = MIO_MMGR_REALLOC(mio->mmgr, mux->pd.pfd, new_capa * MIO_SIZEOF(*tmp1)); tmp1 = mio_reallocmem(mio, mux->pd.pfd, new_capa * MIO_SIZEOF(*tmp1));
if (!tmp1) if (!tmp1) return -1;
{
mio->errnum = MIO_ESYSMEM;
return -1;
}
tmp2 = MIO_MMGR_REALLOC (mio->mmgr, mux->pd.dptr, new_capa * MIO_SIZEOF(*tmp2)); tmp2 = mio_reallocmem(mio, mux->pd.dptr, new_capa * MIO_SIZEOF(*tmp2));
if (!tmp2) if (!tmp2)
{ {
MIO_MMGR_FREE (mio->mmgr, tmp1); mio_freemem (mio, tmp1);
mio->errnum = MIO_ESYSMEM;
return -1; return -1;
} }
@ -217,50 +231,10 @@ int mio_sys_ctrlmux (mio_t* mio, mio_sys_mux_cmd_t cmd, mio_dev_t* dev, int dev_
return 0; return 0;
default: default:
mio->errnum = MIO_EINVAL; mio_seterrnum (mio, MIO_EINVAL);
return -1; return -1;
} }
}
#elif defined(USE_EPOLL) #elif defined(USE_EPOLL)
struct mio_sys_mux_t
{
int hnd;
struct epoll_event revs[100]; /* TODO: is it a good size? */
};
int mio_sys_initmux (mio_t* mio)
{
mio_sys_mux_t* mux;
mux = (mio_sys_mux_t*)mio_callocmem(mio, MIO_SIZEOF(*mux));
if (!mux) return -1;
mux->hnd = epoll_create (1000);
if (mux->hnd == -1)
{
mio_seterrwithsyserr (mio, 0, errno);
mio_freemem (mio, mux);
return -1;
}
mio->sys.mux = mux;
return 0;
}
void mio_sys_finimux (mio_t* mio)
{
if (mio->sys.mux)
{
close (mio->sys.mux->hnd);
mio_freemem (mio, mio->sys.mux);
mio->sys.mux = MIO_NULL;
}
}
int mio_sys_ctrlmux (mio_t* mio, mio_sys_mux_cmd_t cmd, mio_dev_t* dev, int dev_capa)
{
static int epoll_cmd[] = { EPOLL_CTL_ADD, EPOLL_CTL_MOD, EPOLL_CTL_DEL }; static int epoll_cmd[] = { EPOLL_CTL_ADD, EPOLL_CTL_MOD, EPOLL_CTL_DEL };
struct epoll_event ev; struct epoll_event ev;
@ -287,24 +261,14 @@ int mio_sys_ctrlmux (mio_t* mio, mio_sys_mux_cmd_t cmd, mio_dev_t* dev, int dev_
} }
return 0; return 0;
} #else
# error NO SUPPORTED MULTIPLEXER
#endif #endif
}
int mio_sys_waitmux (mio_t* mio, const mio_ntime_t* tmout, mio_sys_mux_evtcb_t event_handler) int mio_sys_waitmux (mio_t* mio, const mio_ntime_t* tmout, mio_sys_mux_evtcb_t event_handler)
{ {
#if defined(_WIN32) #if defined(USE_POLL)
/*
if (GetQueuedCompletionStatusEx (mio->iocp, mio->ovls, MIO_COUNTOF(mio->ovls), &nentries, timeout, FALSE) == FALSE)
{
// TODO: set errnum
return -1;
}
for (i = 0; i < nentries; i++)
{
}
*/
#elif defined(USE_POLL)
int nentries; int nentries;
mux = (mio_sys_mux_t*)mio->sys.mux; mux = (mio_sys_mux_t*)mio->sys.mux;