src: Use user-defined literals for k, m, and g.

This commit is contained in:
Tatsuhiro Tsujikawa 2015-06-21 14:32:47 +09:00
parent 46b70c1db8
commit 39f89f4a60
20 changed files with 58 additions and 32 deletions

View File

@ -453,7 +453,7 @@ int Http2Handler::fill_wb() {
int Http2Handler::read_clear() {
int rv;
std::array<uint8_t, 8192> buf;
std::array<uint8_t, 8_k> buf;
for (;;) {
ssize_t nread;
@ -570,7 +570,7 @@ int Http2Handler::tls_handshake() {
}
int Http2Handler::read_tls() {
std::array<uint8_t, 8192> buf;
std::array<uint8_t, 8_k> buf;
ERR_clear_error();

View File

@ -45,6 +45,7 @@
#include "http2.h"
#include "buffer.h"
#include "template.h"
namespace nghttp2 {
@ -155,7 +156,7 @@ public:
struct ev_loop *get_loop() const;
using WriteBuf = Buffer<65536>;
using WriteBuf = Buffer<64_k>;
WriteBuf *get_wb();

View File

@ -58,6 +58,7 @@
#include "app_helper.h"
#include "util.h"
#include "http2.h"
#include "template.h"
namespace nghttp2 {
@ -463,7 +464,7 @@ ssize_t deflate_data(uint8_t *out, size_t outlen, const uint8_t *in,
size_t inlen) {
int rv;
z_stream zst;
uint8_t temp_out[8192];
uint8_t temp_out[8_k];
auto temp_outlen = sizeof(temp_out);
zst.next_in = Z_NULL;

View File

@ -313,7 +313,7 @@ bool session_impl::setup_session() {
return false;
}
const uint32_t window_size = 256 * 1024 * 1024;
const uint32_t window_size = 256_m;
std::array<nghttp2_settings_entry, 2> iv{
{{NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS, 100},

View File

@ -31,6 +31,8 @@
#include <nghttp2/asio_http2_client.h>
#include "template.h"
namespace nghttp2 {
namespace asio_http2 {
namespace client {
@ -90,8 +92,8 @@ public:
void do_write();
protected:
boost::array<uint8_t, 8192> rb_;
boost::array<uint8_t, 65536> wb_;
boost::array<uint8_t, 8_k> rb_;
boost::array<uint8_t, 64_k> wb_;
std::size_t wblen_;
private:

View File

@ -49,6 +49,7 @@
#include "asio_server_http2_handler.h"
#include "asio_server_serve_mux.h"
#include "util.h"
#include "template.h"
namespace nghttp2 {
@ -153,9 +154,9 @@ private:
std::shared_ptr<http2_handler> handler_;
/// Buffer for incoming data.
boost::array<uint8_t, 8192> buffer_;
boost::array<uint8_t, 8_k> buffer_;
boost::array<uint8_t, 65536> outbuf_;
boost::array<uint8_t, 64_k> outbuf_;
bool writing_;
};

View File

@ -49,6 +49,10 @@ extern "C" {
#include "comp_helper.h"
}
#include "template.h"
namespace nghttp2 {
typedef struct {
size_t table_size;
size_t deflate_table_size;
@ -122,7 +126,7 @@ static void deflate_hd(nghttp2_hd_deflater *deflater,
ssize_t rv;
nghttp2_bufs bufs;
nghttp2_bufs_init2(&bufs, 4096, 16, 0, nghttp2_mem_default());
nghttp2_bufs_init2(&bufs, 4_k, 16, 0, nghttp2_mem_default());
rv = nghttp2_hd_deflate_hd_bufs(deflater, &bufs, (nghttp2_nv *)nva.data(),
nva.size());
@ -448,3 +452,7 @@ int main(int argc, char **argv) {
output_sum, comp_ratio);
return 0;
}
} // namespace nghttp2
int main(int argc, char **argv) { return nghttp2::main(argc, argv); }

View File

@ -506,7 +506,7 @@ int Client::on_write() {
}
int Client::read_clear() {
uint8_t buf[8192];
uint8_t buf[8_k];
for (;;) {
ssize_t nread;
@ -626,7 +626,7 @@ int Client::tls_handshake() {
}
int Client::read_tls() {
uint8_t buf[8192];
uint8_t buf[8_k];
ERR_clear_error();

View File

@ -50,6 +50,7 @@
#include "http2.h"
#include "buffer.h"
#include "template.h"
using namespace nghttp2;
@ -200,7 +201,7 @@ struct Client {
// The number of requests this client has done so far.
size_t req_done;
int fd;
Buffer<65536> wb;
Buffer<64_k> wb;
enum { ERR_CONNECT_FAIL = -100 };

View File

@ -228,7 +228,7 @@ template <typename Memchunk> struct Memchunks {
size_t len;
};
using Memchunk16K = Memchunk<16384>;
using Memchunk16K = Memchunk<16_k>;
using MemchunkPool = Pool<Memchunk16K>;
using DefaultMemchunks = Memchunks<Memchunk16K>;

View File

@ -95,7 +95,7 @@ constexpr auto anchors = std::array<Anchor, 5>{{
} // namespace
Config::Config()
: output_upper_thres(1024 * 1024), padding(0),
: padding(0),
peer_max_concurrent_streams(NGHTTP2_INITIAL_MAX_CONCURRENT_STREAMS),
header_table_size(-1), weight(NGHTTP2_DEFAULT_WEIGHT), multiply(1),
timeout(0.), window_bits(-1), connection_window_bits(-1), verbose(0),
@ -362,7 +362,7 @@ int submit_request(HttpClient *client, const Headers &headers, Request *req) {
if (config.continuation) {
for (size_t i = 0; i < 6; ++i) {
build_headers.emplace_back("continuation-test-" + util::utos(i + 1),
std::string(4096, '-'));
std::string(4_k, '-'));
}
}
auto num_initial_headers = build_headers.size();
@ -634,7 +634,7 @@ void HttpClient::disconnect() {
int HttpClient::read_clear() {
ev_timer_again(loop, &rt);
std::array<uint8_t, 8192> buf;
std::array<uint8_t, 8_k> buf;
for (;;) {
ssize_t nread;
@ -1149,7 +1149,7 @@ int HttpClient::read_tls() {
ERR_clear_error();
std::array<uint8_t, 8192> buf;
std::array<uint8_t, 8_k> buf;
for (;;) {
auto rv = SSL_read(ssl, buf.data(), buf.size());
@ -1525,7 +1525,7 @@ int on_data_chunk_recv_callback(nghttp2_session *session, uint8_t flags,
if (req->inflater) {
while (len > 0) {
const size_t MAX_OUTLEN = 4096;
const size_t MAX_OUTLEN = 4_k;
std::array<uint8_t, MAX_OUTLEN> out;
size_t outlen = MAX_OUTLEN;
size_t tlen = len;
@ -2244,7 +2244,7 @@ int run(char **uris, int n) {
<< std::endl;
}
while (1) {
std::array<char, 1024> buf;
std::array<char, 1_k> buf;
ssize_t rret, wret;
while ((rret = read(0, buf.data(), buf.size())) == -1 &&
errno == EINTR)

View File

@ -52,6 +52,7 @@
#include "buffer.h"
#include "http2.h"
#include "nghttp2_gzip.h"
#include "template.h"
namespace nghttp2 {
@ -68,7 +69,6 @@ struct Config {
std::string datafile;
std::string harfile;
nghttp2_option *http2_option;
size_t output_upper_thres;
size_t padding;
ssize_t peer_max_concurrent_streams;
ssize_t header_table_size;
@ -260,7 +260,7 @@ struct HttpClient {
// true if the response message of HTTP Upgrade request is fully
// received. It is not relevant the upgrade succeeds, or not.
bool upgrade_response_complete;
Buffer<65536> wb;
Buffer<64_k> wb;
// SETTINGS payload sent as token68 in HTTP Upgrade
std::array<uint8_t, 128> settings_payload;

View File

@ -945,8 +945,8 @@ void fill_default_config() {
mod_config()->downstream_connections_per_host = 8;
mod_config()->downstream_connections_per_frontend = 0;
mod_config()->listener_disable_timeout = 0.;
mod_config()->downstream_request_buffer_size = 16 * 1024;
mod_config()->downstream_response_buffer_size = 16 * 1024;
mod_config()->downstream_request_buffer_size = 16_k;
mod_config()->downstream_response_buffer_size = 16_k;
mod_config()->no_server_push = false;
mod_config()->host_unix = false;
mod_config()->http2_downstream_connections_per_worker = 0;
@ -955,7 +955,7 @@ void fill_default_config() {
mod_config()->fetch_ocsp_response_file =
strcopy(PKGDATADIR "/fetch-ocsp-response");
mod_config()->no_ocsp = false;
mod_config()->header_field_buffer = 64 * 1024;
mod_config()->header_field_buffer = 64_k;
mod_config()->max_header_fields = 100;
}
} // namespace

View File

@ -119,7 +119,7 @@ public:
Worker *get_worker() const;
using WriteBuf = Buffer<32768>;
using ReadBuf = Buffer<8192>;
using ReadBuf = Buffer<8_k>;
WriteBuf *get_wb();
ReadBuf *get_rb();

View File

@ -455,7 +455,7 @@ int ConnectionHandler::start_ocsp_update(const char *cert_file) {
}
void ConnectionHandler::read_ocsp_chunk() {
std::array<uint8_t, 4096> buf;
std::array<uint8_t, 4_k> buf;
for (;;) {
ssize_t n;
while ((n = read(ocsp_.fd, buf.data(), buf.size())) == -1 && errno == EINTR)

View File

@ -177,7 +177,7 @@ public:
CONNECTION_CHECK_STARTED
};
using ReadBuf = Buffer<8192>;
using ReadBuf = Buffer<8_k>;
using WriteBuf = Buffer<32768>;
private:

View File

@ -729,7 +729,7 @@ int HttpDownstreamConnection::on_read() {
}
ev_timer_again(conn_.loop, &conn_.rt);
std::array<uint8_t, 8192> buf;
std::array<uint8_t, 8_k> buf;
int rv;
if (downstream_->get_upgraded()) {

View File

@ -125,7 +125,7 @@ Log::~Log() {
return;
}
char buf[4096];
char buf[4_k];
auto tty = lgconf->errorlog_tty;
lgconf->update_tstamp(std::chrono::system_clock::now());
@ -172,7 +172,7 @@ void upstream_accesslog(const std::vector<LogFragment> &lfv,
return;
}
char buf[4096];
char buf[4_k];
auto downstream = lgsp.downstream;

View File

@ -464,7 +464,7 @@ SpdyUpstream::SpdyUpstream(uint16_t version, ClientHandler *handler)
rv = spdylay_session_server_new(&session_, version, &callbacks, this);
assert(rv == 0);
uint32_t max_buffer = 65536;
uint32_t max_buffer = 64_k;
rv = spdylay_session_set_option(session_,
SPDYLAY_OPT_MAX_RECV_CTRL_FRAME_BUFFER,
&max_buffer, sizeof(max_buffer));

View File

@ -145,6 +145,18 @@ template <typename T> void dlist_delete_all(DList<T> &dl) {
}
}
constexpr unsigned long long operator"" _k(unsigned long long k) {
return k * 1024;
}
constexpr unsigned long long operator"" _m(unsigned long long m) {
return m * 1024 * 1024;
}
constexpr unsigned long long operator"" _g(unsigned long long g) {
return g * 1024 * 1024 * 1024;
}
} // namespace nghttp2
#endif // TEMPLATE_H