added --enable-all-static and --with-all-static-libs to ease full static binary builds for selected commands

fixed a bug where the client socket is kept when keep-alive is set. it should have been closed if client EOF is detected regardless of keep-alive
touched up debug messages in http-file.c
This commit is contained in:
2022-10-08 16:47:55 +09:00
parent ba858ecbc0
commit 7ec3ba3ab7
24 changed files with 1744 additions and 1788 deletions

View File

@ -1,7 +1,7 @@
# Makefile.in generated by automake 1.16.1 from Makefile.am.
# Makefile.in generated by automake 1.16.2 from Makefile.am.
# @configure_input@
# Copyright (C) 1994-2018 Free Software Foundation, Inc.
# Copyright (C) 1994-2020 Free Software Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
@ -263,8 +263,8 @@ am__include_HEADERS_DIST = hio-chr.h hio-cmn.h hio-dhcp.h hio-dns.h \
hio-sck.h hio-shw.h hio-skad.h hio-str.h hio-thr.h hio-upac.h \
hio-utl.h hio.h hio-mar.h
HEADERS = $(include_HEADERS)
am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) \
$(LISP)hio-cfg.h.in
am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP) \
hio-cfg.h.in
# Read a list of newline-separated strings from the standard input,
# and print each of them once, without duplicates. Input order is
# *not* preserved.
@ -287,6 +287,7 @@ am__DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/hio-cfg.h.in \
$(top_srcdir)/ac/depcomp
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
ACLOCAL = @ACLOCAL@
ALL_STATIC_LIBS = @ALL_STATIC_LIBS@
AMTAR = @AMTAR@
AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@
AR = @AR@

View File

@ -57,7 +57,6 @@ struct file_t
hio_oow_t num_pending_writes_to_client;
hio_oow_t num_pending_writes_to_peer;
int sendfile_ok;
int peer;
hio_foff_t total_size;
@ -76,6 +75,7 @@ struct file_t
unsigned int keep_alive: 1;
unsigned int req_content_length_unlimited: 1;
unsigned int ever_attempted_to_write_to_client: 1;
unsigned int client_eof_detected: 1;
unsigned int client_disconnected: 1;
unsigned int client_htrd_recbs_changed: 1;
unsigned int etag_match: 1;
@ -98,8 +98,10 @@ static void file_halt_participating_devices (file_t* file)
HIO_ASSERT (file->client->htts->hio, file->client != HIO_NULL);
HIO_ASSERT (file->client->htts->hio, file->client->sck != HIO_NULL);
HIO_DEBUG4 (file->client->htts->hio, "HTTS(%p) - Halting participating devices in file state %p(client=%p,peer=%d)\n", file->client->htts, file, file->client->sck, (int)file->peer);
HIO_DEBUG3 (file->client->htts->hio, "HTTS(%p) - file(c=%d,p=%d) Halting participating devices in file state\n", file->client->htts, (int)file->client->sck->hnd, (int)file->peer);
/* only the client socket device.
* the peer side is just a file descriptor - no hio-managed device */
hio_dev_sck_halt (file->client->sck);
}
@ -186,13 +188,13 @@ static void file_mark_over (file_t* file, int over_bits)
old_over = file->over;
file->over |= over_bits;
HIO_DEBUG5 (file->htts->hio, "HTTS(%p) - client=%p peer=%p new-bits=%x over=%x\n", file->htts, file->client->sck, file->peer, (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->client->sck->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 (hio_dev_sck_read(file->client->sck, 0) <= -1)
{
HIO_DEBUG2 (file->htts->hio, "HTTS(%p) - halting client(%p) for failure to disable input watching\n", file->htts, file->client->sck);
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->client->sck->hnd, file->peer);
hio_dev_sck_halt (file->client->sck);
}
}
@ -207,10 +209,10 @@ 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_DEBUG2 (file->htts->hio, "HTTS(%p) - halting peer(%p) as it is unneeded\n", file->htts, 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->client->sck->hnd, file->peer);
file_close_peer (file);
if (file->keep_alive)
if (file->keep_alive && !file->client_eof_detected)
{
#if defined(TCP_CORK)
int tcp_cork = 0;
@ -223,20 +225,19 @@ static void file_mark_over (file_t* file, int over_bits)
/* how to arrange to delete this file object and put the socket back to the normal waiting state??? */
HIO_ASSERT (file->htts->hio, file->client->rsrc == (hio_svc_htts_rsrc_t*)file);
HIO_SVC_HTTS_RSRC_DETACH (file->client->rsrc);
/* file must not be accessed from here down as it could have been destroyed */
/* the file resource must not be accessed from here down as it could have been destroyed */
}
else
{
HIO_DEBUG2 (file->htts->hio, "HTTS(%p) - halting client(%p) for no keep-alive\n", file->htts, file->client->sck);
HIO_DEBUG4 (file->htts->hio, "HTTS(%p) - file(c=%d,p=%d) halting client for %hs\n", file->htts, (int)file->client->sck->hnd, file->peer, (file->client_eof_detected? "EOF detected": "no keep-alive"));
hio_dev_sck_shutdown (file->client->sck, HIO_DEV_SCK_SHUTDOWN_WRITE);
hio_dev_sck_halt (file->client->sck);
/* the file resource will be detached from file->client->rsrc by the upstream disconnect handler in http_svr.c */
}
}
}
static int file_write_to_peer (file_t* file, const void* data, hio_iolen_t dlen)
{
hio_t* hio = file->htts->hio;
@ -260,7 +261,7 @@ static void file_on_kill (file_t* file)
{
hio_t* hio = file->htts->hio;
HIO_DEBUG2 (hio, "HTTS(%p) - killing file client(%p)\n", file->htts, file->client->sck);
HIO_DEBUG3 (hio, "HTTS(%p) - file(c=%d,p=%d) on_kill\n", file->htts, (int)file->client->sck->hnd, file->peer);
file_close_peer (file);
@ -292,7 +293,7 @@ static void file_on_kill (file_t* file)
{
if (!file->keep_alive || hio_dev_sck_read(file->client->sck, 1) <= -1)
{
HIO_DEBUG2 (hio, "HTTS(%p) - halting client(%p) for failure to enable input watching\n", file->htts, file->client->sck);
HIO_DEBUG3 (hio, "HTTS(%p) - file(c=%d,p=%d) halting client for failure to enable input watching\n", file->htts, (int)file->client->sck->hnd, file->peer);
hio_dev_sck_halt (file->client->sck);
}
}
@ -300,10 +301,21 @@ static void file_on_kill (file_t* file)
static void file_client_on_disconnect (hio_dev_sck_t* sck)
{
hio_t* hio = sck->hio;
hio_svc_htts_cli_t* cli = hio_dev_sck_getxtn(sck);
file_t* file = (file_t*)cli->rsrc;
HIO_ASSERT (hio, sck == cli->sck);
HIO_ASSERT (hio, sck == file->client->sck);
HIO_DEBUG3 (cli->htts->hio, "HTTS(%p) - file(c=%d,p=%d) client on_disconnect\n", file->client->htts, (int)sck->hnd, file->peer);
file->client_disconnected = 1;
file->client_org_on_disconnect (sck);
/* the original disconnect handler (listener_on_disconnect in http-svr.c)
* frees the file resource attached to the client. so it must not be accessed */
HIO_ASSERT (hio, cli->rsrc == HIO_NULL);
}
static int file_client_on_read (hio_dev_sck_t* sck, const void* buf, hio_iolen_t len, const hio_skad_t* srcaddr)
@ -313,11 +325,12 @@ static int file_client_on_read (hio_dev_sck_t* sck, const void* buf, hio_iolen_t
file_t* file = (file_t*)cli->rsrc;
HIO_ASSERT (hio, sck == cli->sck);
HIO_ASSERT (hio, sck == file->client->sck);
if (len <= -1)
{
/* read error */
HIO_DEBUG2 (cli->htts->hio, "HTTPS(%p) - read error on client %p(%d)\n", sck, (int)sck->hnd);
HIO_DEBUG3 (cli->htts->hio, "HTTS(%p) - file(c=%d,p=%d) read error on client\n", file->client->htts, (int)sck->hnd, file->peer);
goto oops;
}
@ -330,11 +343,12 @@ static int file_client_on_read (hio_dev_sck_t* sck, const void* buf, hio_iolen_t
if (len == 0)
{
/* EOF on the client side. arrange to close */
HIO_DEBUG3 (hio, "HTTPS(%p) - EOF from client %p(hnd=%d)\n", file->client->htts, sck, (int)sck->hnd);
HIO_DEBUG3 (cli->htts->hio, "HTTS(%p) - file(c=%d,p=%d) EOF detected on client\n", file->client->htts, (int)sck->hnd, file->peer);
if (!(file->over & FILE_OVER_READ_FROM_CLIENT)) /* if this is true, EOF is received without file_client_htrd_poke() */
{
if (file_write_to_peer(file, HIO_NULL, 0) <= -1) goto oops;
file->client_eof_detected = 1;
file_mark_over (file, FILE_OVER_READ_FROM_CLIENT);
}
}
@ -349,7 +363,7 @@ static int file_client_on_read (hio_dev_sck_t* sck, const void* buf, hio_iolen_t
if (rem > 0)
{
/* TODO store this to client buffer. once the current resource is completed, arrange to call on_read() with it */
HIO_DEBUG3 (hio, "HTTPS(%p) - excessive data after contents by file client %p(%d)\n", sck->hio, sck, (int)sck->hnd);
HIO_DEBUG3 (cli->htts->hio, "HTTS(%p) - file(c=%d,p=%d) excessive data after contents on client\n", file->client->htts, (int)sck->hnd, file->peer);
}
}
@ -366,9 +380,12 @@ static int file_client_on_write (hio_dev_sck_t* sck, hio_iolen_t wrlen, void* wr
hio_svc_htts_cli_t* cli = hio_dev_sck_getxtn(sck);
file_t* file = (file_t*)cli->rsrc;
HIO_ASSERT (hio, sck == cli->sck);
HIO_ASSERT (hio, sck == file->client->sck);
if (wrlen <= -1)
{
HIO_DEBUG3 (hio, "HTTPS(%p) - unable to write to client %p(%d)\n", sck->hio, sck, (int)sck->hnd);
HIO_DEBUG3 (hio, "HTTS(%p) - file(c=%d,p=%d) unable to write to client\n", file->client->htts, (int)sck->hnd, file->peer);
goto oops;
}
@ -377,7 +394,7 @@ static int file_client_on_write (hio_dev_sck_t* sck, hio_iolen_t wrlen, void* wr
/* if the connect is keep-alive, this part may not be called */
file->num_pending_writes_to_client--;
HIO_ASSERT (hio, file->num_pending_writes_to_client == 0);
HIO_DEBUG3 (hio, "HTTS(%p) - indicated EOF to client %p(%d)\n", file->client->htts, sck, (int)sck->hnd);
HIO_DEBUG3 (hio, "HTTS(%p) - file(c=%d,p=%d) indicated EOF to client\n", file->client->htts, (int)sck->hnd, file->peer);
/* since EOF has been indicated to the client, it must not write to the client any further.
* this also means that i don't need any data from the peer side either.
* i don't need to enable input watching on the peer side */
@ -733,6 +750,9 @@ int hio_svc_htts_dofile (hio_svc_htts_t* htts, hio_dev_sck_t* csck, hio_htre_t*
/* ensure that you call this function before any contents is received */
HIO_ASSERT (hio, hio_htre_getcontentlen(req) == 0);
HIO_ASSERT (hio, cli->sck == csck);
HIO_DEBUG5 (hio, "HTTS(%p) - file(c=%d) - [%hs] %hs%hs\n", htts, (int)csck->hnd, cli->cli_addr_bcstr, (docroot[0] == '/' && docroot[1] == '\0' && filepath[0] == '/'? "": docroot), filepath);
actual_file = hio_svc_htts_dupmergepaths(htts, docroot, filepath);
if (HIO_UNLIKELY(!actual_file)) goto oops;
@ -756,7 +776,7 @@ int hio_svc_htts_dofile (hio_svc_htts_t* htts, hio_dev_sck_t* csck, hio_htre_t*
csck->on_disconnect = file_client_on_disconnect;
HIO_ASSERT (hio, cli->rsrc == HIO_NULL); /* you must not call this function while cli->rsrc is not HIO_NULL */
HIO_SVC_HTTS_RSRC_ATTACH (file, cli->rsrc);
HIO_SVC_HTTS_RSRC_ATTACH (file, cli->rsrc); /* cli->rsrc = file with ref-count up */
file->peer_tmridx = HIO_TMRIDX_INVALID;
file->peer = -1;
@ -879,7 +899,7 @@ int hio_svc_htts_dofile (hio_svc_htts_t* htts, hio_dev_sck_t* csck, hio_htre_t*
return 0;
oops:
HIO_DEBUG2 (hio, "HTTS(%p) - FAILURE in dofile - socket(%p)\n", htts, csck);
HIO_DEBUG2 (hio, "HTTS(%p) - file(c=%d) failure\n", htts, csck->hnd);
if (file) file_halt_participating_devices (file);
if (actual_file) hio_freemem (hio, actual_file);
return -1;

View File

@ -40,6 +40,8 @@ struct hio_svc_htts_cli_t
/* a client sockets uses all the fields in this struct */
hio_svc_htts_t* htts;
hio_dev_sck_t* sck;
hio_skad_t cli_addr;
hio_bch_t cli_addr_bcstr[HIO_SKAD_IP_STRLEN + 1];
hio_oow_t l_idx; /* listening socket: < htts->l.count, client socket: >= htts->l.count */
hio_htrd_t* htrd;

View File

@ -53,6 +53,8 @@ static int init_client (hio_svc_htts_cli_t* cli, hio_dev_sck_t* sck)
HIO_ASSERT (sck->hio, sck->hio == cli->htts->hio);
cli->sck = sck;
if (hio_dev_sck_getpeeraddr (sck, &cli->cli_addr) >= 0)
hio_skadtobcstr (sck->hio, &cli->cli_addr, cli->cli_addr_bcstr, HIO_COUNTOF(cli->cli_addr_bcstr), HIO_SKAD_TO_BCSTR_ADDR | HIO_SKAD_TO_BCSTR_PORT);
cli->l_idx = INVALID_LIDX; /* not a listening socket anymore */
cli->htrd = HIO_NULL;
cli->sbuf = HIO_NULL;
@ -77,7 +79,7 @@ static int init_client (hio_svc_htts_cli_t* cli, hio_dev_sck_t* sck)
hio_htrd_setrecbs (cli->htrd, &client_htrd_recbs);
hio_gettime (sck->hio, &cli->last_active);
HIO_DEBUG3 (sck->hio, "HTTS(%p) - initialized client %p socket %p\n", cli->htts, cli, sck);
HIO_DEBUG4 (sck->hio, "HTTS(%p) - initialized client(%p,%p,%d)\n", cli->htts, cli, sck, (int)sck->hnd);
return 0;
oops:
@ -98,12 +100,16 @@ oops:
static void fini_client (hio_svc_htts_cli_t* cli)
{
HIO_DEBUG3 (cli->sck->hio, "HTTS(%p) - finalizing client %p socket %p\n", cli->htts, cli, cli->sck);
HIO_DEBUG4 (cli->sck->hio, "HTTS(%p) - finalizing client(%p,%p,%d)\n", cli->htts, cli, cli->sck, (int)cli->sck->hnd);
if (cli->rsrc)
{
#if 0
hio_svc_htts_rsrc_kill (cli->rsrc);
cli->rsrc = HIO_NULL;
#else
HIO_SVC_HTTS_RSRC_DETACH (cli->rsrc);
#endif
}
if (cli->sbuf)
@ -209,18 +215,18 @@ static void listener_on_connect (hio_dev_sck_t* sck)
if (sck->state & HIO_DEV_SCK_ACCEPTED)
{
/* accepted a new client */
HIO_DEBUG3 (sck->hio, "HTTS(%p) - accepted... %p %d \n", cli->htts, sck, sck->hnd);
HIO_DEBUG3 (sck->hio, "HTTS(%p) - accepted client(%p,%d) \n", cli->htts, sck, (int)sck->hnd);
if (init_client(cli, sck) <= -1)
{
HIO_DEBUG2 (cli->htts->hio, "HTTS(%p) - halting client(%p) for client intiaialization failure\n", cli->htts, sck);
HIO_DEBUG3 (cli->htts->hio, "HTTS(%p) - halting client(%p,%d) for client intiaialization failure\n", cli->htts, sck, (int)sck->hnd);
hio_dev_sck_halt (sck);
}
}
else if (sck->state & HIO_DEV_SCK_CONNECTED)
{
/* this will never be triggered as the listing socket never call hio_dev_sck_connect() */
HIO_DEBUG3 (sck->hio, "** HTTS(%p) - connected... %p %d \n", cli->htts, sck, sck->hnd);
HIO_DEBUG3 (sck->hio, "HTTS(%p) - connected (%p,%d) \n", cli->htts, sck, (int)sck->hnd);
}
/* HIO_DEV_SCK_CONNECTED must not be seen here as this is only for the listener socket */
@ -314,7 +320,7 @@ static void halt_idle_clients (hio_t* hio, const hio_ntime_t* now, hio_tmrjob_t*
if (HIO_CMP_NTIME(&t, &max_client_idle) >= 0)
{
HIO_DEBUG3 (hio, "HTTS(%p) - Halting idle client socket %p(client=%p)\n", htts, cli->sck, cli);
HIO_DEBUG4 (hio, "HTTS(%p) - Halting idle client(%p,%p,%d)\n", htts, cli, cli->sck, (int)cli->sck->hnd);
hio_dev_sck_halt (cli->sck);
}
}
@ -404,7 +410,7 @@ hio_svc_htts_t* hio_svc_htts_start (hio_t* hio, hio_oow_t xtnsize, hio_dev_sck_b
* most of other fields are used for client management. init_client() will set
* the sck field to the client socket and the listening field to 0. */
cli = (hio_svc_htts_cli_t*)hio_dev_sck_getxtn(sck);
cli->htts = htts;
cli->htts = htts;
cli->sck = sck;
cli->l_idx = i;