changed mio_svc_htts_start() to accept mio_dev_sck_bind_t* instead of mio_skad_t*
This commit is contained in:
parent
fc74064984
commit
18eda3a6b5
@ -1224,7 +1224,7 @@ for (i = 0; i < 5; i++)
|
||||
mio_svc_htts_t* htts;
|
||||
mio_ntime_t send_tmout, reply_tmout;
|
||||
mio_skad_t servaddr;
|
||||
mio_skad_t htts_bind_addr;
|
||||
mio_dev_sck_bind_t htts_bind_info;
|
||||
|
||||
send_tmout.sec = 0;
|
||||
send_tmout.nsec = 0;
|
||||
@ -1238,8 +1238,13 @@ for (i = 0; i < 5; i++)
|
||||
//mio_bcstrtoskad (mio, "[fe80::c7e2:bd6e:1209:ac1b]:1153", &servaddr);
|
||||
//mio_bcstrtoskad (mio, "[fe80::c7e2:bd6e:1209:ac1b%eno1]:1153", &servaddr);
|
||||
|
||||
//mio_bcstrtoskad (mio, "[::]:9988", &htts_bind_addr);
|
||||
mio_bcstrtoskad (mio, "0.0.0.0:9988", &htts_bind_addr);
|
||||
memset (&htts_bind_info, 0, MIO_SIZEOF(htts_bind_info));
|
||||
//mio_bcstrtoskad (mio, "[""]:9988", &htts_bind_info.localaddr);
|
||||
mio_bcstrtoskad (mio, "0.0.0.0:9988", &htts_bind_info.localaddr);
|
||||
htts_bind_info.options = MIO_DEV_SCK_BIND_REUSEADDR | MIO_DEV_SCK_BIND_REUSEPORT | MIO_DEV_SCK_BIND_IGNERR;
|
||||
htts_bind_info.options |= MIO_DEV_SCK_BIND_SSL;
|
||||
htts_bind_info.ssl_certfile = "localhost.crt";
|
||||
htts_bind_info.ssl_keyfile = "localhost.key";
|
||||
|
||||
dnc = mio_svc_dnc_start(mio, &servaddr, MIO_NULL, &send_tmout, &reply_tmout, 2); /* option - send to all, send one by one */
|
||||
if (!dnc)
|
||||
@ -1247,7 +1252,7 @@ for (i = 0; i < 5; i++)
|
||||
MIO_INFO1 (mio, "UNABLE TO START DNC - %js\n", mio_geterrmsg(mio));
|
||||
}
|
||||
|
||||
htts = mio_svc_htts_start(mio, &htts_bind_addr, process_http_request);
|
||||
htts = mio_svc_htts_start(mio, &htts_bind_info, process_http_request);
|
||||
if (htts) mio_svc_htts_setservernamewithbcstr (htts, "MIO-HTTP");
|
||||
else MIO_INFO1 (mio, "UNABLE TO START HTTS - %js\n", mio_geterrmsg(mio));
|
||||
|
||||
|
@ -58,6 +58,7 @@ struct file_state_t
|
||||
mio_oow_t num_pending_writes_to_client;
|
||||
mio_oow_t num_pending_writes_to_peer;
|
||||
|
||||
int sendfile_ok;
|
||||
int peer;
|
||||
mio_foff_t total_size;
|
||||
mio_foff_t start_offset;
|
||||
@ -471,11 +472,6 @@ static void send_contents_to_client_later (mio_t* mio, const mio_ntime_t* now, m
|
||||
|
||||
static int file_state_send_contents_to_client (file_state_t* file_state)
|
||||
{
|
||||
/* TODO: implement mio_dev_sck_sendfile(0 or enhance mio_dev_sck_write() to emulate sendfile
|
||||
*
|
||||
* mio_dev_sck_setsendfile (ON);
|
||||
* mio_dev_sck_write(sck, data_required_for_sendfile_operation, 0, MIO_NULL);....
|
||||
*/
|
||||
mio_t* mio = file_state->htts->mio;
|
||||
mio_foff_t lim;
|
||||
|
||||
@ -487,8 +483,7 @@ static int file_state_send_contents_to_client (file_state_t* file_state)
|
||||
}
|
||||
|
||||
lim = file_state->end_offset - file_state->cur_offset + 1;
|
||||
|
||||
if (1 /*mio_dev_sck_sendfileok(file_state->client->sck)*/)
|
||||
if (file_state->sendfile_ok)
|
||||
{
|
||||
if (lim > 0x7FFF0000) lim = 0x7FFF0000; /* TODO: change this... */
|
||||
if (file_state_sendfile_to_client(file_state, file_state->cur_offset, lim) <= -1) return -1;
|
||||
@ -683,6 +678,7 @@ int mio_svc_htts_dofile (mio_svc_htts_t* htts, mio_dev_sck_t* csck, mio_htre_t*
|
||||
if (MIO_UNLIKELY(!file_state)) goto oops;
|
||||
|
||||
file_state->client = cli;
|
||||
file_state->sendfile_ok = mio_dev_sck_sendfileok(cli->sck);
|
||||
/*file_state->num_pending_writes_to_client = 0;
|
||||
file_state->num_pending_writes_to_peer = 0;*/
|
||||
file_state->req_version = *mio_htre_getversion(req);
|
||||
|
@ -274,13 +274,12 @@ static void listener_on_disconnect (mio_dev_sck_t* sck)
|
||||
|
||||
/* ------------------------------------------------------------------------ */
|
||||
|
||||
mio_svc_htts_t* mio_svc_htts_start (mio_t* mio, const mio_skad_t* bind_addr, mio_svc_htts_proc_req_t proc_req)
|
||||
mio_svc_htts_t* mio_svc_htts_start (mio_t* mio, mio_dev_sck_bind_t* sck_bind, mio_svc_htts_proc_req_t proc_req)
|
||||
{
|
||||
mio_svc_htts_t* htts = MIO_NULL;
|
||||
union
|
||||
{
|
||||
mio_dev_sck_make_t m;
|
||||
mio_dev_sck_bind_t b;
|
||||
mio_dev_sck_listen_t l;
|
||||
} info;
|
||||
mio_svc_htts_cli_t* cli;
|
||||
@ -293,7 +292,7 @@ mio_svc_htts_t* mio_svc_htts_start (mio_t* mio, const mio_skad_t* bind_addr, mio
|
||||
htts->proc_req = proc_req;
|
||||
|
||||
MIO_MEMSET (&info, 0, MIO_SIZEOF(info));
|
||||
switch (mio_skad_family(bind_addr))
|
||||
switch (mio_skad_family(&sck_bind->localaddr))
|
||||
{
|
||||
case MIO_AF_INET:
|
||||
info.m.type = MIO_DEV_SCK_TCP4;
|
||||
@ -324,13 +323,7 @@ mio_svc_htts_t* mio_svc_htts_start (mio_t* mio, const mio_skad_t* bind_addr, mio
|
||||
cli->htts = htts;
|
||||
cli->sck = htts->lsck;
|
||||
|
||||
MIO_MEMSET (&info, 0, MIO_SIZEOF(info));
|
||||
info.b.localaddr = *bind_addr;
|
||||
info.b.options = MIO_DEV_SCK_BIND_REUSEADDR | MIO_DEV_SCK_BIND_REUSEPORT | MIO_DEV_SCK_BIND_IGNERR;
|
||||
/*info.b.options |= MIO_DEV_SCK_BIND_SSL; */
|
||||
info.b.ssl_certfile = "localhost.crt";
|
||||
info.b.ssl_keyfile = "localhost.key";
|
||||
if (mio_dev_sck_bind(htts->lsck, &info.b) <= -1) goto oops;
|
||||
if (mio_dev_sck_bind(htts->lsck, sck_bind) <= -1) goto oops;
|
||||
|
||||
MIO_MEMSET (&info, 0, MIO_SIZEOF(info));
|
||||
info.l.options = MIO_DEV_SCK_LISTEN_LENIENT;
|
||||
|
@ -249,9 +249,9 @@ MIO_EXPORT int mio_scan_http_qparam (
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
MIO_EXPORT mio_svc_htts_t* mio_svc_htts_start (
|
||||
mio_t* mio,
|
||||
const mio_skad_t* bind_addr,
|
||||
mio_svc_htts_proc_req_t proc_req
|
||||
mio_t* mio,
|
||||
mio_dev_sck_bind_t* sck_bind,
|
||||
mio_svc_htts_proc_req_t proc_req
|
||||
);
|
||||
|
||||
MIO_EXPORT void mio_svc_htts_stop (
|
||||
|
@ -562,6 +562,10 @@ MIO_EXPORT int mio_dev_sck_shutdown (
|
||||
int how /* bitwise-ORed of mio_dev_sck_shutdown_how_t enumerators */
|
||||
);
|
||||
|
||||
MIO_EXPORT int mio_dev_sck_sendfileok (
|
||||
mio_dev_sck_t* dev
|
||||
);
|
||||
|
||||
MIO_EXPORT mio_uint16_t mio_checksum_ip (
|
||||
const void* hdr,
|
||||
mio_oow_t len
|
||||
|
@ -1837,6 +1837,15 @@ int mio_dev_sck_shutdown (mio_dev_sck_t* dev, int how)
|
||||
return shutdown(dev->hnd, how);
|
||||
}
|
||||
|
||||
int mio_dev_sck_sendfileok (mio_dev_sck_t* dev)
|
||||
{
|
||||
#if defined(USE_SSL)
|
||||
return !(dev->ssl);
|
||||
#else
|
||||
return 1;
|
||||
#endif
|
||||
}
|
||||
|
||||
/* ========================================================================= */
|
||||
|
||||
mio_uint16_t mio_checksum_ip (const void* hdr, mio_oow_t len)
|
||||
|
Loading…
Reference in New Issue
Block a user