From 7ca2a8213d4efe7d36752040f5e7638ac8004102 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Thu, 3 Dec 2020 22:29:30 +0900 Subject: [PATCH] h2load: Enable --data for HTTP/3 --- src/h2load.cc | 9 +++++++++ src/h2load.h | 2 ++ src/h2load_http3_session.cc | 32 +++++++++++++++++++++++++++++--- src/h2load_http3_session.h | 2 ++ 4 files changed, 42 insertions(+), 3 deletions(-) diff --git a/src/h2load.cc b/src/h2load.cc index 0cbcaebb..a51b2372 100644 --- a/src/h2load.cc +++ b/src/h2load.cc @@ -34,6 +34,7 @@ #ifdef HAVE_FCNTL_H # include #endif // HAVE_FCNTL_H +#include #include #include @@ -90,6 +91,7 @@ Config::Config() "CHACHA20_POLY1305_SHA256:TLS_AES_128_CCM_SHA256"), groups("X25519:P-256:P-384:P-521"), data_length(-1), + data(nullptr), addrs(nullptr), nreqs(1), nclients(1), @@ -2661,6 +2663,13 @@ int main(int argc, char **argv) { exit(EXIT_FAILURE); } config.data_length = data_stat.st_size; + auto addr = mmap(nullptr, config.data_length, PROT_READ, MAP_SHARED, + config.data_fd, 0); + if (addr == MAP_FAILED) { + std::cerr << "-d: Could not mmap file " << datafile << std::endl; + exit(EXIT_FAILURE); + } + config.data = static_cast(addr); } if (!logfile.empty()) { diff --git a/src/h2load.h b/src/h2load.h index fdacf727..3f51c2c8 100644 --- a/src/h2load.h +++ b/src/h2load.h @@ -81,6 +81,8 @@ struct Config { std::string groups; // length of upload data int64_t data_length; + // memory mapped upload data + uint8_t *data; addrinfo *addrs; size_t nreqs; size_t nclients; diff --git a/src/h2load_http3_session.cc b/src/h2load_http3_session.cc index 3fad5dc7..24e99b9d 100644 --- a/src/h2load_http3_session.cc +++ b/src/h2load_http3_session.cc @@ -64,6 +64,29 @@ int Http3Session::submit_request() { return 0; } +namespace { +nghttp3_ssize read_data(nghttp3_conn *conn, int64_t stream_id, nghttp3_vec *vec, + size_t veccnt, uint32_t *pflags, void *user_data, + void *stream_user_data) { + auto s = static_cast(user_data); + + s->read_data(vec, veccnt, pflags); + + return 1; +} +} // namespace + +void Http3Session::read_data(nghttp3_vec *vec, size_t veccnt, + uint32_t *pflags) { + assert(veccnt > 0); + + auto config = client_->worker->config; + + vec[0].base = config->data; + vec[0].len = config->data_length; + *pflags |= NGHTTP3_DATA_FLAG_EOF; +} + int64_t Http3Session::submit_request_internal() { int rv; int64_t stream_id; @@ -76,9 +99,12 @@ int64_t Http3Session::submit_request_internal() { return rv; } - rv = nghttp3_conn_submit_request(conn_, stream_id, - reinterpret_cast(nva.data()), - nva.size(), nullptr, nullptr); + nghttp3_data_reader dr{}; + dr.read_data = h2load::read_data; + + rv = nghttp3_conn_submit_request( + conn_, stream_id, reinterpret_cast(nva.data()), nva.size(), + config->data_fd == -1 ? nullptr : &dr, nullptr); if (rv != 0) { return rv; } diff --git a/src/h2load_http3_session.h b/src/h2load_http3_session.h index cd3d96ba..aaca13dc 100644 --- a/src/h2load_http3_session.h +++ b/src/h2load_http3_session.h @@ -66,6 +66,8 @@ public: int add_write_offset(int64_t stream_id, size_t ndatalen); int add_ack_offset(int64_t stream_id, size_t datalen); + void read_data(nghttp3_vec *vec, size_t veccnt, uint32_t *pflags); + private: Client *client_; nghttp3_conn *conn_;