kept read timeout after successful read until read is disabled

This commit is contained in:
hyung-hwan 2019-01-17 08:51:10 +00:00
parent 115031d2ce
commit 0072ab5bd8
3 changed files with 40 additions and 8 deletions

View File

@ -215,6 +215,7 @@ printf ("TCP_SCK_ON_WRITE ENABLING READING..............................\n");
static int tcp_sck_on_read (mio_dev_sck_t* tcp, const void* buf, mio_iolen_t len, const mio_sckaddr_t* srcaddr) static int tcp_sck_on_read (mio_dev_sck_t* tcp, const void* buf, mio_iolen_t len, const mio_sckaddr_t* srcaddr)
{ {
int n; int n;
static int x = 0;
if (len <= -1) if (len <= -1)
{ {
@ -448,7 +449,7 @@ static int schedule_icmp_wait (mio_dev_sck_t* dev)
assert (icmpxtn->tmout_jobidx == MIO_TMRIDX_INVALID); assert (icmpxtn->tmout_jobidx == MIO_TMRIDX_INVALID);
return (mio_instmrjob (dev->mio, &tmrjob) == MIO_TMRIDX_INVALID)? -1: 0; return (mio_instmrjob(dev->mio, &tmrjob) == MIO_TMRIDX_INVALID)? -1: 0;
} }
static int icmp_sck_on_read (mio_dev_sck_t* dev, const void* data, mio_iolen_t dlen, const mio_sckaddr_t* srcaddr) static int icmp_sck_on_read (mio_dev_sck_t* dev, const void* data, mio_iolen_t dlen, const mio_sckaddr_t* srcaddr)
@ -552,7 +553,7 @@ static int setup_ping4_tester (mio_t* mio)
/* ========================================================================= */ /* ========================================================================= */
#if 0 #if 1
static mio_t* g_mio; static mio_t* g_mio;
static void handle_signal (int sig) static void handle_signal (int sig)
@ -771,8 +772,7 @@ oops:
return -1; return -1;
} }
#endif #else
#if 1
int main (int argc, char* argv[]) int main (int argc, char* argv[])
{ {
mio_t* mio = MIO_NULL; mio_t* mio = MIO_NULL;

View File

@ -61,6 +61,8 @@ static int kill_and_free_device (mio_dev_t* dev, int force);
} while (0) } while (0)
static void on_read_timeout (mio_t* mio, const mio_ntime_t* now, mio_tmrjob_t* job);
static void on_write_timeout (mio_t* mio, const mio_ntime_t* now, mio_tmrjob_t* job);
/* ========================================================================= */ /* ========================================================================= */
#if defined(USE_POLL) #if defined(USE_POLL)
@ -631,13 +633,34 @@ static MIO_INLINE void handle_event (mio_dev_t* dev, int events, int rdhup)
dev = MIO_NULL; dev = MIO_NULL;
break; break;
} }
else if (x == 0)
if (dev->rtmridx != MIO_TMRIDX_INVALID)
{
/* delete the read timeout job on the device as the
* read operation will be reported below. */
mio_tmrjob_t tmrjob;
MIO_MEMSET (&tmrjob, 0, MIO_SIZEOF(tmrjob));
tmrjob.ctx = dev;
mio_gettime (&tmrjob.when);
mio_addtime (&tmrjob.when, &dev->rtmout, &tmrjob.when);
tmrjob.handler = on_read_timeout;
tmrjob.idxptr = &dev->rtmridx;
mio_updtmrjob (mio, dev->rtmridx, &tmrjob);
/*mio_deltmrjob (mio, dev->rtmridx);
dev->rtmridx = MIO_TMRIDX_INVALID;*/
}
if (x == 0)
{ {
/* no data is available - EWOULDBLOCK or something similar */ /* no data is available - EWOULDBLOCK or something similar */
break; break;
} }
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
@ -645,6 +668,7 @@ static MIO_INLINE void handle_event (mio_dev_t* dev, int events, int rdhup)
dev->dev_capa |= MIO_DEV_CAPA_IN_CLOSED; dev->dev_capa |= MIO_DEV_CAPA_IN_CLOSED;
mio->renew_watch = 1; mio->renew_watch = 1;
/* 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 ||
(dev->dev_capa & MIO_DEV_CAPA_OUT_CLOSED)) (dev->dev_capa & MIO_DEV_CAPA_OUT_CLOSED))
@ -926,6 +950,7 @@ mio_dev_t* mio_makedev (mio_t* mio, mio_oow_t dev_size, mio_dev_mth_t* dev_mth,
dev->dev_capa = MIO_DEV_CAPA_IN | MIO_DEV_CAPA_OUT; dev->dev_capa = MIO_DEV_CAPA_IN | MIO_DEV_CAPA_OUT;
dev->dev_mth = dev_mth; dev->dev_mth = dev_mth;
dev->dev_evcb = dev_evcb; dev->dev_evcb = dev_evcb;
mio_inittime (&dev->rtmout, 0, 0);
dev->rtmridx = MIO_TMRIDX_INVALID; dev->rtmridx = MIO_TMRIDX_INVALID;
MIO_WQ_INIT (&dev->wq); MIO_WQ_INIT (&dev->wq);
dev->cw_count = 0; dev->cw_count = 0;
@ -1088,7 +1113,6 @@ void mio_killdev (mio_t* mio, mio_dev_t* dev)
if (dev->rtmridx != MIO_TMRIDX_INVALID) if (dev->rtmridx != MIO_TMRIDX_INVALID)
{ {
printf ("REMOVING.... TIMER FOR DEV\n");
mio_deltmrjob (mio, dev->rtmridx); mio_deltmrjob (mio, dev->rtmridx);
dev->rtmridx = MIO_TMRIDX_INVALID; dev->rtmridx = MIO_TMRIDX_INVALID;
} }
@ -1324,6 +1348,7 @@ update_timer:
/* if timer registration fails, timeout will never be triggered */ /* if timer registration fails, timeout will never be triggered */
return -1; return -1;
} }
dev->rtmout = *tmout;
} }
return 0; return 0;
} }

View File

@ -307,6 +307,7 @@ struct mio_wq_t
int dev_capa; \ int dev_capa; \
mio_dev_mth_t* dev_mth; \ mio_dev_mth_t* dev_mth; \
mio_dev_evcb_t* dev_evcb; \ mio_dev_evcb_t* dev_evcb; \
mio_ntime_t rtmout; \
mio_tmridx_t rtmridx; \ mio_tmridx_t rtmridx; \
mio_wq_t wq; \ mio_wq_t wq; \
mio_oow_t cw_count; \ mio_oow_t cw_count; \
@ -431,7 +432,13 @@ MIO_EXPORT int mio_dev_watch (
MIO_EXPORT int mio_dev_read ( MIO_EXPORT int mio_dev_read (
mio_dev_t* dev, mio_dev_t* dev,
int enabled int enabled
);
MIO_EXPORT int mio_dev_timedread (
mio_dev_t* dev,
int enabled,
const mio_ntime_t* tmout
); );
/** /**