added a debug message

This commit is contained in:
hyung-hwan 2020-07-28 10:21:10 +00:00
parent 190c1effc5
commit 07e6a1ac70
4 changed files with 66 additions and 27 deletions

View File

@ -154,6 +154,7 @@ static int listener_on_read (mio_dev_sck_t* sck, const void* buf, mio_iolen_t le
if ((x = mio_htrd_feed(cli->htrd, buf, len, &rem)) <= -1)
{
MIO_DEBUG3 (mio, "HTTS(%p) - feed error onto client htrd %p(%d)\n", cli->htts, sck, (int)sck->hnd);
goto oops;
}
@ -173,7 +174,7 @@ static int listener_on_read (mio_dev_sck_t* sck, const void* buf, mio_iolen_t le
oops:
mio_dev_sck_halt (sck);
return 0;
return 0; /* still return success here. instead call halt() */
}
static int listener_on_write (mio_dev_sck_t* sck, mio_iolen_t wrlen, void* wrctx, const mio_skad_t* dstaddr)
@ -261,6 +262,7 @@ static void listener_on_disconnect (mio_dev_sck_t* sck)
MIO_ASSERT (mio, cli->sbuf == MIO_NULL);
MIO_DEBUG2 (mio, "HTTS(%p) - listener socket disconnect %p\n", cli->htts, sck);
printf ("listener socket disconnect..................sck %p %d\n", sck, sck->hnd);
cli->htts->lsck = MIO_NULL; /* let the htts service forget about this listening socket */
}
else
@ -318,7 +320,7 @@ mio_svc_htts_t* mio_svc_htts_start (mio_t* mio, mio_dev_sck_bind_t* sck_bind, mi
if (!htts->lsck) goto oops;
/* the name 'cli' for the listening socket is awkard.
* the listing socket will use the htts and sck fields for tracking only.
* the listening socket will use the htts and sck fields for tracking only.
* each accepted client socket gets the extension size for this size as well.
* most of other fields are used for client management */
cli = (mio_svc_htts_cli_t*)mio_dev_sck_getxtn(htts->lsck);

View File

@ -324,7 +324,6 @@ static void fire_cwq_handlers (mio_t* mio)
cwq = MIO_CWQ_HEAD(&mio->cwq);
if (cwq->dev->dev_evcb->on_write(cwq->dev, cwq->olen, cwq->ctx, &cwq->dstaddr) <= -1)
{
MIO_DEBUG1 (mio, "MIO - Error returned by on_write() of device %p in cwq\n", cwq->dev);
dev_to_halt = cwq->dev;
}
else
@ -347,7 +346,11 @@ static void fire_cwq_handlers (mio_t* mio)
mio_freemem (mio, cwq);
}
if (dev_to_halt) mio_dev_halt (dev_to_halt);
if (dev_to_halt)
{
MIO_DEBUG1 (mio, "DEV(%p) - halting a device for on_write error upon write completion[1]\n", dev_to_halt);
mio_dev_halt (dev_to_halt);
}
}
}
@ -368,7 +371,6 @@ static void fire_cwq_handlers_for_dev (mio_t* mio, mio_dev_t* dev, int for_kill)
if (cwq->dev->dev_evcb->on_write(cwq->dev, cwq->olen, cwq->ctx, &cwq->dstaddr) <= -1)
{
MIO_DEBUG1 (mio, "MIO - Error returned by on_write() of device %p in cwq\n", cwq->dev);
dev_to_halt = cwq->dev;
}
else
@ -392,7 +394,11 @@ static void fire_cwq_handlers_for_dev (mio_t* mio, mio_dev_t* dev, int for_kill)
mio_freemem (mio, cwq);
}
if (!for_kill && dev_to_halt) mio_dev_halt (dev_to_halt);
if (!for_kill && dev_to_halt)
{
MIO_DEBUG1 (mio, "DEV(%p) - halting a device for on_write error upon write completion[2]\n", dev_to_halt);
mio_dev_halt (dev_to_halt);
}
}
cwq = next;
}
@ -421,6 +427,7 @@ static MIO_INLINE void handle_event (mio_t* mio, mio_dev_t* dev, int events, int
x = dev->dev_evcb->ready(dev, xevents);
if (x <= -1)
{
MIO_DEBUG1 (mio, "DEV(%p) - halting a device for ready callback error\n", dev);
mio_dev_halt (dev);
return;
}
@ -461,6 +468,7 @@ static MIO_INLINE void handle_event (mio_t* mio, mio_dev_t* dev, int events, int
}
if (x <= -1)
{
MIO_DEBUG1 (mio, "DEV(%p) - halting a device for write failure\n", dev);
mio_dev_halt (dev);
dev = MIO_NULL;
break;
@ -504,7 +512,7 @@ static MIO_INLINE void handle_event (mio_t* mio, mio_dev_t* dev, int events, int
if (y <= -1)
{
MIO_DEBUG1 (mio, "MIO - Error returned by on_write() of device %p\n", dev);
MIO_DEBUG1 (mio, "DEV(%p) - halting a device for on_write error\n", dev);
mio_dev_halt (dev);
dev = MIO_NULL;
break;
@ -532,6 +540,7 @@ static MIO_INLINE void handle_event (mio_t* mio, mio_dev_t* dev, int events, int
/* no pending request to write */
if ((dev->dev_cap & MIO_DEV_CAP_IN_CLOSED) && (dev->dev_cap & MIO_DEV_CAP_OUT_CLOSED))
{
MIO_DEBUG1 (mio, "DEV(%p) - halting a device for closed input and output in output handler\n", dev);
mio_dev_halt (dev);
dev = MIO_NULL;
}
@ -557,6 +566,7 @@ static MIO_INLINE void handle_event (mio_t* mio, mio_dev_t* dev, int events, int
x = dev->dev_mth->read(dev, mio->bigbuf, &len, &srcaddr);
if (x <= -1)
{
MIO_DEBUG1 (mio, "DEV(%p) - halting a device for read failure\n", dev);
mio_dev_halt (dev);
dev = MIO_NULL;
break;
@ -620,6 +630,7 @@ static MIO_INLINE void handle_event (mio_t* mio, mio_dev_t* dev, int events, int
{
/* 1. input ended and its reporting failed or
* 2. input ended and no writing is possible */
MIO_DEBUG1 (mio, "DEV(%p) - halting a stream device for on_read failure while output is closed\n", dev);
mio_dev_halt (dev);
dev = MIO_NULL;
}
@ -637,6 +648,7 @@ static MIO_INLINE void handle_event (mio_t* mio, mio_dev_t* dev, int events, int
y = dev->dev_evcb->on_read(dev, mio->bigbuf, len, &srcaddr);
if (y <= -1)
{
MIO_DEBUG1 (mio, "DEV(%p) - halting a non-stream device for on_read failure while output is closed\n", dev);
mio_dev_halt (dev);
dev = MIO_NULL;
break;
@ -689,6 +701,7 @@ static MIO_INLINE void handle_event (mio_t* mio, mio_dev_t* dev, int events, int
if ((dev->dev_cap & MIO_DEV_CAP_IN_CLOSED) &&
(dev->dev_cap & MIO_DEV_CAP_OUT_CLOSED))
{
MIO_DEBUG1 (mio, "DEV(%p) - halting a device for closed input and output\n", dev);
mio_dev_halt (dev);
dev = MIO_NULL;
}
@ -697,6 +710,7 @@ static MIO_INLINE void handle_event (mio_t* mio, mio_dev_t* dev, int events, int
skip_evcb:
if (dev && (dev->dev_cap & MIO_DEV_CAP_RENEW_REQUIRED) && mio_dev_watch(dev, MIO_DEV_WATCH_RENEW, MIO_DEV_EVENT_IN) <= -1)
{
MIO_DEBUG1 (mio, "DEV(%p) - halting a device for wathcer renewal failure\n", dev);
mio_dev_halt (dev);
dev = MIO_NULL;
}
@ -1162,7 +1176,11 @@ static void on_read_timeout (mio_t* mio, const mio_ntime_t* now, mio_tmrjob_t* j
MIO_ASSERT (mio, dev->rtmridx == MIO_TMRIDX_INVALID);
if (x <= -1) mio_dev_halt (dev);
if (x <= -1)
{
MIO_DEBUG1 (mio, "DEV(%p) - halting a device for on_read error upon timeout\n", dev);
mio_dev_halt (dev);
}
}
static int __dev_read (mio_dev_t* dev, int enabled, const mio_ntime_t* tmout, void* rdctx)
@ -1249,7 +1267,11 @@ static void on_write_timeout (mio_t* mio, const mio_ntime_t* now, mio_tmrjob_t*
MIO_WQ_UNLINK(q);
mio_freemem (mio, q);
if (x <= -1) mio_dev_halt (dev);
if (x <= -1)
{
MIO_DEBUG1 (mio, "DEV(%p) - halting a device for on_write error upon timeout\n", dev);
mio_dev_halt (dev);
}
}
static MIO_INLINE int __enqueue_completed_write (mio_dev_t* dev, mio_iolen_t len, void* wrctx, const mio_devaddr_t* dstaddr)

View File

@ -268,6 +268,7 @@ static void connect_timedout (mio_t* mio, const mio_ntime_t* now, mio_tmrjob_t*
* doesn't need to be deleted when it gets connected for this check
* here. this libarary, however, deletes the job when it gets
* connected. */
MIO_DEBUG1 (mio, "SCK(%p) - connect timed out. halting\n", rdev);
mio_dev_sck_halt (rdev);
}
}
@ -280,6 +281,7 @@ static void ssl_accept_timedout (mio_t* mio, const mio_ntime_t* now, mio_tmrjob_
if (rdev->state & MIO_DEV_SCK_ACCEPTING_SSL)
{
MIO_DEBUG1 (mio, "SCK(%p) - ssl-accept timed out. halting\n", rdev);
mio_dev_sck_halt(rdev);
}
}
@ -292,6 +294,7 @@ static void ssl_connect_timedout (mio_t* mio, const mio_ntime_t* now, mio_tmrjob
if (rdev->state & MIO_DEV_SCK_CONNECTING_SSL)
{
MIO_DEBUG1 (mio, "SCK(%p) - ssl-connect timed out. halting\n", rdev);
mio_dev_sck_halt(rdev);
}
}
@ -420,8 +423,11 @@ static int dev_sck_make_client (mio_dev_t* dev, void* ctx)
rdev->tmrjob_index = MIO_TMRIDX_INVALID;
rdev->side_chan = MIO_SYSHND_INVALID;
if (mio_makesyshndasync(mio, rdev->hnd) <= -1 ||
mio_makesyshndcloexec(mio, rdev->hnd) <= -1) return -1;
/*if (mio_makesyshndasync(mio, rdev->hnd) <= -1 ||
mio_makesyshndcloexec(mio, rdev->hnd) <= -1) { printf ("cannot make sysnhnd async or cloexec %d\n", rdev->hnd); return -1; }
*/
mio_makesyshndasync(mio, rdev->hnd);
mio_makesyshndcloexec(mio, rdev->hnd);
return 0;
}
@ -542,9 +548,13 @@ static int dev_sck_read_stateless (mio_dev_t* dev, void* buf, mio_iolen_t* len,
x = recvfrom(rdev->hnd, buf, *len, 0, (struct sockaddr*)&rdev->remoteaddr, &srcaddrlen);
if (x <= -1)
{
if (errno == EINPROGRESS || errno == EWOULDBLOCK || errno == EAGAIN) return 0; /* no data available */
if (errno == EINTR) return 0;
mio_seterrwithsyserr (mio, 0, errno);
int eno = errno;
if (eno == EINPROGRESS || eno == EWOULDBLOCK || eno == EAGAIN) return 0; /* no data available */
if (eno == EINTR) return 0;
mio_seterrwithsyserr (mio, 0, eno);
MIO_DEBUG2 (mio, "SCK(%p) - recvfrom failure - %hs", rdev, strerror(eno));
return -1;
}
@ -1402,7 +1412,8 @@ static int harvest_outgoing_connection (mio_dev_sck_t* rdev)
if (MIO_IS_POS_NTIME(&rdev->tmout) &&
schedule_timer_job_at(rdev, &rdev->tmout, ssl_connect_timedout) <= -1)
{
mio_dev_halt ((mio_dev_t*)rdev);
MIO_DEBUG1 (mio, "SCK(%p) - ssl-connect timeout scheduling failed. halting\n", rdev);
mio_dev_sck_halt (rdev);
}
return 0;
@ -1458,13 +1469,11 @@ static int make_accepted_client_connection (mio_dev_sck_t* rdev, mio_syshnd_t cl
clidev = (mio_dev_sck_t*)mio_dev_make(mio, rdev->dev_size, &dev_mth_clisck, rdev->dev_evcb, &clisck);
if (MIO_UNLIKELY(!clidev))
{
MIO_DEBUG3 (mio, "SCK(%p) - unable to make a new accepted device for %d - %js\n", rdev, (int)clisck, mio_geterrmsg(mio));
close (clisck);
return -1;
}
// TODO:
//if (clidev->type == MIO_DEV_SCK_QX) change it to the specified type..
// TODO:
clidev->type = clisck_type;
MIO_ASSERT (mio, clidev->hnd == clisck);
@ -1538,7 +1547,8 @@ static int make_accepted_client_connection (mio_dev_sck_t* rdev, mio_syshnd_t cl
schedule_timer_job_after(clidev, &rdev->tmout, ssl_accept_timedout) <= -1)
{
/* timer job scheduling failed. halt the device */
mio_dev_halt ((mio_dev_t*)clidev);
MIO_DEBUG1 (mio, "SCK(%p) - ssl-accept timeout scheduling failed. halting\n", rdev);
mio_dev_sck_halt (clidev);
}
}
else
@ -1906,7 +1916,8 @@ static int dev_evcb_sck_on_read_qx (mio_dev_t* dev, const void* data, mio_iolen_
if (dlen != MIO_SIZEOF(*qxmsg))
{
mio_seterrbfmt (mio, MIO_EINVAL, "wrong qx packet size");
return -1;
printf ("unable wrong packet size... \n");
return 0;
}
qxmsg = (mio_dev_sck_qxmsg_t*)data;
@ -1914,14 +1925,16 @@ static int dev_evcb_sck_on_read_qx (mio_dev_t* dev, const void* data, mio_iolen_
{
if (make_accepted_client_connection(rdev, qxmsg->syshnd, &qxmsg->remoteaddr, qxmsg->scktype) <= -1)
{
printf ("unable to accept new client connection\n");
close (qxmsg->syshnd);
return -1;
}
}
else
{
printf ("unknown qx xommand code\n");
mio_seterrbfmt (mio, MIO_EINVAL, "wrong qx command code");
return -1;
return 0;
}
return 0;

View File

@ -77,9 +77,10 @@ int mio_makesyshndasync (mio_t* mio, mio_syshnd_t hnd)
#if defined(F_GETFL) && defined(F_SETFL) && defined(O_NONBLOCK)
int flags;
if ((flags = fcntl(hnd, F_GETFL)) <= -1 ||
(flags = fcntl(hnd, F_SETFL, flags | O_NONBLOCK)) <= -1)
if ((flags = fcntl(hnd, F_GETFL, 0)) <= -1 ||
fcntl(hnd, F_SETFL, flags | O_NONBLOCK) <= -1)
{
printf ("make sysnhd async error (%d)\n", hnd);
mio_seterrwithsyserr (mio, 0, errno);
return -1;
}
@ -96,9 +97,10 @@ int mio_makesyshndcloexec (mio_t* mio, mio_syshnd_t hnd)
#if defined(F_GETFL) && defined(F_SETFL) && defined(FD_CLOEXEC)
int flags;
if ((flags = fcntl(hnd, F_GETFD)) <= -1 ||
(flags = fcntl(hnd, F_SETFD, flags | FD_CLOEXEC)) <= -1)
if ((flags = fcntl(hnd, F_GETFD, 0)) <= -1 ||
fcntl(hnd, F_SETFD, flags | FD_CLOEXEC) <= -1)
{
printf ("make sysnhd cloexec error (%d)\n", hnd);
mio_seterrwithsyserr (mio, 0, errno);
return -1;
}