moved the csck field to the task header
This commit is contained in:
parent
490591ca32
commit
bafad8ceab
@ -304,7 +304,7 @@ static void htts_task_on_kill (hio_svc_htts_task_t* task)
|
||||
hio_t* hio = hio_svc_htts_gethio(htts);
|
||||
|
||||
/* TODO: pretty log message */
|
||||
HIO_INFO3 (hio, "DONE [%hs] [%hs] [%hs] ......................................\n", task->task_req_qmth, task->task_req_qpath, hio_http_status_to_bcstr(task->task_status_code));
|
||||
HIO_INFO3 (hio, "DONE [%hs] [%hs] [%d] ......................................\n", task->task_req_qmth, task->task_req_qpath, (int)task->task_status_code);
|
||||
}
|
||||
|
||||
static int process_http_request (hio_svc_htts_t* htts, hio_dev_sck_t* csck, hio_htre_t* req)
|
||||
|
@ -102,6 +102,7 @@ typedef void (*hio_svc_htts_task_on_kill_t) (
|
||||
hio_bch_t* task_req_qmth; \
|
||||
hio_bch_t* task_req_qpath; \
|
||||
hio_http_status_t task_status_code; \
|
||||
hio_dev_sck_t* task_csck; \
|
||||
hio_svc_htts_cli_t* task_client
|
||||
|
||||
struct hio_svc_htts_task_t
|
||||
@ -481,14 +482,13 @@ HIO_EXPORT hio_svc_htts_task_t* hio_svc_htts_task_make (
|
||||
hio_oow_t task_size,
|
||||
hio_svc_htts_task_on_kill_t on_kill,
|
||||
hio_htre_t* req,
|
||||
hio_svc_htts_cli_t* client
|
||||
hio_dev_sck_t* csck
|
||||
);
|
||||
|
||||
HIO_EXPORT void hio_svc_htts_task_kill (
|
||||
hio_svc_htts_task_t* task
|
||||
);
|
||||
|
||||
|
||||
HIO_EXPORT void hio_svc_htts_fmtgmtime (
|
||||
hio_svc_htts_t* htts,
|
||||
const hio_ntime_t* nt,
|
||||
|
@ -66,8 +66,6 @@ struct cgi_t
|
||||
hio_dev_pro_t* peer;
|
||||
hio_htrd_t* peer_htrd;
|
||||
|
||||
hio_dev_sck_t* csck;
|
||||
|
||||
unsigned int over: 4; /* must be large enough to accomodate CGI_OVER_ALL */
|
||||
unsigned int keep_alive: 1;
|
||||
unsigned int req_content_length_unlimited: 1;
|
||||
@ -93,9 +91,9 @@ typedef struct cgi_peer_xtn_t cgi_peer_xtn_t;
|
||||
|
||||
static void cgi_halt_participating_devices (cgi_t* cgi)
|
||||
{
|
||||
HIO_DEBUG5 (cgi->htts->hio, "HTTS(%p) - cgi(t=%p,c=%p(%d),p=%p) Halting participating devices\n", cgi->htts, cgi, cgi->csck, (cgi->csck? cgi->csck->hnd: -1), cgi->peer);
|
||||
HIO_DEBUG5 (cgi->htts->hio, "HTTS(%p) - cgi(t=%p,c=%p(%d),p=%p) Halting participating devices\n", cgi->htts, cgi, cgi->task_csck, (cgi->task_csck? cgi->task_csck->hnd: -1), cgi->peer);
|
||||
|
||||
if (cgi->csck) hio_dev_sck_halt (cgi->csck);
|
||||
if (cgi->task_csck) hio_dev_sck_halt (cgi->task_csck);
|
||||
|
||||
/* check for peer as it may not have been started */
|
||||
if (cgi->peer) hio_dev_pro_halt (cgi->peer);
|
||||
@ -103,12 +101,12 @@ static void cgi_halt_participating_devices (cgi_t* cgi)
|
||||
|
||||
static int cgi_write_to_client (cgi_t* cgi, const void* data, hio_iolen_t dlen)
|
||||
{
|
||||
if (cgi->csck)
|
||||
if (cgi->task_csck)
|
||||
{
|
||||
cgi->ever_attempted_to_write_to_client = 1;
|
||||
|
||||
cgi->num_pending_writes_to_client++;
|
||||
if (hio_dev_sck_write(cgi->csck, data, dlen, HIO_NULL, HIO_NULL) <= -1)
|
||||
if (hio_dev_sck_write(cgi->task_csck, data, dlen, HIO_NULL, HIO_NULL) <= -1)
|
||||
{
|
||||
cgi->num_pending_writes_to_client--;
|
||||
return -1;
|
||||
@ -125,12 +123,12 @@ static int cgi_write_to_client (cgi_t* cgi, const void* data, hio_iolen_t dlen)
|
||||
|
||||
static int cgi_writev_to_client (cgi_t* cgi, hio_iovec_t* iov, hio_iolen_t iovcnt)
|
||||
{
|
||||
if (cgi->csck)
|
||||
if (cgi->task_csck)
|
||||
{
|
||||
cgi->ever_attempted_to_write_to_client = 1;
|
||||
|
||||
cgi->num_pending_writes_to_client++;
|
||||
if (hio_dev_sck_writev(cgi->csck, iov, iovcnt, HIO_NULL, HIO_NULL) <= -1)
|
||||
if (hio_dev_sck_writev(cgi->task_csck, iov, iovcnt, HIO_NULL, HIO_NULL) <= -1)
|
||||
{
|
||||
cgi->num_pending_writes_to_client--;
|
||||
return -1;
|
||||
@ -206,7 +204,7 @@ static int cgi_write_to_peer (cgi_t* cgi, const void* data, hio_iolen_t dlen)
|
||||
if (cgi->num_pending_writes_to_peer > CGI_PENDING_IO_THRESHOLD)
|
||||
{
|
||||
/* suspend input watching */
|
||||
if (cgi->csck && hio_dev_sck_read(cgi->csck, 0) <= -1) return -1;
|
||||
if (cgi->task_csck && hio_dev_sck_read(cgi->task_csck, 0) <= -1) return -1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
@ -221,14 +219,14 @@ static HIO_INLINE void cgi_mark_over (cgi_t* cgi, int over_bits)
|
||||
old_over = cgi->over;
|
||||
cgi->over |= over_bits;
|
||||
|
||||
HIO_DEBUG8 (hio, "HTTS(%p) - cgi(t=%p,c=%p[%d],p=%p) - old_over=%x | new-bits=%x => over=%x\n", cgi->htts, cgi, cgi->task_client, (cgi->csck? cgi->csck->hnd: -1), cgi->peer, (int)old_over, (int)over_bits, (int)cgi->over);
|
||||
HIO_DEBUG8 (hio, "HTTS(%p) - cgi(t=%p,c=%p[%d],p=%p) - old_over=%x | new-bits=%x => over=%x\n", cgi->htts, cgi, cgi->task_client, (cgi->task_csck? cgi->task_csck->hnd: -1), cgi->peer, (int)old_over, (int)over_bits, (int)cgi->over);
|
||||
|
||||
if (!(old_over & CGI_OVER_READ_FROM_CLIENT) && (cgi->over & CGI_OVER_READ_FROM_CLIENT))
|
||||
{
|
||||
if (cgi->csck && hio_dev_sck_read(cgi->csck, 0) <= -1)
|
||||
if (cgi->task_csck && hio_dev_sck_read(cgi->task_csck, 0) <= -1)
|
||||
{
|
||||
HIO_DEBUG5 (hio, "HTTS(%p) - cgi(t=%p,c=%p[%d],p=%p) - halting client for failure to disable input watching\n", cgi->htts, cgi, cgi->task_client, (cgi->csck? cgi->csck->hnd: -1), cgi->peer);
|
||||
hio_dev_sck_halt (cgi->csck);
|
||||
HIO_DEBUG5 (hio, "HTTS(%p) - cgi(t=%p,c=%p[%d],p=%p) - halting client for failure to disable input watching\n", cgi->htts, cgi, cgi->task_client, (cgi->task_csck? cgi->task_csck->hnd: -1), cgi->peer);
|
||||
hio_dev_sck_halt (cgi->task_csck);
|
||||
}
|
||||
}
|
||||
|
||||
@ -236,7 +234,7 @@ static HIO_INLINE void cgi_mark_over (cgi_t* cgi, int over_bits)
|
||||
{
|
||||
if (cgi->peer && hio_dev_pro_read(cgi->peer, HIO_DEV_PRO_OUT, 0) <= -1)
|
||||
{
|
||||
HIO_DEBUG5 (hio, "HTTS(%p) - cgi(t=%p,c=%p[%d],p=%p) - halting peer for failure to disable input watching\n", cgi->htts, cgi, cgi->task_client, (cgi->csck? cgi->csck->hnd: -1), cgi->peer);
|
||||
HIO_DEBUG5 (hio, "HTTS(%p) - cgi(t=%p,c=%p[%d],p=%p) - halting peer for failure to disable input watching\n", cgi->htts, cgi, cgi->task_client, (cgi->task_csck? cgi->task_csck->hnd: -1), cgi->peer);
|
||||
hio_dev_pro_halt (cgi->peer);
|
||||
}
|
||||
}
|
||||
@ -246,11 +244,11 @@ static HIO_INLINE void cgi_mark_over (cgi_t* cgi, int over_bits)
|
||||
/* ready to stop */
|
||||
if (cgi->peer)
|
||||
{
|
||||
HIO_DEBUG5 (hio, "HTTS(%p) - cgi(t=%p,c=%p[%d],p=%p) - halting unneeded peer\n", cgi->htts, cgi, cgi->task_client, (cgi->csck? cgi->csck->hnd: -1), cgi->peer);
|
||||
HIO_DEBUG5 (hio, "HTTS(%p) - cgi(t=%p,c=%p[%d],p=%p) - halting unneeded peer\n", cgi->htts, cgi, cgi->task_client, (cgi->task_csck? cgi->task_csck->hnd: -1), cgi->peer);
|
||||
hio_dev_pro_halt (cgi->peer);
|
||||
}
|
||||
|
||||
if (cgi->csck)
|
||||
if (cgi->task_csck)
|
||||
{
|
||||
HIO_ASSERT (hio, cgi->task_client != HIO_NULL);
|
||||
|
||||
@ -264,9 +262,9 @@ static HIO_INLINE void cgi_mark_over (cgi_t* cgi, int over_bits)
|
||||
}
|
||||
else
|
||||
{
|
||||
HIO_DEBUG5 (hio, "HTTS(%p) - cgi(t=%p,c=%p[%d],p=%p) - halting peer for no keep-alive\n", cgi->htts, cgi, cgi->task_client, (cgi->csck? cgi->csck->hnd: -1), cgi->peer);
|
||||
hio_dev_sck_shutdown (cgi->csck, HIO_DEV_SCK_SHUTDOWN_WRITE);
|
||||
hio_dev_sck_halt (cgi->csck);
|
||||
HIO_DEBUG5 (hio, "HTTS(%p) - cgi(t=%p,c=%p[%d],p=%p) - halting peer for no keep-alive\n", cgi->htts, cgi, cgi->task_client, (cgi->task_csck? cgi->task_csck->hnd: -1), cgi->peer);
|
||||
hio_dev_sck_shutdown (cgi->task_csck, HIO_DEV_SCK_SHUTDOWN_WRITE);
|
||||
hio_dev_sck_halt (cgi->task_csck);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -277,7 +275,7 @@ static void cgi_on_kill (hio_svc_htts_task_t* task)
|
||||
cgi_t* cgi = (cgi_t*)task;
|
||||
hio_t* hio = cgi->htts->hio;
|
||||
|
||||
HIO_DEBUG5 (hio, "HTTS(%p) - cgi(t=%p,c=%p[%d],p=%p) - killing the task\n", cgi->htts, cgi, cgi->task_client, (cgi->csck? cgi->csck->hnd: -1), cgi->peer);
|
||||
HIO_DEBUG5 (hio, "HTTS(%p) - cgi(t=%p,c=%p[%d],p=%p) - killing the task\n", cgi->htts, cgi, cgi->task_client, (cgi->task_csck? cgi->task_csck->hnd: -1), cgi->peer);
|
||||
|
||||
if (cgi->on_kill) cgi->on_kill (task);
|
||||
|
||||
@ -299,21 +297,21 @@ static void cgi_on_kill (hio_svc_htts_task_t* task)
|
||||
cgi->peer_htrd = HIO_NULL;
|
||||
}
|
||||
|
||||
if (cgi->csck)
|
||||
if (cgi->task_csck)
|
||||
{
|
||||
HIO_ASSERT (hio, cgi->task_client != HIO_NULL);
|
||||
|
||||
if (cgi->client_org_on_read) cgi->csck->on_read = cgi->client_org_on_read;
|
||||
if (cgi->client_org_on_write) cgi->csck->on_write = cgi->client_org_on_write;
|
||||
if (cgi->client_org_on_disconnect) cgi->csck->on_disconnect = cgi->client_org_on_disconnect;
|
||||
if (cgi->client_org_on_read) cgi->task_csck->on_read = cgi->client_org_on_read;
|
||||
if (cgi->client_org_on_write) cgi->task_csck->on_write = cgi->client_org_on_write;
|
||||
if (cgi->client_org_on_disconnect) cgi->task_csck->on_disconnect = cgi->client_org_on_disconnect;
|
||||
if (cgi->client_htrd_recbs_changed) hio_htrd_setrecbs (cgi->task_client->htrd, &cgi->client_htrd_org_recbs);
|
||||
|
||||
if (!cgi->client_disconnected)
|
||||
{
|
||||
if (!cgi->keep_alive || hio_dev_sck_read(cgi->csck, 1) <= -1)
|
||||
if (!cgi->keep_alive || hio_dev_sck_read(cgi->task_csck, 1) <= -1)
|
||||
{
|
||||
HIO_DEBUG5 (hio, "HTTS(%p) - cgi(t=%p,c=%p[%d],p=%p) - halting client for failure to enable input watching\n", cgi->htts, cgi, cgi->task_client, (cgi->csck? cgi->csck->hnd: -1), cgi->peer);
|
||||
hio_dev_sck_halt (cgi->csck);
|
||||
HIO_DEBUG5 (hio, "HTTS(%p) - cgi(t=%p,c=%p[%d],p=%p) - halting client for failure to enable input watching\n", cgi->htts, cgi, cgi->task_client, (cgi->task_csck? cgi->task_csck->hnd: -1), cgi->peer);
|
||||
hio_dev_sck_halt (cgi->task_csck);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -324,7 +322,7 @@ static void cgi_on_kill (hio_svc_htts_task_t* task)
|
||||
cgi->client_htrd_recbs_changed = 0;
|
||||
|
||||
if (cgi->task_next) HIO_SVC_HTTS_TASKL_UNLINK_TASK (cgi); /* detach from the htts service only if it's attached */
|
||||
HIO_DEBUG5 (hio, "HTTS(%p) - cgi(t=%p,c=%p[%d],p=%p) - killed the task\n", cgi->htts, cgi, cgi->task_client, (cgi->csck? cgi->csck->hnd: -1), cgi->peer);
|
||||
HIO_DEBUG5 (hio, "HTTS(%p) - cgi(t=%p,c=%p[%d],p=%p) - killed the task\n", cgi->htts, cgi, cgi->task_client, (cgi->task_csck? cgi->task_csck->hnd: -1), cgi->peer);
|
||||
}
|
||||
|
||||
static void cgi_peer_on_close (hio_dev_pro_t* pro, hio_dev_pro_sid_t sid)
|
||||
@ -480,7 +478,7 @@ static int cgi_peer_on_write (hio_dev_pro_t* pro, hio_iolen_t wrlen, void* wrctx
|
||||
if (cgi->num_pending_writes_to_peer == CGI_PENDING_IO_THRESHOLD)
|
||||
{
|
||||
if (!(cgi->over & CGI_OVER_READ_FROM_CLIENT) &&
|
||||
hio_dev_sck_read(cgi->csck, 1) <= -1) goto oops;
|
||||
hio_dev_sck_read(cgi->task_csck, 1) <= -1) goto oops;
|
||||
}
|
||||
|
||||
if ((cgi->over & CGI_OVER_READ_FROM_CLIENT) && cgi->num_pending_writes_to_peer <= 0)
|
||||
@ -568,6 +566,7 @@ static int peer_htrd_peek (hio_htrd_t* htrd, hio_htre_t* req)
|
||||
|
||||
if (hio_becs_cat(cli->sbuf, "\r\n") == (hio_oow_t)-1) return -1;
|
||||
|
||||
cgi->task_status_code = status_code;
|
||||
return cgi_write_to_client(cgi, HIO_BECS_PTR(cli->sbuf), HIO_BECS_LEN(cli->sbuf));
|
||||
}
|
||||
|
||||
@ -679,11 +678,11 @@ static void cgi_client_on_disconnect (hio_dev_sck_t* sck)
|
||||
cgi_t* cgi = (cgi_t*)cli->task;
|
||||
hio_t* hio = sck->hio;
|
||||
|
||||
HIO_ASSERT (hio, sck == cgi->csck);
|
||||
HIO_ASSERT (hio, sck == cgi->task_csck);
|
||||
HIO_DEBUG4 (hio, "HTTS(%p) - cgi(t=%p,c=%p,csck=%p) - client socket disconnect notified\n", htts, cgi, cli, sck);
|
||||
|
||||
cgi->client_disconnected = 1;
|
||||
cgi->csck = HIO_NULL;
|
||||
cgi->task_csck = HIO_NULL;
|
||||
cgi->task_client = HIO_NULL;
|
||||
if (cgi->client_org_on_disconnect)
|
||||
{
|
||||
@ -965,7 +964,6 @@ int hio_svc_htts_docgi (hio_svc_htts_t* htts, hio_dev_sck_t* csck, hio_htre_t* r
|
||||
HIO_ASSERT (hio, hio_htre_getcontentlen(req) == 0);
|
||||
HIO_ASSERT (hio, cli->sck == csck);
|
||||
|
||||
|
||||
HIO_MEMSET (&fc, 0, HIO_SIZEOF(fc));
|
||||
fc.cli = cli;
|
||||
fc.req = req;
|
||||
@ -983,7 +981,7 @@ int hio_svc_htts_docgi (hio_svc_htts_t* htts, hio_dev_sck_t* csck, hio_htre_t* r
|
||||
mi.on_fork = cgi_peer_on_fork;
|
||||
mi.fork_ctx = &fc;
|
||||
|
||||
cgi = (cgi_t*)hio_svc_htts_task_make(htts, HIO_SIZEOF(*cgi), cgi_on_kill, req, cli);
|
||||
cgi = (cgi_t*)hio_svc_htts_task_make(htts, HIO_SIZEOF(*cgi), cgi_on_kill, req, csck);
|
||||
if (HIO_UNLIKELY(!cgi)) goto oops;
|
||||
|
||||
cgi->on_kill = on_kill;
|
||||
@ -992,8 +990,6 @@ int hio_svc_htts_docgi (hio_svc_htts_t* htts, hio_dev_sck_t* csck, hio_htre_t* r
|
||||
cgi->num_pending_writes_to_peer = 0;*/
|
||||
cgi->req_content_length_unlimited = hio_htre_getreqcontentlen(req, &cgi->req_content_length);
|
||||
|
||||
cgi->csck = csck;
|
||||
cgi->task_client = cli;
|
||||
/* remember the client socket's io event handlers */
|
||||
cgi->client_org_on_read = csck->on_read;
|
||||
cgi->client_org_on_write = csck->on_write;
|
||||
|
@ -34,8 +34,6 @@ struct fcgi_t
|
||||
hio_svc_fcgic_sess_t* peer;
|
||||
hio_htrd_t* peer_htrd;
|
||||
|
||||
hio_dev_sck_t* csck;
|
||||
|
||||
unsigned int over: 4; /* must be large enough to accomodate FCGI_OVER_ALL */
|
||||
unsigned int keep_alive: 1;
|
||||
unsigned int req_content_length_unlimited: 1;
|
||||
@ -66,21 +64,21 @@ static void unbind_task_from_peer (fcgi_t* fcgi, int rcdown);
|
||||
static void fcgi_halt_participating_devices (fcgi_t* fcgi)
|
||||
{
|
||||
/* TODO: include fcgi session id in the output in place of peer??? */
|
||||
HIO_DEBUG5 (fcgi->htts->hio, "HTTS(%p) - fcgi(t=%p,c=%p(%d),p=%p) Halting participating devices\n", fcgi->htts, fcgi, fcgi->csck, (fcgi->csck? fcgi->csck->hnd: -1), fcgi->peer);
|
||||
HIO_DEBUG5 (fcgi->htts->hio, "HTTS(%p) - fcgi(t=%p,c=%p(%d),p=%p) Halting participating devices\n", fcgi->htts, fcgi, fcgi->task_csck, (fcgi->task_csck? fcgi->task_csck->hnd: -1), fcgi->peer);
|
||||
|
||||
if (fcgi->csck) hio_dev_sck_halt (fcgi->csck);
|
||||
if (fcgi->task_csck) hio_dev_sck_halt (fcgi->task_csck);
|
||||
unbind_task_from_peer (fcgi, 1);
|
||||
}
|
||||
|
||||
static int fcgi_write_to_client (fcgi_t* fcgi, const void* data, hio_iolen_t dlen)
|
||||
{
|
||||
if (fcgi->csck)
|
||||
if (fcgi->task_csck)
|
||||
{
|
||||
fcgi->ever_attempted_to_write_to_client = 1;
|
||||
|
||||
HIO_DEBUG2 (fcgi->htts->hio, "WR TO C[%.*hs]\n", dlen, data);
|
||||
fcgi->num_pending_writes_to_client++;
|
||||
if (hio_dev_sck_write(fcgi->csck, data, dlen, HIO_NULL, HIO_NULL) <= -1)
|
||||
if (hio_dev_sck_write(fcgi->task_csck, data, dlen, HIO_NULL, HIO_NULL) <= -1)
|
||||
{
|
||||
fcgi->num_pending_writes_to_client--;
|
||||
return -1;
|
||||
@ -103,12 +101,12 @@ HIO_DEBUG2 (fcgi->htts->hio, "WR TO C[%.*hs]\n", dlen, data);
|
||||
|
||||
static int fcgi_writev_to_client (fcgi_t* fcgi, hio_iovec_t* iov, hio_iolen_t iovcnt)
|
||||
{
|
||||
if (fcgi->csck)
|
||||
if (fcgi->task_csck)
|
||||
{
|
||||
fcgi->ever_attempted_to_write_to_client = 1;
|
||||
|
||||
fcgi->num_pending_writes_to_client++;
|
||||
if (hio_dev_sck_writev(fcgi->csck, iov, iovcnt, HIO_NULL, HIO_NULL) <= -1)
|
||||
if (hio_dev_sck_writev(fcgi->task_csck, iov, iovcnt, HIO_NULL, HIO_NULL) <= -1)
|
||||
{
|
||||
fcgi->num_pending_writes_to_client--;
|
||||
return -1;
|
||||
@ -199,7 +197,7 @@ static int fcgi_write_stdin_to_peer (fcgi_t* fcgi, const void* data, hio_iolen_t
|
||||
if (fcgi->num_pending_writes_to_peer > FCGI_PENDING_IO_THRESHOLD_TO_PEER)
|
||||
{
|
||||
/* disable input watching */
|
||||
if (hio_dev_sck_read(fcgi->csck, 0) <= -1) return -1;
|
||||
if (hio_dev_sck_read(fcgi->task_csck, 0) <= -1) return -1;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@ -215,15 +213,15 @@ static HIO_INLINE void fcgi_mark_over (fcgi_t* fcgi, int over_bits)
|
||||
old_over = fcgi->over;
|
||||
fcgi->over |= over_bits;
|
||||
|
||||
HIO_DEBUG8 (hio, "HTTS(%p) - fcgi(t=%p,c=%p[%d],p=%p) - old_over=%x | new-bits=%x => over=%x\n", fcgi->htts, fcgi, fcgi->task_client, (fcgi->csck? fcgi->csck->hnd: -1), fcgi->peer, (int)old_over, (int)over_bits, (int)fcgi->over);
|
||||
HIO_DEBUG8 (hio, "HTTS(%p) - fcgi(t=%p,c=%p[%d],p=%p) - old_over=%x | new-bits=%x => over=%x\n", fcgi->htts, fcgi, fcgi->task_client, (fcgi->task_csck? fcgi->task_csck->hnd: -1), fcgi->peer, (int)old_over, (int)over_bits, (int)fcgi->over);
|
||||
|
||||
if (!(old_over & FCGI_OVER_READ_FROM_CLIENT) && (fcgi->over & FCGI_OVER_READ_FROM_CLIENT))
|
||||
{
|
||||
/* finished reading from the client. stop watching read */
|
||||
if (fcgi->csck && hio_dev_sck_read(fcgi->csck, 0) <= -1)
|
||||
if (fcgi->task_csck && hio_dev_sck_read(fcgi->task_csck, 0) <= -1)
|
||||
{
|
||||
HIO_DEBUG2 (fcgi->htts->hio, "HTTS(%p) - halting client(%p) for failure to disable input watching\n", fcgi->htts, fcgi->csck);
|
||||
hio_dev_sck_halt (fcgi->csck);
|
||||
HIO_DEBUG2 (fcgi->htts->hio, "HTTS(%p) - halting client(%p) for failure to disable input watching\n", fcgi->htts, fcgi->task_csck);
|
||||
hio_dev_sck_halt (fcgi->task_csck);
|
||||
}
|
||||
}
|
||||
|
||||
@ -245,21 +243,21 @@ static HIO_INLINE void fcgi_mark_over (fcgi_t* fcgi, int over_bits)
|
||||
HIO_SVC_HTTS_TASK_RCDOWN((hio_svc_htts_task_t*)fcgi); /* ref down from fcgi->peer->ctx. unable to use UNREF() */
|
||||
}
|
||||
|
||||
if (fcgi->csck)
|
||||
if (fcgi->task_csck)
|
||||
{
|
||||
HIO_DEBUG2 (hio, "HTTS(%p) - ALL OVER keeping client(%p) alive\n", fcgi->htts, fcgi->csck);
|
||||
HIO_DEBUG2 (hio, "HTTS(%p) - ALL OVER keeping client(%p) alive\n", fcgi->htts, fcgi->task_csck);
|
||||
if (fcgi->keep_alive && !fcgi->client_eof_detected)
|
||||
{
|
||||
HIO_DEBUG2 (hio, "HTTS(%p) - keeping client(%p) alive\n", fcgi->htts, fcgi->csck);
|
||||
HIO_DEBUG2 (hio, "HTTS(%p) - keeping client(%p) alive\n", fcgi->htts, fcgi->task_csck);
|
||||
HIO_ASSERT (fcgi->htts->hio, fcgi->task_client->task == (hio_svc_htts_task_t*)fcgi);
|
||||
unbind_task_from_client (fcgi, 1);
|
||||
/* fcgi must not be accessed from here down as it could have been destroyed in unbind_task_from_client() */
|
||||
}
|
||||
else
|
||||
{
|
||||
HIO_DEBUG2 (hio, "HTTS(%p) - halting client(%p) for no keep-alive\n", fcgi->htts, fcgi->csck);
|
||||
hio_dev_sck_shutdown (fcgi->csck, HIO_DEV_SCK_SHUTDOWN_WRITE);
|
||||
hio_dev_sck_halt (fcgi->csck);
|
||||
HIO_DEBUG2 (hio, "HTTS(%p) - halting client(%p) for no keep-alive\n", fcgi->htts, fcgi->task_csck);
|
||||
hio_dev_sck_shutdown (fcgi->task_csck, HIO_DEV_SCK_SHUTDOWN_WRITE);
|
||||
hio_dev_sck_halt (fcgi->task_csck);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -270,12 +268,12 @@ static void fcgi_on_kill (hio_svc_htts_task_t* task)
|
||||
fcgi_t* fcgi = (fcgi_t*)task;
|
||||
hio_t* hio = fcgi->htts->hio;
|
||||
|
||||
HIO_DEBUG5 (hio, "HTTS(%p) - fcgi(t=%p,c=%p[%d],p=%p) - killing the task\n", fcgi->htts, fcgi, fcgi->task_client, (fcgi->csck? fcgi->csck->hnd: -1), fcgi->peer);
|
||||
HIO_DEBUG5 (hio, "HTTS(%p) - fcgi(t=%p,c=%p[%d],p=%p) - killing the task\n", fcgi->htts, fcgi, fcgi->task_client, (fcgi->task_csck? fcgi->task_csck->hnd: -1), fcgi->peer);
|
||||
|
||||
if (fcgi->on_kill) fcgi->on_kill (task);
|
||||
|
||||
/* [NOTE]
|
||||
* 1. if hio_svc_htts_task_kill() is called, fcgi->peer, fcgi->peer_htrd, fcgi->csck,
|
||||
* 1. if hio_svc_htts_task_kill() is called, fcgi->peer, fcgi->peer_htrd, fcgi->task_csck,
|
||||
* fcgi->task_client may not not null.
|
||||
* 2. this callback function doesn't decrement the reference count on fcgi because
|
||||
* this is the fcgi destruction call-back.
|
||||
@ -292,7 +290,7 @@ static void fcgi_on_kill (hio_svc_htts_task_t* task)
|
||||
fcgi->peer_htrd = HIO_NULL;
|
||||
}
|
||||
|
||||
if (fcgi->csck)
|
||||
if (fcgi->task_csck)
|
||||
{
|
||||
HIO_ASSERT (hio, fcgi->task_client != HIO_NULL);
|
||||
unbind_task_from_client (fcgi, 0);
|
||||
@ -301,7 +299,7 @@ static void fcgi_on_kill (hio_svc_htts_task_t* task)
|
||||
/* detach from the htts service only if it's attached */
|
||||
if (fcgi->task_next) HIO_SVC_HTTS_TASKL_UNLINK_TASK (fcgi);
|
||||
|
||||
HIO_DEBUG5 (hio, "HTTS(%p) - fcgi(t=%p,c=%p[%d],p=%p) - killed the task\n", fcgi->htts, fcgi, fcgi->task_client, (fcgi->csck? fcgi->csck->hnd: -1), fcgi->peer);
|
||||
HIO_DEBUG5 (hio, "HTTS(%p) - fcgi(t=%p,c=%p[%d],p=%p) - killed the task\n", fcgi->htts, fcgi, fcgi->task_client, (fcgi->task_csck? fcgi->task_csck->hnd: -1), fcgi->peer);
|
||||
}
|
||||
|
||||
static void fcgi_peer_on_untie (hio_svc_fcgic_sess_t* peer, void* ctx)
|
||||
@ -313,7 +311,7 @@ static void fcgi_peer_on_untie (hio_svc_fcgic_sess_t* peer, void* ctx)
|
||||
* fcgi_halt_participating_devices() calls hio_svc_fcgi_untie() again
|
||||
* to cause an infinite loop if we don't reset fcgi->peer to HIO_NULL here */
|
||||
|
||||
HIO_DEBUG5 (hio, "HTTS(%p) - fcgi(t=%p,c=%p[%d],p=%p) - peer untied\n", fcgi->htts, fcgi, fcgi->task_client, (fcgi->csck? fcgi->csck->hnd: -1), fcgi->peer);
|
||||
HIO_DEBUG5 (hio, "HTTS(%p) - fcgi(t=%p,c=%p[%d],p=%p) - peer untied\n", fcgi->htts, fcgi, fcgi->task_client, (fcgi->task_csck? fcgi->task_csck->hnd: -1), fcgi->peer);
|
||||
|
||||
fcgi->peer = HIO_NULL;
|
||||
fcgi_write_last_chunk_to_client (fcgi);
|
||||
@ -471,6 +469,7 @@ static int peer_htrd_peek (hio_htrd_t* htrd, hio_htre_t* req)
|
||||
|
||||
if (hio_becs_cat(cli->sbuf, "\r\n") == (hio_oow_t)-1) return -1;
|
||||
|
||||
fcgi->task_status_code = status_code;
|
||||
return fcgi_write_to_client(fcgi, HIO_BECS_PTR(cli->sbuf), HIO_BECS_LEN(cli->sbuf));
|
||||
}
|
||||
|
||||
@ -592,7 +591,7 @@ static void fcgi_client_on_disconnect (hio_dev_sck_t* sck)
|
||||
* the previously associated one is already gone */
|
||||
if (fcgi)
|
||||
{
|
||||
HIO_ASSERT (hio, sck == fcgi->csck);
|
||||
HIO_ASSERT (hio, sck == fcgi->task_csck);
|
||||
|
||||
/* set fcgi->client_disconnect to 1 before unbind_task_from_client()
|
||||
* because fcgi can be destroyed if its reference count hits 0 */
|
||||
@ -763,7 +762,6 @@ static int peer_capture_request_header (hio_htre_t* req, const hio_bch_t* key, c
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int write_params (fcgi_t* fcgi, hio_dev_sck_t* csck, hio_htre_t* req, const hio_bch_t* docroot, const hio_bch_t* script)
|
||||
{
|
||||
hio_t* hio = fcgi->htts->hio;
|
||||
@ -774,7 +772,7 @@ static int write_params (fcgi_t* fcgi, hio_dev_sck_t* csck, hio_htre_t* req, con
|
||||
hio_bch_t* actual_script = HIO_NULL;
|
||||
hio_becs_t dbuf;
|
||||
|
||||
HIO_ASSERT (hio, fcgi->csck == csck);
|
||||
HIO_ASSERT (hio, fcgi->task_csck == csck);
|
||||
|
||||
actual_script = hio_svc_htts_dupmergepaths(fcgi->htts, docroot, script);
|
||||
if (!actual_script) goto oops;
|
||||
@ -838,8 +836,7 @@ static void bind_task_to_client (fcgi_t* fcgi, hio_dev_sck_t* csck)
|
||||
HIO_ASSERT (fcgi->htts->hio, cli->sck == csck);
|
||||
HIO_ASSERT (fcgi->htts->hio, cli->task == HIO_NULL);
|
||||
|
||||
fcgi->csck = csck;
|
||||
fcgi->task_client = cli;
|
||||
/* fcgi->task_client and fcgi->task_csck are set in hio_svc_htts_task_make() */
|
||||
|
||||
/* remember the client socket's io event handlers */
|
||||
fcgi->client_org_on_read = csck->on_read;
|
||||
@ -857,10 +854,10 @@ static void bind_task_to_client (fcgi_t* fcgi, hio_dev_sck_t* csck)
|
||||
|
||||
static void unbind_task_from_client (fcgi_t* fcgi, int rcdown)
|
||||
{
|
||||
hio_dev_sck_t* csck = fcgi->csck;
|
||||
hio_dev_sck_t* csck = fcgi->task_csck;
|
||||
|
||||
HIO_ASSERT (fcgi->htts->hio, fcgi->task_client != HIO_NULL);
|
||||
HIO_ASSERT (fcgi->htts->hio, fcgi->csck != HIO_NULL);
|
||||
HIO_ASSERT (fcgi->htts->hio, fcgi->task_csck != HIO_NULL);
|
||||
HIO_ASSERT (fcgi->htts->hio, fcgi->task_client->task == (hio_svc_htts_task_t*)fcgi);
|
||||
HIO_ASSERT (fcgi->htts->hio, fcgi->task_client->htrd != HIO_NULL);
|
||||
|
||||
@ -895,7 +892,7 @@ HIO_DEBUG2 (csck->hio, "UNBINDING CLEINT FROM TASK... client=%p csck=%p\n", fcgi
|
||||
* to null and call RCDOWN() later */
|
||||
fcgi->task_client->task = HIO_NULL;
|
||||
fcgi->task_client = HIO_NULL;
|
||||
fcgi->csck = HIO_NULL;
|
||||
fcgi->task_csck = HIO_NULL;
|
||||
|
||||
if (!fcgi->client_disconnected && (!fcgi->keep_alive || hio_dev_sck_read(csck, 1) <= -1))
|
||||
{
|
||||
@ -1080,7 +1077,7 @@ int hio_svc_htts_dofcgi (hio_svc_htts_t* htts, hio_dev_sck_t* csck, hio_htre_t*
|
||||
goto oops;
|
||||
}
|
||||
|
||||
fcgi = (fcgi_t*)hio_svc_htts_task_make(htts, HIO_SIZEOF(*fcgi), fcgi_on_kill, req, cli);
|
||||
fcgi = (fcgi_t*)hio_svc_htts_task_make(htts, HIO_SIZEOF(*fcgi), fcgi_on_kill, req, csck);
|
||||
if (HIO_UNLIKELY(!fcgi)) goto oops;
|
||||
|
||||
fcgi->on_kill = on_kill;
|
||||
|
@ -69,8 +69,6 @@ struct file_t
|
||||
hio_tmridx_t peer_tmridx;
|
||||
hio_bch_t peer_etag[128];
|
||||
|
||||
hio_dev_sck_t* csck;
|
||||
|
||||
unsigned int over: 4; /* must be large enough to accomodate FILE_OVER_ALL */
|
||||
unsigned int keep_alive: 1;
|
||||
unsigned int req_content_length_unlimited: 1;
|
||||
@ -93,21 +91,21 @@ static int file_send_contents_to_client (file_t* file);
|
||||
|
||||
static void file_halt_participating_devices (file_t* file)
|
||||
{
|
||||
HIO_DEBUG3 (file->htts->hio, "HTTS(%p) - file(c=%d,p=%d) Halting participating devices\n", file->htts, (int)file->csck->hnd, (int)file->peer);
|
||||
HIO_DEBUG3 (file->htts->hio, "HTTS(%p) - file(c=%d,p=%d) Halting participating devices\n", file->htts, (int)file->task_csck->hnd, (int)file->peer);
|
||||
|
||||
/* only the client socket device.
|
||||
* the peer side is just a file descriptor - no hio-managed device */
|
||||
if (file->csck) hio_dev_sck_halt (file->csck);
|
||||
if (file->task_csck) hio_dev_sck_halt (file->task_csck);
|
||||
}
|
||||
|
||||
static int file_write_to_client (file_t* file, const void* data, hio_iolen_t dlen)
|
||||
{
|
||||
if (file->csck)
|
||||
if (file->task_csck)
|
||||
{
|
||||
file->ever_attempted_to_write_to_client = 1;
|
||||
|
||||
file->num_pending_writes_to_client++;
|
||||
if (hio_dev_sck_write(file->csck, data, dlen, HIO_NULL, HIO_NULL) <= -1) /* TODO: use sendfile here.. */
|
||||
if (hio_dev_sck_write(file->task_csck, data, dlen, HIO_NULL, HIO_NULL) <= -1) /* TODO: use sendfile here.. */
|
||||
{
|
||||
file->num_pending_writes_to_client--;
|
||||
return -1;
|
||||
@ -119,12 +117,12 @@ static int file_write_to_client (file_t* file, const void* data, hio_iolen_t dle
|
||||
|
||||
static int file_sendfile_to_client (file_t* file, hio_foff_t foff, hio_iolen_t len)
|
||||
{
|
||||
if (file->csck)
|
||||
if (file->task_csck)
|
||||
{
|
||||
file->ever_attempted_to_write_to_client = 1;
|
||||
|
||||
file->num_pending_writes_to_client++;
|
||||
if (hio_dev_sck_sendfile(file->csck, file->peer, foff, len, HIO_NULL) <= -1)
|
||||
if (hio_dev_sck_sendfile(file->task_csck, file->peer, foff, len, HIO_NULL) <= -1)
|
||||
{
|
||||
file->num_pending_writes_to_client--;
|
||||
return -1;
|
||||
@ -200,14 +198,14 @@ static void file_mark_over (file_t* file, int over_bits)
|
||||
old_over = file->over;
|
||||
file->over |= over_bits;
|
||||
|
||||
HIO_DEBUG6 (file->htts->hio, "HTTS(%p) - file(c=%d,p=%d) updating mark - old_over=%x | new-bits=%x => over=%x\n", file->htts, (int)file->csck->hnd, file->peer, (int)old_over, (int)over_bits, (int)file->over);
|
||||
HIO_DEBUG6 (file->htts->hio, "HTTS(%p) - file(c=%d,p=%d) updating mark - old_over=%x | new-bits=%x => over=%x\n", file->htts, (int)file->task_csck->hnd, file->peer, (int)old_over, (int)over_bits, (int)file->over);
|
||||
|
||||
if (!(old_over & FILE_OVER_READ_FROM_CLIENT) && (file->over & FILE_OVER_READ_FROM_CLIENT))
|
||||
{
|
||||
if (file->csck && hio_dev_sck_read(file->csck, 0) <= -1)
|
||||
if (file->task_csck && hio_dev_sck_read(file->task_csck, 0) <= -1)
|
||||
{
|
||||
HIO_DEBUG3 (file->htts->hio, "HTTS(%p) - file(c=%d,p=%d) halting client for failure to disable input watching\n", file->htts, (int)file->csck->hnd, file->peer);
|
||||
hio_dev_sck_halt (file->csck);
|
||||
HIO_DEBUG3 (file->htts->hio, "HTTS(%p) - file(c=%d,p=%d) halting client for failure to disable input watching\n", file->htts, (int)file->task_csck->hnd, file->peer);
|
||||
hio_dev_sck_halt (file->task_csck);
|
||||
}
|
||||
}
|
||||
|
||||
@ -221,19 +219,19 @@ static void file_mark_over (file_t* file, int over_bits)
|
||||
if (old_over != FILE_OVER_ALL && file->over == FILE_OVER_ALL)
|
||||
{
|
||||
/* ready to stop */
|
||||
HIO_DEBUG3 (file->htts->hio, "HTTS(%p) - file(c=%d,p=%d) halting peer as it is unneeded\n", file->htts, (int)file->csck->hnd, file->peer);
|
||||
HIO_DEBUG3 (file->htts->hio, "HTTS(%p) - file(c=%d,p=%d) halting peer as it is unneeded\n", file->htts, (int)file->task_csck->hnd, file->peer);
|
||||
file_close_peer (file);
|
||||
|
||||
if (HIO_LIKELY(file->csck))
|
||||
if (HIO_LIKELY(file->task_csck))
|
||||
{
|
||||
if (file->keep_alive && !file->client_eof_detected)
|
||||
{
|
||||
#if defined(TCP_CORK)
|
||||
int tcp_cork = 0;
|
||||
#if defined(SOL_TCP)
|
||||
hio_dev_sck_setsockopt(file->csck, SOL_TCP, TCP_CORK, &tcp_cork, HIO_SIZEOF(tcp_cork));
|
||||
hio_dev_sck_setsockopt(file->task_csck, SOL_TCP, TCP_CORK, &tcp_cork, HIO_SIZEOF(tcp_cork));
|
||||
#elif defined(IPPROTO_TCP)
|
||||
hio_dev_sck_setsockopt(file->csck, IPPROTO_TCP, TCP_CORK, &tcp_cork, HIO_SIZEOF(tcp_cork));
|
||||
hio_dev_sck_setsockopt(file->task_csck, IPPROTO_TCP, TCP_CORK, &tcp_cork, HIO_SIZEOF(tcp_cork));
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@ -244,9 +242,9 @@ static void file_mark_over (file_t* file, int over_bits)
|
||||
}
|
||||
else
|
||||
{
|
||||
HIO_DEBUG4 (file->htts->hio, "HTTS(%p) - file(c=%d,p=%d) halting client for %hs\n", file->htts, (int)file->csck->hnd, file->peer, (file->client_eof_detected? "EOF detected": "no keep-alive"));
|
||||
hio_dev_sck_shutdown (file->csck, HIO_DEV_SCK_SHUTDOWN_WRITE);
|
||||
hio_dev_sck_halt (file->csck);
|
||||
HIO_DEBUG4 (file->htts->hio, "HTTS(%p) - file(c=%d,p=%d) halting client for %hs\n", file->htts, (int)file->task_csck->hnd, file->peer, (file->client_eof_detected? "EOF detected": "no keep-alive"));
|
||||
hio_dev_sck_shutdown (file->task_csck, HIO_DEV_SCK_SHUTDOWN_WRITE);
|
||||
hio_dev_sck_halt (file->task_csck);
|
||||
/* the file task will be detached from file->task_client->task by the upstream disconnect handler in http_svr.c */
|
||||
}
|
||||
}
|
||||
@ -287,23 +285,23 @@ static void file_on_kill (hio_svc_htts_task_t* task)
|
||||
file_t* file = (file_t*)task;
|
||||
hio_t* hio = file->htts->hio;
|
||||
|
||||
HIO_DEBUG5 (hio, "HTTS(%p) - file(t=%p,c=%p[%d],p=%d) - killing the task\n", file->htts, file, file->task_client, (file->csck? file->csck->hnd: -1), file->peer);
|
||||
HIO_DEBUG5 (hio, "HTTS(%p) - file(t=%p,c=%p[%d],p=%d) - killing the task\n", file->htts, file, file->task_client, (file->task_csck? file->task_csck->hnd: -1), file->peer);
|
||||
|
||||
if (file->on_kill) file->on_kill (task);
|
||||
|
||||
file_close_peer (file);
|
||||
|
||||
if (file->csck)
|
||||
if (file->task_csck)
|
||||
{
|
||||
if (file->client_org_on_read) file->csck->on_read = file->client_org_on_read;
|
||||
if (file->client_org_on_write) file->csck->on_write = file->client_org_on_write;
|
||||
if (file->client_org_on_disconnect) file->csck->on_disconnect = file->client_org_on_disconnect;
|
||||
if (file->client_org_on_read) file->task_csck->on_read = file->client_org_on_read;
|
||||
if (file->client_org_on_write) file->task_csck->on_write = file->client_org_on_write;
|
||||
if (file->client_org_on_disconnect) file->task_csck->on_disconnect = file->client_org_on_disconnect;
|
||||
if (file->client_htrd_recbs_changed) hio_htrd_setrecbs (file->task_client->htrd, &file->client_htrd_org_recbs);
|
||||
|
||||
if (!file->keep_alive || hio_dev_sck_read(file->csck, 1) <= -1)
|
||||
if (!file->keep_alive || hio_dev_sck_read(file->task_csck, 1) <= -1)
|
||||
{
|
||||
HIO_DEBUG5 (hio, "HTTS(%p) - file(t=%p,c=%p[%d],p=%d) - halting client for failure to enable input watching\n", file->htts, file, file->task_client, (file->csck? file->csck->hnd: -1), file->peer);
|
||||
hio_dev_sck_halt (file->csck);
|
||||
HIO_DEBUG5 (hio, "HTTS(%p) - file(t=%p,c=%p[%d],p=%d) - halting client for failure to enable input watching\n", file->htts, file, file->task_client, (file->task_csck? file->task_csck->hnd: -1), file->peer);
|
||||
hio_dev_sck_halt (file->task_csck);
|
||||
}
|
||||
}
|
||||
|
||||
@ -313,7 +311,7 @@ static void file_on_kill (hio_svc_htts_task_t* task)
|
||||
file->client_htrd_recbs_changed = 0;
|
||||
|
||||
if (file->task_next) HIO_SVC_HTTS_TASKL_UNLINK_TASK (file); /* detach from the htts service only if it's attached */
|
||||
HIO_DEBUG5 (hio, "HTTS(%p) - file(t=%p,c=%p[%d],p=%d) - killed the task\n", file->htts, file, file->task_client, (file->csck? file->csck->hnd: -1), file->peer);
|
||||
HIO_DEBUG5 (hio, "HTTS(%p) - file(t=%p,c=%p[%d],p=%d) - killed the task\n", file->htts, file, file->task_client, (file->task_csck? file->task_csck->hnd: -1), file->peer);
|
||||
}
|
||||
|
||||
static void file_client_on_disconnect (hio_dev_sck_t* sck)
|
||||
@ -324,12 +322,12 @@ static void file_client_on_disconnect (hio_dev_sck_t* sck)
|
||||
hio_svc_htts_t* htts = file->htts;
|
||||
|
||||
HIO_ASSERT (hio, sck == cli->sck);
|
||||
HIO_ASSERT (hio, sck == file->csck);
|
||||
HIO_ASSERT (hio, sck == file->task_csck);
|
||||
|
||||
HIO_DEBUG4 (hio, "HTTS(%p) - file(t=%p,c=%p,csck=%p) - client socket disconnect notified\n", htts, file, sck, cli);
|
||||
|
||||
file->client_disconnected = 1;
|
||||
file->csck = HIO_NULL;
|
||||
file->task_csck = HIO_NULL;
|
||||
file->task_client = HIO_NULL;
|
||||
if (file->client_org_on_disconnect)
|
||||
{
|
||||
@ -349,7 +347,7 @@ static int file_client_on_read (hio_dev_sck_t* sck, const void* buf, hio_iolen_t
|
||||
file_t* file = (file_t*)cli->task;
|
||||
|
||||
HIO_ASSERT (hio, sck == cli->sck);
|
||||
HIO_ASSERT (hio, sck == file->csck);
|
||||
HIO_ASSERT (hio, sck == file->task_csck);
|
||||
|
||||
if (len <= -1)
|
||||
{
|
||||
@ -408,7 +406,7 @@ static int file_client_on_write (hio_dev_sck_t* sck, hio_iolen_t wrlen, void* wr
|
||||
file_t* file = (file_t*)cli->task;
|
||||
|
||||
HIO_ASSERT (hio, sck == cli->sck);
|
||||
HIO_ASSERT (hio, sck == file->csck);
|
||||
HIO_ASSERT (hio, sck == file->task_csck);
|
||||
|
||||
if (wrlen <= -1)
|
||||
{
|
||||
@ -528,6 +526,7 @@ static int file_send_header_to_client (file_t* file, int status_code, int force_
|
||||
|
||||
if (hio_becs_fcat(cli->sbuf, "Content-Length: %ju\r\n\r\n", (hio_uintmax_t)content_length) == (hio_oow_t)-1) return -1;
|
||||
|
||||
file->task_status_code = status_code;
|
||||
return file_write_to_client(file, HIO_BECS_PTR(cli->sbuf), HIO_BECS_LEN(cli->sbuf));
|
||||
}
|
||||
|
||||
@ -782,7 +781,7 @@ int hio_svc_htts_dofile (hio_svc_htts_t* htts, hio_dev_sck_t* csck, hio_htre_t*
|
||||
actual_file = hio_svc_htts_dupmergepaths(htts, docroot, filepath);
|
||||
if (HIO_UNLIKELY(!actual_file)) goto oops;
|
||||
|
||||
file = (file_t*)hio_svc_htts_task_make(htts, HIO_SIZEOF(*file), file_on_kill, req, cli);
|
||||
file = (file_t*)hio_svc_htts_task_make(htts, HIO_SIZEOF(*file), file_on_kill, req, csck);
|
||||
if (HIO_UNLIKELY(!file)) goto oops;
|
||||
|
||||
file->on_kill = on_kill;
|
||||
@ -793,8 +792,6 @@ int hio_svc_htts_dofile (hio_svc_htts_t* htts, hio_dev_sck_t* csck, hio_htre_t*
|
||||
file->num_pending_writes_to_peer = 0;*/
|
||||
file->req_content_length_unlimited = hio_htre_getreqcontentlen(req, &file->req_content_length);
|
||||
|
||||
file->csck = csck;
|
||||
file->task_client = cli;
|
||||
file->client_org_on_read = csck->on_read;
|
||||
file->client_org_on_write = csck->on_write;
|
||||
file->client_org_on_disconnect = csck->on_disconnect;
|
||||
@ -913,7 +910,7 @@ int hio_svc_htts_dofile (hio_svc_htts_t* htts, hio_dev_sck_t* csck, hio_htre_t*
|
||||
#if defined(HAVE_POSIX_FADVISE)
|
||||
posix_fadvise (file->peer, file->start_offset, file->end_offset - file->start_offset + 1, POSIX_FADV_SEQUENTIAL);
|
||||
#endif
|
||||
set_tcp_cork (file->csck);
|
||||
set_tcp_cork (file->task_csck);
|
||||
|
||||
if (file_send_header_to_client(file, HIO_HTTP_STATUS_OK, 0, actual_mime_type) <= -1) goto oops;
|
||||
if (file_send_contents_to_client(file) <= -1) goto oops;
|
||||
|
@ -653,7 +653,7 @@ int hio_svc_htts_getsockaddr (hio_svc_htts_t* htts, hio_oow_t idx, hio_skad_t* s
|
||||
*
|
||||
* you can pass sizeof(my_task_t) to hio_svc_htts_task_make()
|
||||
*/
|
||||
hio_svc_htts_task_t* hio_svc_htts_task_make (hio_svc_htts_t* htts, hio_oow_t task_size, hio_svc_htts_task_on_kill_t on_kill, hio_htre_t* req, hio_svc_htts_cli_t* cli)
|
||||
hio_svc_htts_task_t* hio_svc_htts_task_make (hio_svc_htts_t* htts, hio_oow_t task_size, hio_svc_htts_task_on_kill_t on_kill, hio_htre_t* req, hio_dev_sck_t* csck)
|
||||
{
|
||||
hio_t* hio = htts->hio;
|
||||
hio_svc_htts_task_t* task;
|
||||
@ -681,7 +681,8 @@ hio_svc_htts_task_t* hio_svc_htts_task_make (hio_svc_htts_t* htts, hio_oow_t tas
|
||||
task->task_req_qpath_is_root = (hio_htre_getqpathlen(req) == 1 && hio_htre_getqpath(req)[0] == '/');
|
||||
task->task_req_qmth = (hio_bch_t*)((hio_uint8_t*)task + task_size);
|
||||
task->task_req_qpath = task->task_req_qmth + qmth_len + 1;
|
||||
task->task_client = cli;
|
||||
task->task_csck = csck;
|
||||
task->task_client = (hio_svc_htts_cli_t*)hio_dev_sck_getxtn(csck);
|
||||
|
||||
HIO_MEMCPY (task->task_req_qmth, hio_htre_getqmethodname(req),qmth_len + 1);
|
||||
HIO_MEMCPY (task->task_req_qpath, hio_htre_getqpath(req), qpath_len + 1);
|
||||
@ -747,12 +748,12 @@ int hio_svc_https_task_sendfinal (hio_svc_htts_task_t* task, int status_code, co
|
||||
}
|
||||
else
|
||||
{
|
||||
if (hio_becs_fcat(cli->sbuf, "nContent-Length: %zu\r\n\r\n%hs", content_len, content_text) == (hio_oow_t)-1) return -1;
|
||||
if (hio_becs_fcat(cli->sbuf, "Content-Length: %zu\r\n\r\n%hs", content_len, content_text) == (hio_oow_t)-1) return -1;
|
||||
}
|
||||
|
||||
task->task_status_code = status_code;
|
||||
return (task_write_to_client(task, HIO_BECS_PTR(cli->sbuf), HIO_BECS_LEN(cli->sbuf)) <= -1 ||
|
||||
(force_close && task_write_to_client(file, HIO_NULL, 0) <= -1))? -1: 0;
|
||||
(force_close && task_write_to_client(task, HIO_NULL, 0) <= -1))? -1: 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -68,7 +68,6 @@ struct thr_task_t
|
||||
hio_oow_t num_pending_writes_to_peer;
|
||||
hio_dev_thr_t* peer;
|
||||
hio_htrd_t* peer_htrd;
|
||||
hio_dev_sck_t* csck;
|
||||
|
||||
unsigned int over: 4; /* must be large enough to accomodate THR_TASK_OVER_ALL */
|
||||
unsigned int keep_alive: 1;
|
||||
@ -96,21 +95,21 @@ typedef struct thr_peer_xtn_t thr_peer_xtn_t;
|
||||
|
||||
static void thr_task_halt_participating_devices (thr_task_t* thr)
|
||||
{
|
||||
HIO_DEBUG4 (thr->htts->hio, "HTTS(%p) - Halting participating devices in thr task %p(csck=%p,peer=%p)\n", thr->htts, thr, thr->csck, thr->peer);
|
||||
HIO_DEBUG4 (thr->htts->hio, "HTTS(%p) - Halting participating devices in thr task %p(csck=%p,peer=%p)\n", thr->htts, thr, thr->task_csck, thr->peer);
|
||||
|
||||
if (thr->csck) hio_dev_sck_halt (thr->csck);
|
||||
if (thr->task_csck) hio_dev_sck_halt (thr->task_csck);
|
||||
/* check for peer as it may not have been started */
|
||||
if (thr->peer) hio_dev_thr_halt (thr->peer);
|
||||
}
|
||||
|
||||
static int thr_task_write_to_client (thr_task_t* thr, const void* data, hio_iolen_t dlen)
|
||||
{
|
||||
if (thr->csck)
|
||||
if (thr->task_csck)
|
||||
{
|
||||
thr->ever_attempted_to_write_to_client = 1;
|
||||
|
||||
thr->num_pending_writes_to_client++;
|
||||
if (hio_dev_sck_write(thr->csck, data, dlen, HIO_NULL, HIO_NULL) <= -1)
|
||||
if (hio_dev_sck_write(thr->task_csck, data, dlen, HIO_NULL, HIO_NULL) <= -1)
|
||||
{
|
||||
thr->num_pending_writes_to_client--;
|
||||
return -1;
|
||||
@ -126,12 +125,12 @@ static int thr_task_write_to_client (thr_task_t* thr, const void* data, hio_iole
|
||||
|
||||
static int thr_task_writev_to_client (thr_task_t* thr, hio_iovec_t* iov, hio_iolen_t iovcnt)
|
||||
{
|
||||
if (thr->csck)
|
||||
if (thr->task_csck)
|
||||
{
|
||||
thr->ever_attempted_to_write_to_client = 1;
|
||||
|
||||
thr->num_pending_writes_to_client++;
|
||||
if (hio_dev_sck_writev(thr->csck, iov, iovcnt, HIO_NULL, HIO_NULL) <= -1)
|
||||
if (hio_dev_sck_writev(thr->task_csck, iov, iovcnt, HIO_NULL, HIO_NULL) <= -1)
|
||||
{
|
||||
thr->num_pending_writes_to_client--;
|
||||
return -1;
|
||||
@ -206,7 +205,7 @@ static int thr_task_write_to_peer (thr_task_t* thr, const void* data, hio_iolen_
|
||||
/* TODO: check if it's already finished or something.. */
|
||||
if (thr->num_pending_writes_to_peer > THR_TASK_PENDING_IO_THRESHOLD)
|
||||
{
|
||||
if (thr->csck && hio_dev_sck_read(thr->csck, 0) <= -1) return -1;
|
||||
if (thr->task_csck && hio_dev_sck_read(thr->task_csck, 0) <= -1) return -1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
@ -221,14 +220,14 @@ static HIO_INLINE void thr_task_mark_over (thr_task_t* thr, int over_bits)
|
||||
old_over = thr->over;
|
||||
thr->over |= over_bits;
|
||||
|
||||
HIO_DEBUG8 (hio, "HTTS(%p) - thr(t=%p,c=%p[%d],p=%p) - old_over=%x | new-bits=%x => over=%x\n", thr->htts, thr, thr->task_client, (thr->csck? thr->csck->hnd: -1), thr->peer, (int)old_over, (int)over_bits, (int)thr->over);
|
||||
HIO_DEBUG8 (hio, "HTTS(%p) - thr(t=%p,c=%p[%d],p=%p) - old_over=%x | new-bits=%x => over=%x\n", thr->htts, thr, thr->task_client, (thr->task_csck? thr->task_csck->hnd: -1), thr->peer, (int)old_over, (int)over_bits, (int)thr->over);
|
||||
|
||||
if (!(old_over & THR_TASK_OVER_READ_FROM_CLIENT) && (thr->over & THR_TASK_OVER_READ_FROM_CLIENT))
|
||||
{
|
||||
if (thr->csck && hio_dev_sck_read(thr->csck, 0) <= -1)
|
||||
if (thr->task_csck && hio_dev_sck_read(thr->task_csck, 0) <= -1)
|
||||
{
|
||||
HIO_DEBUG5 (hio, "HTTS(%p) - thr(t=%p,c=%p[%d],p=%p) - halting client for failure to disable input watching\n", thr->htts, thr, thr->task_client, (thr->csck? thr->csck->hnd: -1), thr->peer);
|
||||
hio_dev_sck_halt (thr->csck);
|
||||
HIO_DEBUG5 (hio, "HTTS(%p) - thr(t=%p,c=%p[%d],p=%p) - halting client for failure to disable input watching\n", thr->htts, thr, thr->task_client, (thr->task_csck? thr->task_csck->hnd: -1), thr->peer);
|
||||
hio_dev_sck_halt (thr->task_csck);
|
||||
}
|
||||
}
|
||||
|
||||
@ -236,7 +235,7 @@ static HIO_INLINE void thr_task_mark_over (thr_task_t* thr, int over_bits)
|
||||
{
|
||||
if (thr->peer && hio_dev_thr_read(thr->peer, 0) <= -1)
|
||||
{
|
||||
HIO_DEBUG5 (hio, "HTTS(%p) - thr(t=%p,c=%p[%d],p=%p) - halting peer for failure to disable input watching\n", thr->htts, thr, thr->task_client, (thr->csck? thr->csck->hnd: -1), thr->peer);
|
||||
HIO_DEBUG5 (hio, "HTTS(%p) - thr(t=%p,c=%p[%d],p=%p) - halting peer for failure to disable input watching\n", thr->htts, thr, thr->task_client, (thr->task_csck? thr->task_csck->hnd: -1), thr->peer);
|
||||
hio_dev_thr_halt (thr->peer);
|
||||
}
|
||||
}
|
||||
@ -246,11 +245,11 @@ static HIO_INLINE void thr_task_mark_over (thr_task_t* thr, int over_bits)
|
||||
/* ready to stop */
|
||||
if (thr->peer)
|
||||
{
|
||||
HIO_DEBUG5 (hio, "HTTS(%p) - thr(t=%p,c=%p[%d],p=%p) - halting peer as it is unneeded\n", thr->htts, thr, thr->task_client, (thr->csck? thr->csck->hnd: -1), thr->peer);
|
||||
HIO_DEBUG5 (hio, "HTTS(%p) - thr(t=%p,c=%p[%d],p=%p) - halting peer as it is unneeded\n", thr->htts, thr, thr->task_client, (thr->task_csck? thr->task_csck->hnd: -1), thr->peer);
|
||||
hio_dev_thr_halt (thr->peer);
|
||||
}
|
||||
|
||||
if (thr->csck)
|
||||
if (thr->task_csck)
|
||||
{
|
||||
HIO_ASSERT (hio, thr->task_client != HIO_NULL);
|
||||
|
||||
@ -263,9 +262,9 @@ static HIO_INLINE void thr_task_mark_over (thr_task_t* thr, int over_bits)
|
||||
}
|
||||
else
|
||||
{
|
||||
HIO_DEBUG5 (hio, "HTTS(%p) - thr(t=%p,c=%p[%d],p=%p) - halting client for no keep-alive\n", thr->htts, thr, thr->task_client, (thr->csck? thr->csck->hnd: -1), thr->peer);
|
||||
hio_dev_sck_shutdown (thr->csck, HIO_DEV_SCK_SHUTDOWN_WRITE);
|
||||
hio_dev_sck_halt (thr->csck);
|
||||
HIO_DEBUG5 (hio, "HTTS(%p) - thr(t=%p,c=%p[%d],p=%p) - halting client for no keep-alive\n", thr->htts, thr, thr->task_client, (thr->task_csck? thr->task_csck->hnd: -1), thr->peer);
|
||||
hio_dev_sck_shutdown (thr->task_csck, HIO_DEV_SCK_SHUTDOWN_WRITE);
|
||||
hio_dev_sck_halt (thr->task_csck);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -276,7 +275,7 @@ static void thr_task_on_kill (hio_svc_htts_task_t* task)
|
||||
thr_task_t* thr = (thr_task_t*)task;
|
||||
hio_t* hio = thr->htts->hio;
|
||||
|
||||
HIO_DEBUG5 (hio, "HTTS(%p) - thr(t=%p,c=%p[%d],p=%p) - killing the task\n", thr->htts, thr, thr->task_client, (thr->csck? thr->csck->hnd: -1), thr->peer);
|
||||
HIO_DEBUG5 (hio, "HTTS(%p) - thr(t=%p,c=%p[%d],p=%p) - killing the task\n", thr->htts, thr, thr->task_client, (thr->task_csck? thr->task_csck->hnd: -1), thr->peer);
|
||||
|
||||
if (thr->on_kill) thr->on_kill (task);
|
||||
|
||||
@ -304,20 +303,20 @@ static void thr_task_on_kill (hio_svc_htts_task_t* task)
|
||||
thr->peer_htrd = HIO_NULL;
|
||||
}
|
||||
|
||||
if (thr->csck)
|
||||
if (thr->task_csck)
|
||||
{
|
||||
HIO_ASSERT (hio, thr->task_client != HIO_NULL);
|
||||
|
||||
/* restore callbacks */
|
||||
if (thr->client_org_on_read) thr->csck->on_read = thr->client_org_on_read;
|
||||
if (thr->client_org_on_write) thr->csck->on_write = thr->client_org_on_write;
|
||||
if (thr->client_org_on_disconnect) thr->csck->on_disconnect = thr->client_org_on_disconnect;
|
||||
if (thr->client_org_on_read) thr->task_csck->on_read = thr->client_org_on_read;
|
||||
if (thr->client_org_on_write) thr->task_csck->on_write = thr->client_org_on_write;
|
||||
if (thr->client_org_on_disconnect) thr->task_csck->on_disconnect = thr->client_org_on_disconnect;
|
||||
if (thr->client_htrd_recbs_changed) hio_htrd_setrecbs (thr->task_client->htrd, &thr->client_htrd_org_recbs);
|
||||
|
||||
if (!thr->keep_alive || hio_dev_sck_read(thr->csck, 1) <= -1)
|
||||
if (!thr->keep_alive || hio_dev_sck_read(thr->task_csck, 1) <= -1)
|
||||
{
|
||||
HIO_DEBUG5 (hio, "HTTS(%p) - thr(t=%p,c=%p[%d],p=%p) - halting client for failure to enable input watching\n", thr->htts, thr, thr->task_client, (thr->csck? thr->csck->hnd: -1), thr->peer);
|
||||
hio_dev_sck_halt (thr->csck);
|
||||
HIO_DEBUG5 (hio, "HTTS(%p) - thr(t=%p,c=%p[%d],p=%p) - halting client for failure to enable input watching\n", thr->htts, thr, thr->task_client, (thr->task_csck? thr->task_csck->hnd: -1), thr->peer);
|
||||
hio_dev_sck_halt (thr->task_csck);
|
||||
}
|
||||
}
|
||||
|
||||
@ -327,7 +326,7 @@ static void thr_task_on_kill (hio_svc_htts_task_t* task)
|
||||
thr->client_htrd_recbs_changed = 0;
|
||||
|
||||
if (thr->task_next) HIO_SVC_HTTS_TASKL_UNLINK_TASK (thr); /* detach from the htts service only if it's attached */
|
||||
HIO_DEBUG5 (hio, "HTTS(%p) - thr(t=%p,c=%p[%d],p=%p) - killed the task\n", thr->htts, thr, thr->task_client, (thr->csck? thr->csck->hnd: -1), thr->peer);
|
||||
HIO_DEBUG5 (hio, "HTTS(%p) - thr(t=%p,c=%p[%d],p=%p) - killed the task\n", thr->htts, thr, thr->task_client, (thr->task_csck? thr->task_csck->hnd: -1), thr->peer);
|
||||
}
|
||||
|
||||
static void thr_peer_on_close (hio_dev_thr_t* peer, hio_dev_thr_sid_t sid)
|
||||
@ -481,6 +480,7 @@ static int thr_peer_htrd_peek (hio_htrd_t* htrd, hio_htre_t* req)
|
||||
hio_svc_htts_cli_t* cli = thr->task_client;
|
||||
hio_bch_t dtbuf[64];
|
||||
int status_code = HIO_HTTP_STATUS_OK;
|
||||
const hio_bch_t* status_desc = HIO_NULL;
|
||||
|
||||
if (req->attr.content_length)
|
||||
{
|
||||
@ -488,21 +488,13 @@ static int thr_peer_htrd_peek (hio_htrd_t* htrd, hio_htre_t* req)
|
||||
thr->res_mode_to_cli = THR_TASK_RES_MODE_LENGTH;
|
||||
}
|
||||
|
||||
if (req->attr.status)
|
||||
{
|
||||
int is_sober;
|
||||
const hio_bch_t* endptr;
|
||||
hio_intmax_t v;
|
||||
|
||||
v = hio_bchars_to_intmax(req->attr.status, hio_count_bcstr(req->attr.status), HIO_BCHARS_TO_INTMAX_MAKE_OPTION(0,0,0,10), &endptr, &is_sober);
|
||||
if (*endptr == '\0' && is_sober && v > 0 && v <= HIO_TYPE_MAX(int)) status_code = v;
|
||||
}
|
||||
if (req->attr.status) hio_parse_http_status_header_value(req->attr.status, &status_code, &status_desc);
|
||||
|
||||
hio_svc_htts_fmtgmtime (cli->htts, HIO_NULL, dtbuf, HIO_COUNTOF(dtbuf));
|
||||
|
||||
if (hio_becs_fmt(cli->sbuf, "HTTP/%d.%d %d %hs\r\nServer: %hs\r\nDate: %hs\r\n",
|
||||
thr->task_req_version.major, thr->task_req_version.minor,
|
||||
status_code, hio_http_status_to_bcstr(status_code),
|
||||
status_code, (status_desc? status_desc: hio_http_status_to_bcstr(status_code)),
|
||||
cli->htts->server_name, dtbuf) == (hio_oow_t)-1) return -1;
|
||||
|
||||
if (hio_htre_walkheaders(req, thr_peer_capture_response_header, cli) <= -1) return -1;
|
||||
@ -524,6 +516,7 @@ static int thr_peer_htrd_peek (hio_htrd_t* htrd, hio_htre_t* req)
|
||||
|
||||
if (hio_becs_cat(cli->sbuf, "\r\n") == (hio_oow_t)-1) return -1;
|
||||
|
||||
thr->task_status_code = status_code;
|
||||
return thr_task_write_to_client(thr, HIO_BECS_PTR(cli->sbuf), HIO_BECS_LEN(cli->sbuf));
|
||||
}
|
||||
|
||||
@ -663,7 +656,7 @@ static int thr_peer_on_write (hio_dev_thr_t* peer, hio_iolen_t wrlen, void* wrct
|
||||
if (thr->num_pending_writes_to_peer == THR_TASK_PENDING_IO_THRESHOLD)
|
||||
{
|
||||
if (!(thr->over & THR_TASK_OVER_READ_FROM_CLIENT) &&
|
||||
hio_dev_sck_read(thr->csck, 1) <= -1) goto oops;
|
||||
hio_dev_sck_read(thr->task_csck, 1) <= -1) goto oops;
|
||||
}
|
||||
|
||||
if ((thr->over & THR_TASK_OVER_READ_FROM_CLIENT) && thr->num_pending_writes_to_peer <= 0)
|
||||
@ -686,11 +679,11 @@ static void thr_client_on_disconnect (hio_dev_sck_t* sck)
|
||||
hio_svc_htts_t* htts = thr->htts;
|
||||
hio_t* hio = sck->hio;
|
||||
|
||||
HIO_ASSERT (hio, sck = thr->csck);
|
||||
HIO_ASSERT (hio, sck = thr->task_csck);
|
||||
HIO_DEBUG4 (hio, "HTTS(%p) - thr(t=%p,c=%p,csck=%p) - client socket disconnect notified\n", htts, thr, cli, sck);
|
||||
|
||||
thr->client_disconnected = 1;
|
||||
thr->csck = HIO_NULL;
|
||||
thr->task_csck = HIO_NULL;
|
||||
thr->task_client = HIO_NULL;
|
||||
if (thr->client_org_on_disconnect)
|
||||
{
|
||||
@ -919,13 +912,11 @@ int hio_svc_htts_dothr (hio_svc_htts_t* htts, hio_dev_sck_t* csck, hio_htre_t* r
|
||||
mi.on_write = thr_peer_on_write;
|
||||
mi.on_close = thr_peer_on_close;
|
||||
|
||||
thr = (thr_task_t*)hio_svc_htts_task_make(htts, HIO_SIZEOF(*thr), thr_task_on_kill, req, cli);
|
||||
thr = (thr_task_t*)hio_svc_htts_task_make(htts, HIO_SIZEOF(*thr), thr_task_on_kill, req, csck);
|
||||
if (HIO_UNLIKELY(!thr)) goto oops;
|
||||
|
||||
thr->on_kill = on_kill;
|
||||
thr->options = options;
|
||||
thr->csck = csck;
|
||||
thr->task_client = cli; /* for faster access without going through csck. */
|
||||
|
||||
/*thr->num_pending_writes_to_client = 0;
|
||||
thr->num_pending_writes_to_peer = 0;*/
|
||||
|
@ -38,8 +38,6 @@ struct txt_t
|
||||
int options;
|
||||
hio_oow_t num_pending_writes_to_client;
|
||||
|
||||
hio_dev_sck_t* csck;
|
||||
|
||||
unsigned int over: 2; /* must be large enough to accomodate TXT_OVER_ALL */
|
||||
unsigned int keep_alive: 1;
|
||||
unsigned int req_content_length_unlimited: 1;
|
||||
@ -57,16 +55,16 @@ typedef struct txt_t txt_t;
|
||||
|
||||
static void txt_halt_participating_devices (txt_t* txt)
|
||||
{
|
||||
HIO_DEBUG3 (txt->htts->hio, "HTTS(%p) - Halting participating devices in txt state %p(client=%p)\n", txt->htts, txt, txt->csck);
|
||||
if (txt->csck) hio_dev_sck_halt (txt->csck);
|
||||
HIO_DEBUG3 (txt->htts->hio, "HTTS(%p) - Halting participating devices in txt state %p(client=%p)\n", txt->htts, txt, txt->task_csck);
|
||||
if (txt->task_csck) hio_dev_sck_halt (txt->task_csck);
|
||||
}
|
||||
|
||||
static int txt_write_to_client (txt_t* txt, const void* data, hio_iolen_t dlen)
|
||||
{
|
||||
if (txt->csck)
|
||||
if (txt->task_csck)
|
||||
{
|
||||
txt->num_pending_writes_to_client++;
|
||||
if (hio_dev_sck_write(txt->csck, data, dlen, HIO_NULL, HIO_NULL) <= -1)
|
||||
if (hio_dev_sck_write(txt->task_csck, data, dlen, HIO_NULL, HIO_NULL) <= -1)
|
||||
{
|
||||
txt->num_pending_writes_to_client--;
|
||||
return -1;
|
||||
@ -78,10 +76,10 @@ static int txt_write_to_client (txt_t* txt, const void* data, hio_iolen_t dlen)
|
||||
#if 0
|
||||
static int txt_writev_to_client (txt_t* txt, hio_iovec_t* iov, hio_iolen_t iovcnt)
|
||||
{
|
||||
if (txt->csck)
|
||||
if (txt->task_csck)
|
||||
{
|
||||
txt->num_pending_writes_to_client++;
|
||||
if (hio_dev_sck_writev(txt->csck, iov, iovcnt, HIO_NULL, HIO_NULL) <= -1)
|
||||
if (hio_dev_sck_writev(txt->task_csck, iov, iovcnt, HIO_NULL, HIO_NULL) <= -1)
|
||||
{
|
||||
txt->num_pending_writes_to_client--;
|
||||
return -1;
|
||||
@ -134,14 +132,14 @@ static HIO_INLINE void txt_mark_over (txt_t* txt, int over_bits)
|
||||
old_over = txt->over;
|
||||
txt->over |= over_bits;
|
||||
|
||||
HIO_DEBUG4 (txt->htts->hio, "HTTS(%p) - client=%p new-bits=%x over=%x\n", txt->htts, txt->csck, (int)over_bits, (int)txt->over);
|
||||
HIO_DEBUG4 (txt->htts->hio, "HTTS(%p) - client=%p new-bits=%x over=%x\n", txt->htts, txt->task_csck, (int)over_bits, (int)txt->over);
|
||||
|
||||
if (!(old_over & TXT_OVER_READ_FROM_CLIENT) && (txt->over & TXT_OVER_READ_FROM_CLIENT))
|
||||
{
|
||||
if (hio_dev_sck_read(txt->csck, 0) <= -1)
|
||||
if (hio_dev_sck_read(txt->task_csck, 0) <= -1)
|
||||
{
|
||||
HIO_DEBUG2 (txt->htts->hio, "HTTS(%p) - halting client(%p) for failure to disable input watching\n", txt->htts, txt->csck);
|
||||
hio_dev_sck_halt (txt->csck);
|
||||
HIO_DEBUG2 (txt->htts->hio, "HTTS(%p) - halting client(%p) for failure to disable input watching\n", txt->htts, txt->task_csck);
|
||||
hio_dev_sck_halt (txt->task_csck);
|
||||
}
|
||||
}
|
||||
|
||||
@ -159,9 +157,9 @@ static HIO_INLINE void txt_mark_over (txt_t* txt, int over_bits)
|
||||
}
|
||||
else
|
||||
{
|
||||
HIO_DEBUG2 (txt->htts->hio, "HTTS(%p) - halting client(%p) for no keep-alive\n", txt->htts, txt->csck);
|
||||
hio_dev_sck_shutdown (txt->csck, HIO_DEV_SCK_SHUTDOWN_WRITE);
|
||||
hio_dev_sck_halt (txt->csck);
|
||||
HIO_DEBUG2 (txt->htts->hio, "HTTS(%p) - halting client(%p) for no keep-alive\n", txt->htts, txt->task_csck);
|
||||
hio_dev_sck_shutdown (txt->task_csck, HIO_DEV_SCK_SHUTDOWN_WRITE);
|
||||
hio_dev_sck_halt (txt->task_csck);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -171,26 +169,26 @@ static void txt_on_kill (hio_svc_htts_task_t* task)
|
||||
txt_t* txt = (txt_t*)task;
|
||||
hio_t* hio = txt->htts->hio;
|
||||
|
||||
HIO_DEBUG2 (hio, "HTTS(%p) - killing txt client(%p)\n", txt->htts, txt->csck);
|
||||
HIO_DEBUG2 (hio, "HTTS(%p) - killing txt client(%p)\n", txt->htts, txt->task_csck);
|
||||
|
||||
if (txt->on_kill) txt->on_kill (task);
|
||||
|
||||
if (txt->csck)
|
||||
if (txt->task_csck)
|
||||
{
|
||||
HIO_ASSERT (hio, txt->task_client != HIO_NULL);
|
||||
|
||||
if (txt->client_org_on_read) txt->csck->on_read = txt->client_org_on_read;
|
||||
if (txt->client_org_on_write) txt->csck->on_write = txt->client_org_on_write;
|
||||
if (txt->client_org_on_disconnect) txt->csck->on_disconnect = txt->client_org_on_disconnect;
|
||||
if (txt->client_org_on_read) txt->task_csck->on_read = txt->client_org_on_read;
|
||||
if (txt->client_org_on_write) txt->task_csck->on_write = txt->client_org_on_write;
|
||||
if (txt->client_org_on_disconnect) txt->task_csck->on_disconnect = txt->client_org_on_disconnect;
|
||||
if (txt->client_htrd_recbs_changed)
|
||||
hio_htrd_setrecbs (txt->task_client->htrd, &txt->client_htrd_org_recbs);
|
||||
|
||||
if (!txt->client_disconnected)
|
||||
{
|
||||
if (!txt->keep_alive || hio_dev_sck_read(txt->csck, 1) <= -1)
|
||||
if (!txt->keep_alive || hio_dev_sck_read(txt->task_csck, 1) <= -1)
|
||||
{
|
||||
HIO_DEBUG2 (hio, "HTTS(%p) - halting client(%p) for failure to enable input watching\n", txt->htts, txt->csck);
|
||||
hio_dev_sck_halt (txt->csck);
|
||||
HIO_DEBUG2 (hio, "HTTS(%p) - halting client(%p) for failure to enable input watching\n", txt->htts, txt->task_csck);
|
||||
hio_dev_sck_halt (txt->task_csck);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -336,7 +334,7 @@ int hio_svc_htts_dotxt (hio_svc_htts_t* htts, hio_dev_sck_t* csck, hio_htre_t* r
|
||||
HIO_ASSERT (hio, hio_htre_getcontentlen(req) == 0);
|
||||
HIO_ASSERT (hio, cli->sck == csck);
|
||||
|
||||
txt = (txt_t*)hio_svc_htts_task_make(htts, HIO_SIZEOF(*txt), txt_on_kill, req, cli);
|
||||
txt = (txt_t*)hio_svc_htts_task_make(htts, HIO_SIZEOF(*txt), txt_on_kill, req, csck);
|
||||
if (HIO_UNLIKELY(!txt)) goto oops;
|
||||
|
||||
txt->on_kill = on_kill;
|
||||
@ -344,8 +342,6 @@ int hio_svc_htts_dotxt (hio_svc_htts_t* htts, hio_dev_sck_t* csck, hio_htre_t* r
|
||||
/*txt->num_pending_writes_to_client = 0;*/
|
||||
txt->req_content_length_unlimited = hio_htre_getreqcontentlen(req, &txt->req_content_length);
|
||||
|
||||
txt->csck = csck;
|
||||
txt->task_client = cli;
|
||||
txt->client_org_on_read = csck->on_read;
|
||||
txt->client_org_on_write = csck->on_write;
|
||||
txt->client_org_on_disconnect = csck->on_disconnect;
|
||||
|
Loading…
Reference in New Issue
Block a user