Commit 863434fa authored by Tatsuhiro Tsujikawa's avatar Tatsuhiro Tsujikawa

h2load: Enable --data for HTTP/3

parent 4660252b
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#ifdef HAVE_FCNTL_H #ifdef HAVE_FCNTL_H
# include <fcntl.h> # include <fcntl.h>
#endif // HAVE_FCNTL_H #endif // HAVE_FCNTL_H
#include <sys/mman.h>
#include <cstdio> #include <cstdio>
#include <cassert> #include <cassert>
...@@ -90,6 +91,7 @@ Config::Config() ...@@ -90,6 +91,7 @@ Config::Config()
"CHACHA20_POLY1305_SHA256:TLS_AES_128_CCM_SHA256"), "CHACHA20_POLY1305_SHA256:TLS_AES_128_CCM_SHA256"),
groups("X25519:P-256:P-384:P-521"), groups("X25519:P-256:P-384:P-521"),
data_length(-1), data_length(-1),
data(nullptr),
addrs(nullptr), addrs(nullptr),
nreqs(1), nreqs(1),
nclients(1), nclients(1),
...@@ -2661,6 +2663,13 @@ int main(int argc, char **argv) { ...@@ -2661,6 +2663,13 @@ int main(int argc, char **argv) {
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
config.data_length = data_stat.st_size; 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<uint8_t *>(addr);
} }
if (!logfile.empty()) { if (!logfile.empty()) {
......
...@@ -81,6 +81,8 @@ struct Config { ...@@ -81,6 +81,8 @@ struct Config {
std::string groups; std::string groups;
// length of upload data // length of upload data
int64_t data_length; int64_t data_length;
// memory mapped upload data
uint8_t *data;
addrinfo *addrs; addrinfo *addrs;
size_t nreqs; size_t nreqs;
size_t nclients; size_t nclients;
......
...@@ -64,6 +64,29 @@ int Http3Session::submit_request() { ...@@ -64,6 +64,29 @@ int Http3Session::submit_request() {
return 0; 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<Http3Session *>(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() { int64_t Http3Session::submit_request_internal() {
int rv; int rv;
int64_t stream_id; int64_t stream_id;
...@@ -76,9 +99,12 @@ int64_t Http3Session::submit_request_internal() { ...@@ -76,9 +99,12 @@ int64_t Http3Session::submit_request_internal() {
return rv; return rv;
} }
rv = nghttp3_conn_submit_request(conn_, stream_id, nghttp3_data_reader dr{};
reinterpret_cast<nghttp3_nv *>(nva.data()), dr.read_data = h2load::read_data;
nva.size(), nullptr, nullptr);
rv = nghttp3_conn_submit_request(
conn_, stream_id, reinterpret_cast<nghttp3_nv *>(nva.data()), nva.size(),
config->data_fd == -1 ? nullptr : &dr, nullptr);
if (rv != 0) { if (rv != 0) {
return rv; return rv;
} }
......
...@@ -66,6 +66,8 @@ public: ...@@ -66,6 +66,8 @@ public:
int add_write_offset(int64_t stream_id, size_t ndatalen); int add_write_offset(int64_t stream_id, size_t ndatalen);
int add_ack_offset(int64_t stream_id, size_t datalen); int add_ack_offset(int64_t stream_id, size_t datalen);
void read_data(nghttp3_vec *vec, size_t veccnt, uint32_t *pflags);
private: private:
Client *client_; Client *client_;
nghttp3_conn *conn_; nghttp3_conn *conn_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment