enhanced side-channel write handling

This commit is contained in:
hyung-hwan 2021-08-10 10:32:36 +00:00
parent 0ebd75fda8
commit 0a4ca3cb4e
3 changed files with 19 additions and 7 deletions

View File

@ -387,6 +387,7 @@ static int try_to_accept (hio_dev_sck_t* sck, hio_dev_sck_qxmsg_t* qxmsg, int in
g_htts_no = (g_htts_no + 1) % g_num_thrs; g_htts_no = (g_htts_no + 1) % g_num_thrs;
pthread_mutex_unlock (&g_htts_mutex); pthread_mutex_unlock (&g_htts_mutex);
/* 0: index to the QX socket device (see the the first binding address to hi_svc_htts_start) */
if (hio_svc_htts_writetosidechan(htts, 0, qxmsg, HIO_SIZEOF(*qxmsg)) <= -1) if (hio_svc_htts_writetosidechan(htts, 0, qxmsg, HIO_SIZEOF(*qxmsg)) <= -1)
{ {
hio_bch_t buf[128]; hio_bch_t buf[128];
@ -414,7 +415,7 @@ static int try_to_accept (hio_dev_sck_t* sck, hio_dev_sck_qxmsg_t* qxmsg, int in
else else
{ {
sidechan_write_error: sidechan_write_error:
printf ("sidechannel write error %s\n", strerror(errno)); //printf ("sidechannel write error errno=%d strerror=%s\n", errno, strerror(errno));
hio_skadtobcstr (hio, &qxmsg->remoteaddr, buf, HIO_COUNTOF(buf), HIO_SKAD_TO_BCSTR_ADDR | HIO_SKAD_TO_BCSTR_PORT); hio_skadtobcstr (hio, &qxmsg->remoteaddr, buf, HIO_COUNTOF(buf), HIO_SKAD_TO_BCSTR_ADDR | HIO_SKAD_TO_BCSTR_PORT);
HIO_INFO2 (hio, "unable to handle the accepted connection %ld from %hs\n", (long int)qxmsg->syshnd, buf); HIO_INFO2 (hio, "unable to handle the accepted connection %ld from %hs\n", (long int)qxmsg->syshnd, buf);

View File

@ -26,6 +26,7 @@
#include "http-prv.h" #include "http-prv.h"
#include <hio-path.h> #include <hio-path.h>
#include <errno.h>
#define INVALID_LIDX HIO_TYPE_MAX(hio_oow_t) #define INVALID_LIDX HIO_TYPE_MAX(hio_oow_t)
@ -389,6 +390,7 @@ hio_svc_htts_t* hio_svc_htts_start (hio_t* hio, hio_dev_sck_bind_t* binds, hio_o
default: default:
/* ignore this */ /* ignore this */
HIO_DEBUG3 (hio, "HTTS(%p) - [%zu] unsupported bind address type %d\n", htts, i, (int)hio_skad_family(&binds[i].localaddr));
continue; continue;
} }
info.m.options = HIO_DEV_SCK_MAKE_LENIENT; info.m.options = HIO_DEV_SCK_MAKE_LENIENT;
@ -417,7 +419,7 @@ hio_svc_htts_t* hio_svc_htts_start (hio_t* hio, hio_dev_sck_bind_t* binds, hio_o
{ {
hio_bch_t tmpbuf[HIO_SKAD_IP_STRLEN + 1]; hio_bch_t tmpbuf[HIO_SKAD_IP_STRLEN + 1];
hio_skadtobcstr(hio, &binds[i].localaddr, tmpbuf, HIO_COUNTOF(tmpbuf), HIO_SKAD_TO_BCSTR_ADDR | HIO_SKAD_TO_BCSTR_PORT); hio_skadtobcstr(hio, &binds[i].localaddr, tmpbuf, HIO_COUNTOF(tmpbuf), HIO_SKAD_TO_BCSTR_ADDR | HIO_SKAD_TO_BCSTR_PORT);
HIO_DEBUG3 (hio, "HTTS(%p) - [%zd] unable to bind to %hs\n", htts, i, tmpbuf); HIO_DEBUG3 (hio, "HTTS(%p) - [%zu] unable to bind to %hs\n", htts, i, tmpbuf);
} }
hio_dev_sck_kill (sck); hio_dev_sck_kill (sck);
@ -433,7 +435,7 @@ hio_svc_htts_t* hio_svc_htts_start (hio_t* hio, hio_dev_sck_bind_t* binds, hio_o
{ {
hio_bch_t tmpbuf[HIO_SKAD_IP_STRLEN + 1]; hio_bch_t tmpbuf[HIO_SKAD_IP_STRLEN + 1];
hio_skadtobcstr(hio, &binds[i].localaddr, tmpbuf, HIO_COUNTOF(tmpbuf), HIO_SKAD_TO_BCSTR_ADDR | HIO_SKAD_TO_BCSTR_PORT); hio_skadtobcstr(hio, &binds[i].localaddr, tmpbuf, HIO_COUNTOF(tmpbuf), HIO_SKAD_TO_BCSTR_ADDR | HIO_SKAD_TO_BCSTR_PORT);
HIO_DEBUG3 (hio, "HTTS(%p) - [%zd] unable to bind to %hs\n", htts, i, tmpbuf); HIO_DEBUG3 (hio, "HTTS(%p) - [%zu] unable to bind to %hs\n", htts, i, tmpbuf);
} }
hio_dev_sck_kill (sck); hio_dev_sck_kill (sck);
@ -447,7 +449,7 @@ hio_svc_htts_t* hio_svc_htts_start (hio_t* hio, hio_dev_sck_bind_t* binds, hio_o
hio_bch_t tmpbuf[HIO_SKAD_IP_STRLEN + 1]; hio_bch_t tmpbuf[HIO_SKAD_IP_STRLEN + 1];
hio_dev_sck_getsockaddr(sck, &tmpad); hio_dev_sck_getsockaddr(sck, &tmpad);
hio_skadtobcstr(hio, &tmpad, tmpbuf, HIO_COUNTOF(tmpbuf), HIO_SKAD_TO_BCSTR_ADDR | HIO_SKAD_TO_BCSTR_PORT); hio_skadtobcstr(hio, &tmpad, tmpbuf, HIO_COUNTOF(tmpbuf), HIO_SKAD_TO_BCSTR_ADDR | HIO_SKAD_TO_BCSTR_PORT);
HIO_DEBUG3 (hio, "HTTS(%p) - [%zd] listening on %hs\n", htts, i, tmpbuf); HIO_DEBUG3 (hio, "HTTS(%p) - [%zu] listening on %hs\n", htts, i, tmpbuf);
} }
htts->l.sck[i] = sck; htts->l.sck[i] = sck;
@ -681,13 +683,17 @@ int hio_svc_htts_writetosidechan (hio_svc_htts_t* htts, hio_oow_t idx, const voi
{ {
if (idx >= htts->l.count) if (idx >= htts->l.count)
{ {
hio_seterrbfmt (htts->hio, HIO_EINVAL, "index out of range"); /* don't set the error information - TODO: change hio_seterrbfmt thread-safe?
*hio_seterrbfmt (htts->hio, HIO_EINVAL, "index out of range");*/
errno = EINVAL;
return -1; return -1;
} }
if (!htts->l.sck[idx]) if (!htts->l.sck[idx])
{ {
hio_seterrbfmt (htts->hio, HIO_EINVAL, "no listener at the given index"); /* don't set the error information
*hio_seterrbfmt (htts->hio, HIO_EINVAL, "no listener at the given index"); */
errno = EINVAL;
return -1; return -1;
} }

View File

@ -2532,7 +2532,12 @@ int hio_dev_sck_sendfileok (hio_dev_sck_t* dev)
int hio_dev_sck_writetosidechan (hio_dev_sck_t* dev, const void* dptr, hio_oow_t dlen) int hio_dev_sck_writetosidechan (hio_dev_sck_t* dev, const void* dptr, hio_oow_t dlen)
{ {
if (write(dev->side_chan, dptr, dlen) <= -1) return -1; /* this doesn't set the error information. if you may check errno, though */ if (write(dev->side_chan, dptr, dlen) <= -1)
{
/* this doesn't set the error information on the main socket. if you may check errno, though */
/* TODO: make hio_seterrbfmt() thread safe and set the error information properly. still the caller may be in the thread-unsafe context */
return -1;
}
return 0; return 0;
} }