From 74bb040b8c7f1dd9c5011c026684d187ae921626 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Sat, 25 Aug 2018 13:58:19 -0700 Subject: [PATCH] ircd::resource: Make response head buffer size a named const; fix comment. --- include/ircd/resource.h | 2 ++ ircd/resource.cc | 14 ++++++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/include/ircd/resource.h b/include/ircd/resource.h index d83bbf5a8..2b6b50e75 100644 --- a/include/ircd/resource.h +++ b/include/ircd/resource.h @@ -143,6 +143,8 @@ struct ircd::resource::response { struct chunked; + static const size_t HEAD_BUF_SZ; + response(client &, const http::code &, const string_view &content_type, const size_t &content_length, const string_view &headers = {}); response(client &, const string_view &str, const string_view &content_type, const http::code &, const vector_view &); response(client &, const string_view &str, const string_view &content_type, const http::code & = http::OK, const string_view &headers = {}); diff --git a/ircd/resource.cc b/ircd/resource.cc index 82a8606c2..6b536e6f7 100644 --- a/ircd/resource.cc +++ b/ircd/resource.cc @@ -740,6 +740,14 @@ catch(...) // resource::response // +// A buffer of this size will be passed to the socket and sent +// out and must be on stack. +decltype(ircd::resource::response::HEAD_BUF_SZ) +ircd::resource::response::HEAD_BUF_SZ +{ + 4_KiB +}; + ircd::resource::response::response(client &client, const http::code &code) :response{client, json::object{json::empty_object}, code} @@ -960,9 +968,7 @@ ircd::resource::response::response(client &client, "%zd$us", request_time }; - // This buffer will be passed to the socket and sent out; - // cannot be static/tls. - char head_buf[4_KiB]; + char head_buf[HEAD_BUF_SZ]; window_buffer head{head_buf}; http::response { @@ -977,7 +983,7 @@ ircd::resource::response::response(client &client, }, }; - // Maximum size is is realistically ok but ideally a small + // Maximum size is realistically ok but ideally a small // maximum; this exception should hit the developer in testing. if(unlikely(!head.remaining())) throw assertive