fixing some bugs regarding mux update - wip

This commit is contained in:
2019-01-28 17:41:50 +00:00
parent e9c42b28c6
commit 470e459781
8 changed files with 172 additions and 85 deletions

View File

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

View File

@ -430,6 +430,12 @@ mio_ooi_t mio_logbfmt (mio_t* mio, mio_bitmask_t mask, const mio_bch_t* fmt, ...
* it'll get turned back on */
mask |= (mio->log.default_type_mask & MIO_LOG_ALL_TYPES);
}
else if (!(mask & MIO_LOG_ALL_TYPES))
{
/* no type is set in the given mask and no default type is set.
* make it UNTYPED. */
mask |= MIO_LOG_UNTYPED;
}
fo.mask = mask;
fo.putch = put_ooch;
@ -458,6 +464,10 @@ mio_ooi_t mio_logufmt (mio_t* mio, mio_bitmask_t mask, const mio_uch_t* fmt, ...
mask &= ~MIO_LOG_UNTYPED;
mask |= (mio->log.default_type_mask & MIO_LOG_ALL_TYPES);
}
else if (!(mask & MIO_LOG_ALL_TYPES))
{
mask |= MIO_LOG_UNTYPED;
}
fo.mask = mask;
fo.putch = put_ooch;

View File

@ -128,31 +128,31 @@ static void tcp_sck_on_disconnect (mio_dev_sck_t* tcp)
switch (MIO_DEV_SCK_GET_PROGRESS(tcp))
{
case MIO_DEV_SCK_CONNECTING:
printf ("OUTGOING SESSION DISCONNECTED - FAILED TO CONNECT (%d) TO REMOTE SERVER\n", (int)tcp->sck);
MIO_INFO1 (tcp->mio, "OUTGOING SESSION DISCONNECTED - FAILED TO CONNECT (%d) TO REMOTE SERVER\n", (int)tcp->sck);
break;
case MIO_DEV_SCK_CONNECTING_SSL:
printf ("OUTGOING SESSION DISCONNECTED - FAILED TO SSL-CONNECT (%d) TO REMOTE SERVER\n", (int)tcp->sck);
MIO_INFO1 (tcp->mio, "OUTGOING SESSION DISCONNECTED - FAILED TO SSL-CONNECT (%d) TO REMOTE SERVER\n", (int)tcp->sck);
break;
case MIO_DEV_SCK_LISTENING:
printf ("SHUTTING DOWN THE SERVER SOCKET(%d)...\n", (int)tcp->sck);
MIO_INFO1 (tcp->mio, "SHUTTING DOWN THE SERVER SOCKET(%d)...\n", (int)tcp->sck);
break;
case MIO_DEV_SCK_CONNECTED:
printf ("OUTGOING CLIENT CONNECTION GOT TORN DOWN(%d).......\n", (int)tcp->sck);
MIO_INFO1 (tcp->mio, "OUTGOING CLIENT CONNECTION GOT TORN DOWN(%d).......\n", (int)tcp->sck);
break;
case MIO_DEV_SCK_ACCEPTING_SSL:
printf ("INCOMING SSL-ACCEPT GOT DISCONNECTED(%d) ....\n", (int)tcp->sck);
MIO_INFO1 (tcp->mio, "INCOMING SSL-ACCEPT GOT DISCONNECTED(%d) ....\n", (int)tcp->sck);
break;
case MIO_DEV_SCK_ACCEPTED:
printf ("INCOMING CLIENT BEING SERVED GOT DISCONNECTED(%d).......\n", (int)tcp->sck);
MIO_INFO1 (tcp->mio, "INCOMING CLIENT BEING SERVED GOT DISCONNECTED(%d).......\n", (int)tcp->sck);
break;
default:
printf ("SOCKET DEVICE DISCONNECTED (%d - %x)\n", (int)tcp->sck, (unsigned int)tcp->state);
MIO_INFO2 (tcp->mio, "SOCKET DEVICE DISCONNECTED (%d - %x)\n", (int)tcp->sck, (unsigned int)tcp->state);
break;
}
}
@ -174,14 +174,13 @@ static void tcp_sck_on_connect (mio_dev_sck_t* tcp)
if (tcp->state & MIO_DEV_SCK_CONNECTED)
{
mio_logbfmt (tcp->mio, MIO_LOG_UNTYPED | MIO_LOG_INFO, "DEVICE connected to a remote server... LOCAL %hs:%d REMOTE %hs:%d.",
buf1, mio_getsckaddrport(&tcp->localaddr), buf2, mio_getsckaddrport(&tcp->remoteaddr));
printf ("DEVICE connected to a remote server... LOCAL %s:%d REMOTE %s:%d.",
buf1, mio_getsckaddrport(&tcp->localaddr), buf2, mio_getsckaddrport(&tcp->remoteaddr));
MIO_INFO5 (tcp->mio, "DEVICE connected to a remote server... LOCAL %hs:%d REMOTE %hs:%d SCK: %d\n",
buf1, mio_getsckaddrport(&tcp->localaddr), buf2, mio_getsckaddrport(&tcp->remoteaddr), tcp->sck);
}
else if (tcp->state & MIO_DEV_SCK_ACCEPTED)
{
printf ("DEVICE accepted client device... .LOCAL %s:%d REMOTE %s:%d\n", buf1, mio_getsckaddrport(&tcp->localaddr), buf2, mio_getsckaddrport(&tcp->remoteaddr));
MIO_INFO5 (tcp->mio, "DEVICE accepted client device... .LOCAL %s:%d REMOTE %s:%d\n",
buf1, mio_getsckaddrport(&tcp->localaddr), buf2, mio_getsckaddrport(&tcp->remoteaddr), tcp->sck);
}
if (mio_dev_sck_write(tcp, "hello", 5, MIO_NULL, MIO_NULL) <= -1)
@ -195,24 +194,33 @@ static int tcp_sck_on_write (mio_dev_sck_t* tcp, mio_iolen_t wrlen, void* wrctx,
tcp_server_t* ts;
mio_ntime_t tmout;
if (wrlen <= -1)
{
printf ("TCP_SCK_ON_WRITE SEDING TIMED OUT...........\n");
mio_dev_sck_halt (tcp);
}
else
{
ts = (tcp_server_t*)(tcp + 1);
printf ("TCP_SCK_ON_WRITE >>> SENT MESSAGE %d of length %ld\n", ts->tally, (long int)wrlen);
if (wrlen <= -1)
{
MIO_INFO1 (tcp->mio, "TCP_SCK_ON_WRITE(%d) >>> SEDING TIMED OUT...........\n", (int)tcp->sck);
mio_dev_sck_halt (tcp);
}
else
{
ts = (tcp_server_t*)(tcp + 1);
if (wrlen == 0)
{
MIO_INFO1 (tcp->mio, "TCP_SCK_ON_WRITE(%d) >>> CLOSED WRITING END\n", (int)tcp->sck);
}
else
{
MIO_INFO3 (tcp->mio, "TCP_SCK_ON_WRITE(%d) >>> SENT MESSAGE %d of length %ld\n", (int)tcp->sck, ts->tally, (long int)wrlen);
}
ts->tally++;
// if (ts->tally >= 2) mio_dev_sck_halt (tcp);
ts->tally++;
// if (ts->tally >= 2) mio_dev_sck_halt (tcp);
printf ("TCP_SCK_ON_WRITE ENABLING READING..............................\n");
MIO_INIT_NTIME (&tmout, 5, 0);
//mio_dev_sck_read (tcp, 1);
mio_dev_sck_timedread (tcp, 1, &tmout);
}
MIO_INIT_NTIME (&tmout, 5, 0);
//mio_dev_sck_read (tcp, 1);
MIO_INFO3 (tcp->mio, "TCP_SCK_ON_WRITE(%d) >>> REQUESTING to READ with timeout of %ld.%08ld\n", (int)tcp->sck, (long int)tmout.sec, (long int)tmout.nsec);
mio_dev_sck_timedread (tcp, 1, &tmout);
}
return 0;
}
@ -223,44 +231,45 @@ static int x = 0;
if (len <= -1)
{
printf ("TCP_SCK_ON_READ STREAM DEVICE: TIMED OUT...\n");
MIO_INFO1 (tcp->mio, "TCP_SCK_ON_READ(%d) STREAM DEVICE: TIMED OUT...\n", (int)tcp->sck);
mio_dev_sck_halt (tcp);
return 0;
}
else if (len <= 0)
{
printf ("TCP_SCK_ON_READ STREAM DEVICE: EOF RECEIVED...\n");
MIO_INFO1 (tcp->mio, "TCP_SCK_ON_READ(%d) STREAM DEVICE: EOF RECEIVED...\n", (int)tcp->sck);
/* no outstanding request. but EOF */
mio_dev_sck_halt (tcp);
return 0;
}
printf ("TCP_SCK_ON_READ read %d\n", (int)len);
MIO_INFO2 (tcp->mio, "TCP_SCK_ON_READ(%d) - received %d bytes\n", (int)tcp->sck, (int)len);
{
mio_ntime_t tmout;
{
mio_ntime_t tmout;
static char a ='A';
char* xxx = malloc (1000000);
memset (xxx, a++ ,1000000);
static char a ='A';
char* xxx = malloc (1000000);
memset (xxx, a++ ,1000000);
printf ("TCP_SCK_ON_READ initiating write... of %d\n", 1000000);
//return mio_dev_sck_write (tcp, "HELLO", 5, MIO_NULL);
MIO_INIT_NTIME (&tmout, 5, 0);
n = mio_dev_sck_timedwrite (tcp, xxx, 1000000, &tmout, MIO_NULL, MIO_NULL);
free (xxx);
MIO_INFO2 (tcp->mio, "TCP_SCK_ON_READ(%d) >>> REQUESTING to write data of %d bytes\n", (int)tcp->sck, 1000000);
//return mio_dev_sck_write (tcp, "HELLO", 5, MIO_NULL);
MIO_INIT_NTIME (&tmout, 5, 0);
n = mio_dev_sck_timedwrite(tcp, xxx, 1000000, &tmout, MIO_NULL, MIO_NULL);
free (xxx);
if (n <= -1) return -1;
}
if (n <= -1) return -1;
}
printf ("TCP_SCK_ON_READ DISABLING READING..............................\n");
MIO_INFO1 (tcp->mio, "TCP_SCK_ON_READ(%d) - DISABLING READ\n", (int)tcp->sck);
mio_dev_sck_read (tcp, 0);
printf ("TCP_SCK_ON_READ WRITING 0.............................\n");
#if 0
MIO_INFO1 (tcp->mio, "TCP_SCK_ON_READ(%d) - REQUESTING TO CLOSE WRITING END\n", (int)tcp->sck);
/* post the write finisher - close the writing end */
n = mio_dev_sck_write(tcp, MIO_NULL, 0, MIO_NULL, MIO_NULL);
if (n <= -1) return -1;
#endif
return 0;

View File

@ -508,6 +508,9 @@
/* Define to 1 if you have the <stdlib.h> header file. */
#undef HAVE_STDLIB_H
/* strftime supports %z */
#undef HAVE_STRFTIME_SMALL_Z
/* Define to 1 if you have the <strings.h> header file. */
#undef HAVE_STRINGS_H

View File

@ -912,6 +912,7 @@ int mio_dev_ioctl (mio_dev_t* dev, int cmd, void* arg)
int mio_dev_watch (mio_dev_t* dev, mio_dev_watch_cmd_t cmd, int events)
{
mio_t* mio = dev->mio;
int mux_cmd;
int dev_capa;
@ -1003,24 +1004,26 @@ static void on_read_timeout (mio_t* mio, const mio_ntime_t* now, mio_tmrjob_t* j
static int __dev_read (mio_dev_t* dev, int enabled, const mio_ntime_t* tmout, void* rdctx)
{
mio_t* mio = dev->mio;
if (dev->dev_capa & MIO_DEV_CAPA_IN_CLOSED)
{
dev->mio->errnum = MIO_ENOCAPA;
mio_seterrbfmt (mio, MIO_ENOCAPA, "unable to read closed device");
return -1;
}
if (enabled)
{
dev->dev_capa &= ~MIO_DEV_CAPA_IN_DISABLED;
if (!dev->mio->in_exec && (dev->dev_capa & MIO_DEV_CAPA_IN_WATCHED)) goto renew_watch_now;
if (/*!mio->in_exec && */!(dev->dev_capa & MIO_DEV_CAPA_IN_WATCHED)) goto renew_watch_now;
}
else
{
dev->dev_capa |= MIO_DEV_CAPA_IN_DISABLED;
if (!dev->mio->in_exec && !(dev->dev_capa & MIO_DEV_CAPA_IN_WATCHED)) goto renew_watch_now;
if (/*!mio->in_exec && */(dev->dev_capa & MIO_DEV_CAPA_IN_WATCHED)) goto renew_watch_now;
}
dev->mio->renew_watch = 1;
mio->renew_watch = 1;
goto update_timer;
renew_watch_now:
@ -1031,7 +1034,7 @@ update_timer:
if (dev->rtmridx != MIO_TMRIDX_INVALID)
{
/* read timeout already on the socket. remove it first */
mio_deltmrjob (dev->mio, dev->rtmridx);
mio_deltmrjob (mio, dev->rtmridx);
dev->rtmridx = MIO_TMRIDX_INVALID;
}
@ -1046,7 +1049,7 @@ update_timer:
tmrjob.handler = on_read_timeout;
tmrjob.idxptr = &dev->rtmridx;
dev->rtmridx = mio_instmrjob(dev->mio, &tmrjob);
dev->rtmridx = mio_instmrjob(mio, &tmrjob);
if (dev->rtmridx == MIO_TMRIDX_INVALID)
{
/* if timer registration fails, timeout will never be triggered */
@ -1060,32 +1063,6 @@ update_timer:
int mio_dev_read (mio_dev_t* dev, int enabled)
{
return __dev_read(dev, enabled, MIO_NULL, MIO_NULL);
#if 0
if (dev->dev_capa & MIO_DEV_CAPA_IN_CLOSED)
{
dev->mio->errnum = MIO_ENOCAPA;
return -1;
}
if (enabled)
{
dev->dev_capa &= ~MIO_DEV_CAPA_IN_DISABLED;
if (!dev->mio->in_exec && (dev->dev_capa & MIO_DEV_CAPA_IN_WATCHED)) goto renew_watch_now;
}
else
{
dev->dev_capa |= MIO_DEV_CAPA_IN_DISABLED;
if (!dev->mio->in_exec && !(dev->dev_capa & MIO_DEV_CAPA_IN_WATCHED)) goto renew_watch_now;
}
dev->mio->renew_watch = 1;
return 0;
renew_watch_now:
if (mio_dev_watch(dev, MIO_DEV_WATCH_RENEW, 0) <= -1) return -1;
return 0;
#endif
}
int mio_dev_timedread (mio_dev_t* dev, int enabled, const mio_ntime_t* tmout)
@ -1247,7 +1224,7 @@ enqueue_data:
}
MIO_WQ_ENQ (&dev->wq, q);
if (!dev->mio->in_exec && !(dev->dev_capa & MIO_DEV_CAPA_OUT_WATCHED))
if (!mio->in_exec && !(dev->dev_capa & MIO_DEV_CAPA_OUT_WATCHED))
{
/* if output is not being watched, arrange to do so */
if (mio_dev_watch(dev, MIO_DEV_WATCH_RENEW, 0) <= -1)
@ -1259,7 +1236,7 @@ enqueue_data:
}
else
{
dev->mio->renew_watch = 1;
mio->renew_watch = 1;
}
return 0; /* request pused to a write queue. */