From c3c69ba3bbdbcd4d3fff0735a93aaaa8513d0177 Mon Sep 17 00:00:00 2001 From: Dmitri Tikhonov Date: Tue, 8 Sep 2020 14:16:25 -0400 Subject: [PATCH] Release 2.19.10 -- Fix Windows and MacOS builds --- CHANGELOG | 2 +- bin/CMakeLists.txt | 6 ++++++ bin/http_server.c | 12 ++++++++++++ bin/test_config.h.in | 1 + docs/conf.py | 2 +- include/lsquic.h | 2 +- src/liblsquic/lsquic_stream.c | 37 +++++++++++++++++++++++++++++------ 7 files changed, 53 insertions(+), 9 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 2a53fb8d5..36d1c39e5 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,5 @@ 2020-09-08 - - 2.19.9 + - 2.19.10 - [FEATURE] Add lsquic_stream_pwritev(). This function allows one to reduce the number of system calls required to read a file from disk by using lsquic_stream_pwritev() together with preadv(2). diff --git a/bin/CMakeLists.txt b/bin/CMakeLists.txt index c483d0891..01c248c67 100644 --- a/bin/CMakeLists.txt +++ b/bin/CMakeLists.txt @@ -19,6 +19,12 @@ CHECK_SYMBOL_EXISTS( HAVE_IP_DONTFRAG ) +CHECK_SYMBOL_EXISTS( + preadv + "sys/uio.h" + HAVE_PREADV +) + INCLUDE(CheckIncludeFiles) IF (MSVC AND PCRE_LIB) diff --git a/bin/http_server.c b/bin/http_server.c index e229ddf55..12d7678b5 100644 --- a/bin/http_server.c +++ b/bin/http_server.c @@ -578,8 +578,12 @@ bytes_left (lsquic_stream_ctx_t *st_h) static ssize_t my_preadv (void *user_data, const struct iovec *iov, int iovcnt) { +#if HAVE_PREADV lsquic_stream_ctx_t *const st_h = user_data; return preadv(st_h->file_fd, iov, iovcnt, st_h->written); +#else + return -1; +#endif } @@ -1594,10 +1598,12 @@ usage (const char *prog) " -p FILE Push request with this path\n" " -w SIZE Write immediately (LSWS mode). Argument specifies maximum\n" " size of the immediate write.\n" +#if HAVE_PREADV " -P SIZE Use preadv(2) to read from disk and lsquic_stream_pwritev() to\n" " write to stream. Positive SIZE indicate maximum value per\n" " write; negative means always use remaining file size.\n" " Incompatible with -w.\n" +#endif " -y DELAY Delay response for this many seconds -- use for debugging\n" , prog); } @@ -1799,8 +1805,14 @@ main (int argc, char **argv) s_immediate_write = atoi(optarg); break; case 'P': +#if HAVE_PREADV s_pwritev = strtoull(optarg, NULL, 10); break; +#else + fprintf(stderr, "preadv is not supported on this platform, " + "cannot use -P\n"); + exit(EXIT_FAILURE); +#endif case 'y': server_ctx.delay_resp_sec = atoi(optarg); break; diff --git a/bin/test_config.h.in b/bin/test_config.h.in index 22d742168..f7ea4a38c 100644 --- a/bin/test_config.h.in +++ b/bin/test_config.h.in @@ -7,6 +7,7 @@ #cmakedefine HAVE_IP_DONTFRAG 1 #cmakedefine HAVE_IP_MTU_DISCOVER 1 #cmakedefine HAVE_REGEX 1 +#cmakedefine HAVE_PREADV 1 #define LSQUIC_DONTFRAG_SUPPORTED (HAVE_IP_DONTFRAG || HAVE_IP_MTU_DISCOVER) diff --git a/docs/conf.py b/docs/conf.py index e80a88f37..03de61e22 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -26,7 +26,7 @@ # The short X.Y version version = u'2.19' # The full version, including alpha/beta/rc tags -release = u'2.19.9' +release = u'2.19.10' # -- General configuration --------------------------------------------------- diff --git a/include/lsquic.h b/include/lsquic.h index 30c44935f..e0463c530 100644 --- a/include/lsquic.h +++ b/include/lsquic.h @@ -25,7 +25,7 @@ extern "C" { #define LSQUIC_MAJOR_VERSION 2 #define LSQUIC_MINOR_VERSION 19 -#define LSQUIC_PATCH_VERSION 9 +#define LSQUIC_PATCH_VERSION 10 /** * Engine flags: diff --git a/src/liblsquic/lsquic_stream.c b/src/liblsquic/lsquic_stream.c index c67095a8c..ea03b81af 100644 --- a/src/liblsquic/lsquic_stream.c +++ b/src/liblsquic/lsquic_stream.c @@ -3604,6 +3604,11 @@ lsquic_stream_writef (lsquic_stream_t *stream, struct lsquic_reader *reader) #define PWRITEV_IOVECS LSQUIC_PWRITEV_DEF_IOVECS #define PWRITEV_FRAMES LSQUIC_PWRITEV_DEF_FRAMES #else +#if _MSC_VER +#define MALLOC_PWRITEV 1 +#else +#define MALLOC_PWRITEV 0 +#endif static unsigned PWRITEV_IOVECS = LSQUIC_PWRITEV_DEF_IOVECS, PWRITEV_FRAMES = LSQUIC_PWRITEV_DEF_FRAMES; @@ -3670,8 +3675,14 @@ lsquic_stream_pwritev (struct lsquic_stream *stream, void *user_data, size_t n_to_write) { struct lsquic_send_ctl *const ctl = stream->conn_pub->send_ctl; - struct iovec iovecs[PWRITEV_IOVECS], *last_iov; +#if MALLOC_PWRITEV + struct iovec *iovecs; + unsigned char **hq_frames; +#else + struct iovec iovecs[PWRITEV_IOVECS]; unsigned char *hq_frames[PWRITEV_FRAMES]; +#endif + struct iovec *last_iov; struct pwritev_ctx ctx; struct lsquic_reader reader; struct send_ctl_state ctl_state; @@ -3685,18 +3696,29 @@ lsquic_stream_pwritev (struct lsquic_stream *stream, COMMON_WRITE_CHECKS(); SM_HISTORY_APPEND(stream, SHE_USER_WRITE_DATA); +#if MALLOC_PWRITEV + iovecs = malloc(sizeof(iovecs[0]) * PWRITEV_IOVECS); + hq_frames = malloc(sizeof(hq_frames[0]) * PWRITEV_FRAMES); + if (!(iovecs && hq_frames)) + { + free(iovecs); + free(hq_frames); + return -1; + } +#endif + lsquic_send_ctl_snapshot(ctl, &ctl_state); ctx.total_bytes = 0; ctx.n_to_write = n_to_write; ctx.n_iovecs = 0; - ctx.max_iovecs = sizeof(iovecs) / sizeof(iovecs[0]); + ctx.max_iovecs = PWRITEV_IOVECS; ctx.iov = iovecs; ctx.hq_arr = &hq_arr; hq_arr.p = hq_frames; hq_arr.count = 0; - hq_arr.max = sizeof(hq_frames) / sizeof(hq_frames[0]); + hq_arr.max = PWRITEV_FRAMES; stream->sm_hq_arr = &hq_arr; reader.lsqr_ctx = &ctx; @@ -3719,6 +3741,10 @@ lsquic_stream_pwritev (struct lsquic_stream *stream, cleanup: stream->sm_hq_arr = NULL; +#if MALLOC_PWRITEV + free(iovecs); + free(hq_frames); +#endif return nw; unwind_short_write: @@ -3790,15 +3816,14 @@ lsquic_stream_pwritev (struct lsquic_stream *stream, /* Find last iovec: */ sum = 0; - for (last_iov = iovecs; last_iov - < iovecs + sizeof(iovecs)/sizeof(iovecs[0]); ++last_iov) + for (last_iov = iovecs; last_iov < iovecs + PWRITEV_IOVECS; ++last_iov) { sum += last_iov->iov_len; if ((last_iov == iovecs || (size_t) nw > sum - last_iov->iov_len) && (size_t) nw <= sum) break; } - assert(last_iov < iovecs + sizeof(iovecs)/sizeof(iovecs[0])); + assert(last_iov < iovecs + PWRITEV_IOVECS); lsquic_send_ctl_rollback(ctl, &ctl_state, last_iov, sum - nw); goto cleanup;