From 0f0f6fdf8e2775259ff5ce74864a184ac7cb3234 Mon Sep 17 00:00:00 2001 From: Chunting Gu Date: Fri, 26 Jul 2019 09:59:24 +0800 Subject: [PATCH] Add parameters like timeout, buffer_size to ClientSession. --- webcc/client_session.cc | 6 ++++++ webcc/client_session.h | 27 +++++++++++++-------------- webcc/connection.cc | 2 +- 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/webcc/client_session.cc b/webcc/client_session.cc index 059a48d..09b704a 100644 --- a/webcc/client_session.cc +++ b/webcc/client_session.cc @@ -7,6 +7,12 @@ namespace webcc { +ClientSession::ClientSession(int timeout, bool ssl_verify, + std::size_t buffer_size) + : timeout_(timeout), ssl_verify_(ssl_verify), buffer_size_(buffer_size) { + InitHeaders(); +} + void ClientSession::Auth(const std::string& type, const std::string& credentials) { headers_.Set(headers::kAuthorization, type + " " + credentials); diff --git a/webcc/client_session.h b/webcc/client_session.h index af76bc2..3ada4ef 100644 --- a/webcc/client_session.h +++ b/webcc/client_session.h @@ -15,12 +15,17 @@ namespace webcc { // session for each thread instead. class ClientSession { public: - ClientSession() { - InitHeaders(); - } + explicit ClientSession(int timeout = 0, bool ssl_verify = true, + std::size_t buffer_size = 0); ~ClientSession() = default; + void set_timeout(int timeout) { + if (timeout > 0) { + timeout_ = timeout; + } + } + void set_ssl_verify(bool ssl_verify) { ssl_verify_ = ssl_verify; } @@ -29,12 +34,6 @@ public: buffer_size_ = buffer_size; } - void set_timeout(int timeout) { - if (timeout > 0) { - timeout_ = timeout; - } - } - void SetHeader(const std::string& key, const std::string& value) { headers_.Set(key, value); } @@ -100,15 +99,15 @@ private: // Additional headers for each request. Headers headers_; + // Timeout in seconds for receiving response. + int timeout_; + // Verify the certificate of the peer or not. - bool ssl_verify_ = true; + bool ssl_verify_; // The size of the buffer for reading response. // 0 means default value will be used. - std::size_t buffer_size_ = 0; - - // Timeout in seconds for receiving response. - int timeout_ = 0; + std::size_t buffer_size_; // Pool for Keep-Alive client connections. ClientPool pool_; diff --git a/webcc/connection.cc b/webcc/connection.cc index 5f48170..d378514 100644 --- a/webcc/connection.cc +++ b/webcc/connection.cc @@ -87,7 +87,7 @@ void Connection::DoRead() { void Connection::OnRead(boost::system::error_code ec, std::size_t length) { if (ec) { if (ec == boost::asio::error::eof) { - LOG_WARN("Socket read EOF (%s).", ec.message().c_str()); + LOG_INFO("Socket read EOF (%s).", ec.message().c_str()); } else if (ec == boost::asio::error::operation_aborted) { // The socket of this connection has been closed. // This happens, e.g., when the server was stopped by a signal (Ctrl-C).