0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-17 23:40:57 +01:00

ircd: Add client request timer related.

This commit is contained in:
Jason Volk 2017-09-23 19:46:17 -07:00
parent befb76a9d9
commit 7f7ef9a4bf
3 changed files with 12 additions and 7 deletions

View file

@ -56,6 +56,7 @@ struct ircd::client
unique_const_iterator<list> clit; unique_const_iterator<list> clit;
std::shared_ptr<socket> sock; std::shared_ptr<socket> sock;
ircd::timer request_timer;
bool main() noexcept; bool main() noexcept;

View file

@ -232,6 +232,7 @@ ircd::client::client(const host_port &host_port,
ircd::client::client(std::shared_ptr<socket> sock) ircd::client::client(std::shared_ptr<socket> sock)
:clit{clients, clients.emplace(end(clients), this)} :clit{clients, clients.emplace(end(clients), this)}
,sock{std::move(sock)} ,sock{std::move(sock)}
,request_timer{ircd::timer::stopped}
{ {
} }
@ -310,6 +311,7 @@ ircd::handle_request(client &client,
parse::capstan &pc) parse::capstan &pc)
try try
{ {
client.request_timer = ircd::timer{};
client.sock->set_timeout(request_timeout, [&client] client.sock->set_timeout(request_timeout, [&client]
(const error_code &ec) (const error_code &ec)
{ {
@ -331,9 +333,10 @@ try
} }
catch(const http::error &e) catch(const http::error &e)
{ {
log::debug("client[%s] HTTP %s %s", log::debug("client[%s] HTTP %s in %ld$us %s",
string(remote_addr(client)), string(remote_addr(client)),
e.what(), e.what(),
client.request_timer.at<microseconds>().count(),
e.content); e.content);
switch(e.code) switch(e.code)

View file

@ -359,13 +359,14 @@ ircd::resource::response::response(client &client,
} }
}; };
log::debug("client[%s] HTTP %d %s (%s) content-length: %zu %s...", log::debug("client[%s] HTTP %d %s in %ld$us (%s) content-length: %zu %s...",
string(remote_addr(client)), string(remote_addr(client)),
int(code), int(code),
http::reason[code], http::reason[code],
content_type, client.request_timer.at<microseconds>().count(),
str.size(), content_type,
startswith(content_type, "text") || str.size(),
content_type == "application/json" || startswith(content_type, "text") ||
content_type == "application/javascript"? str.substr(0, 96) : string_view{}); content_type == "application/json" ||
content_type == "application/javascript"? str.substr(0, 96) : string_view{});
} }