diff --git a/mio/lib/http-svr.c b/mio/lib/http-svr.c index d3a0321..8aad3d4 100644 --- a/mio/lib/http-svr.c +++ b/mio/lib/http-svr.c @@ -863,6 +863,14 @@ int mio_svc_htts_dofile (mio_svc_htts_t* htts, mio_dev_sck_t* csck, mio_htre_t* /* ----------------------------------------------------------------- */ +enum cgi_state_res_mode_t +{ + CGI_STATE_RES_MODE_CHUNKED, + CGI_STATE_RES_MODE_CLOSE + /* CGI_STATE_RES_MODE_LENGTH */ +}; +typedef enum cgi_state_res_mode_t cgi_state_res_mode_t; + struct cgi_state_t { @@ -881,6 +889,8 @@ struct cgi_state_t mio_htre_t* req; mio_oow_t req_content_length; + cgi_state_res_mode_t res_mode_to_cli; + mio_dev_sck_on_read_t cli_org_on_read; mio_dev_sck_on_write_t cli_org_on_write; }; @@ -940,26 +950,36 @@ static int cgi_peer_on_read (mio_dev_pro_t* pro, mio_dev_pro_sid_t sid, const vo { mio_t* mio = pro->mio; cgi_peer_xtn_t* cgi_peer = mio_dev_pro_getxtn(pro); + cgi_state_t* cgi_state = cgi_peer->state; if (dlen <= -1) { MIO_DEBUG1 (mio, "PROCESS(%d): READ TIMED OUT...\n", (int)pro->child_pid); mio_dev_pro_halt (pro); - return 0; } else if (dlen <= 0) { MIO_DEBUG1 (mio, "PROCESS(%d): EOF RECEIVED...\n", (int)pro->child_pid); /* no outstanding request. but EOF */ +/* TODO: arrange to finish chunk. or close... also finish the entire state... */ mio_dev_pro_halt (pro); - return 0; } - - MIO_DEBUG5 (mio, "PROCESS(%d) READ DATA ON SLAVE[%d] len=%d [%.*hs]\n", (int)pro->child_pid, (int)sid, (int)dlen, dlen, (char*)data); - if (sid == MIO_DEV_PRO_OUT) + else { - mio_dev_pro_read (pro, sid, 0); - mio_dev_pro_write (pro, "HELLO\n", 6, MIO_NULL); + MIO_DEBUG5 (mio, "PROCESS(%d) READ DATA ON SLAVE[%d] len=%d [%.*hs]\n", (int)pro->child_pid, (int)sid, (int)dlen, dlen, (char*)data); + if (sid == MIO_DEV_PRO_OUT) + { + //mio_dev_pro_read (pro, sid, 0); + //mio_dev_pro_write (pro, "HELLO\n", 6, MIO_NULL); + + /* If chunked, need to write in the chunked format... */ + cgi_state->num_pending_writes_to_client++; + if (mio_dev_sck_write(cgi_state->cli->sck, data, dlen, MIO_NULL, 0) <= -1) + { + cgi_state->num_pending_writes_to_client--; + mio_dev_pro_halt (pro); + } + } } return 0; } diff --git a/mio/lib/mio.c b/mio/lib/mio.c index 69bda96..2668be8 100644 --- a/mio/lib/mio.c +++ b/mio/lib/mio.c @@ -567,12 +567,18 @@ static MIO_INLINE void handle_event (mio_t* mio, mio_dev_t* dev, int events, int * is started from within on_read() callback, and the input data is available * in the next iteration of this loop, the on_read() callback is triggered * before the on_write() callbacks scheduled before that on_read() callback. */ + #if 0 if (dev->cw_count > 0) { fire_cwq_handlers_for_dev (mio, dev); /* it will still invoke the on_read() callbak below even if * the device gets halted inside fire_cwq_handlers_for_dev() */ } + #else + /* currently fire_cwq_handlers_for_dev() scans the entire cwq list. + * i might as well triggger handlers for all devices */ + fire_cwq_handlers (mio); + #endif if (len <= 0 && (dev->dev_cap & MIO_DEV_CAP_STREAM)) { diff --git a/mio/t/b.sh b/mio/t/b.sh new file mode 100755 index 0000000..b0e7339 --- /dev/null +++ b/mio/t/b.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +exec cat /home/hyung-hwan/projects/hawk/lib/run.c diff --git a/mio/t/http1.hawk b/mio/t/http1.hawk new file mode 100644 index 0000000..237a7c4 --- /dev/null +++ b/mio/t/http1.hawk @@ -0,0 +1,15 @@ +BEGIN { + + + x = sys::socket (sys::AF_INET, sys::SOCK_STREAM, 0); + sys::connect (x, "127.0.0.1:9988"); + +msg = b"GET /home/hyung-hwan/projects/mio/bld/b.sh HTTP/1.0\r\n\ +Host: www.google.com\r\n\ +Connection: Keep-Alive\r\n\r\n"; + + + sys::write (x, msg); + while (sys::read (x, buf) >= 0) printf ("%s", buf); + sys::close (x); +}