fixed the mux code using poll()

This commit is contained in:
hyung-hwan 2019-04-10 09:25:34 +00:00
parent cc9a038760
commit 898bf787d5
4 changed files with 16 additions and 14 deletions

View File

@ -67,9 +67,9 @@ install-data-hook:
@echo "#define _MIO_CFG_H_" >> "$(DESTDIR)$(includedir)/mio-cfg.h" @echo "#define _MIO_CFG_H_" >> "$(DESTDIR)$(includedir)/mio-cfg.h"
@$(EGREP) "#define[ ]+MIO_" "$(abs_builddir)/mio-cfg.h" >> "$(DESTDIR)$(includedir)/mio-cfg.h" @$(EGREP) "#define[ ]+MIO_" "$(abs_builddir)/mio-cfg.h" >> "$(DESTDIR)$(includedir)/mio-cfg.h"
@echo "#endif" >> "$(DESTDIR)$(includedir)/mio-cfg.h" @echo "#endif" >> "$(DESTDIR)$(includedir)/mio-cfg.h"
@$(RM) "$(DESTDIR)$(includedir)/mio-cfg.h.in" @rm -f "$(DESTDIR)$(includedir)/mio-cfg.h.in"
@$(SED) 's|/\*#define MIO_HAVE_CFG_H\*/|#define MIO_HAVE_CFG_H|' "$(srcdir)/mio-cmn.h" > "$(DESTDIR)$(includedir)/mio-cmn.h" @$(SED) 's|/\*#define MIO_HAVE_CFG_H\*/|#define MIO_HAVE_CFG_H|' "$(srcdir)/mio-cmn.h" > "$(DESTDIR)$(includedir)/mio-cmn.h"
uninstall-hook: uninstall-hook:
@$(RM) "$(DESTDIR)$(includedir)/mio-cfg.h" @rm -f "$(DESTDIR)$(includedir)/mio-cfg.h"

View File

@ -997,11 +997,11 @@ install-data-hook:
@echo "#define _MIO_CFG_H_" >> "$(DESTDIR)$(includedir)/mio-cfg.h" @echo "#define _MIO_CFG_H_" >> "$(DESTDIR)$(includedir)/mio-cfg.h"
@$(EGREP) "#define[ ]+MIO_" "$(abs_builddir)/mio-cfg.h" >> "$(DESTDIR)$(includedir)/mio-cfg.h" @$(EGREP) "#define[ ]+MIO_" "$(abs_builddir)/mio-cfg.h" >> "$(DESTDIR)$(includedir)/mio-cfg.h"
@echo "#endif" >> "$(DESTDIR)$(includedir)/mio-cfg.h" @echo "#endif" >> "$(DESTDIR)$(includedir)/mio-cfg.h"
@$(RM) "$(DESTDIR)$(includedir)/mio-cfg.h.in" @rm -f "$(DESTDIR)$(includedir)/mio-cfg.h.in"
@$(SED) 's|/\*#define MIO_HAVE_CFG_H\*/|#define MIO_HAVE_CFG_H|' "$(srcdir)/mio-cmn.h" > "$(DESTDIR)$(includedir)/mio-cmn.h" @$(SED) 's|/\*#define MIO_HAVE_CFG_H\*/|#define MIO_HAVE_CFG_H|' "$(srcdir)/mio-cmn.h" > "$(DESTDIR)$(includedir)/mio-cmn.h"
uninstall-hook: uninstall-hook:
@$(RM) "$(DESTDIR)$(includedir)/mio-cfg.h" @rm -f "$(DESTDIR)$(includedir)/mio-cfg.h"
# Tell versions [3.59,3.63) of GNU make to not export all variables. # Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded. # Otherwise a system limit (for SysV at least) may be exceeded.

View File

@ -666,7 +666,7 @@ int main (int argc, char* argv[])
} }
*/ */
memset (&tcp_make, 0, MIO_SIZEOF(&tcp_make)); memset (&tcp_make, 0, MIO_SIZEOF(tcp_make));
tcp_make.type = MIO_DEV_SCK_TCP4; tcp_make.type = MIO_DEV_SCK_TCP4;
tcp_make.on_write = tcp_sck_on_write; tcp_make.on_write = tcp_sck_on_write;
tcp_make.on_read = tcp_sck_on_read; tcp_make.on_read = tcp_sck_on_read;
@ -698,7 +698,7 @@ int main (int argc, char* argv[])
} }
/* -------------------------------------------------------------- */ /* -------------------------------------------------------------- */
memset (&tcp_make, 0, MIO_SIZEOF(&tcp_make)); memset (&tcp_make, 0, MIO_SIZEOF(tcp_make));
tcp_make.type = MIO_DEV_SCK_TCP4; tcp_make.type = MIO_DEV_SCK_TCP4;
tcp_make.on_write = tcp_sck_on_write; tcp_make.on_write = tcp_sck_on_write;
tcp_make.on_read = tcp_sck_on_read; tcp_make.on_read = tcp_sck_on_read;
@ -733,7 +733,7 @@ int main (int argc, char* argv[])
} }
/* -------------------------------------------------------------- */ /* -------------------------------------------------------------- */
memset (&tcp_make, 0, MIO_SIZEOF(&tcp_make)); memset (&tcp_make, 0, MIO_SIZEOF(tcp_make));
tcp_make.type = MIO_DEV_SCK_TCP4; tcp_make.type = MIO_DEV_SCK_TCP4;
tcp_make.on_write = tcp_sck_on_write; tcp_make.on_write = tcp_sck_on_write;
tcp_make.on_read = tcp_sck_on_read; tcp_make.on_read = tcp_sck_on_read;
@ -915,7 +915,7 @@ int main (int argc, char* argv[])
goto oops; goto oops;
} }
memset (&tcp_make, 0, MIO_SIZEOF(&tcp_make)); memset (&tcp_make, 0, MIO_SIZEOF(tcp_make));
tcp_make.type = MIO_DEV_SCK_TCP4; tcp_make.type = MIO_DEV_SCK_TCP4;
tcp_make.on_write = tcp_sck_on_write; tcp_make.on_write = tcp_sck_on_write;
tcp_make.on_read = tcp_sck_on_read; tcp_make.on_read = tcp_sck_on_read;

View File

@ -64,8 +64,11 @@ int mio_sys_ctrlmux (mio_t* mio, mio_sys_mux_cmd_t cmd, mio_dev_t* dev, int dev_
#if defined(USE_POLL) #if defined(USE_POLL)
mio_sys_mux_t* mux = &mio->sysdep->mux; mio_sys_mux_t* mux = &mio->sysdep->mux;
mio_oow_t idx; mio_oow_t idx;
mio_syshnd_t hnd;
if (dev->hnd >= mux->map.capa) hnd = dev->dev_mth->getsyshnd(dev);
if (hnd >= mux->map.capa)
{ {
mio_oow_t new_capa; mio_oow_t new_capa;
mio_oow_t* tmp; mio_oow_t* tmp;
@ -220,11 +223,10 @@ int mio_sys_ctrlmux (mio_t* mio, mio_sys_mux_cmd_t cmd, mio_dev_t* dev, int dev_
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(USE_POLL) #if defined(USE_POLL)
int nentries; mio_sys_mux_t* mux = &mio->sysdep->mux;
int nentries, i;
mux = (mio_sys_mux_t*)mio->sysdep->mux; nentries = poll(mux->pd.pfd, mux->pd.size, MIO_SECNSEC_TO_MSEC(tmout->sec, tmout->nsec));
nentries = poll(mux->pd.pfd, mux->pd.size, MIO_SECNSEC_TO_MSEC(tmout.sec, tmout.nsec));
if (nentries == -1) if (nentries == -1)
{ {
if (errno == EINTR) return 0; if (errno == EINTR) return 0;
@ -248,7 +250,7 @@ int mio_sys_waitmux (mio_t* mio, const mio_ntime_t* tmout, mio_sys_mux_evtcb_t e
if (mux->pd.pfd[i].revents & POLLERR) events |= MIO_DEV_EVENT_ERR; if (mux->pd.pfd[i].revents & POLLERR) events |= MIO_DEV_EVENT_ERR;
if (mux->pd.pfd[i].revents & POLLHUP) events |= MIO_DEV_EVENT_HUP; if (mux->pd.pfd[i].revents & POLLHUP) events |= MIO_DEV_EVENT_HUP;
handle_event (dev, events, 0); event_handler (mio, dev, events, 0);
} }
} }