summaryrefslogtreecommitdiff
path: root/http/http_client.hpp
diff options
context:
space:
mode:
authorEd Tanous <edtanous@google.com>2022-05-31 18:59:27 +0300
committerEd Tanous <ed@tanous.net>2022-06-01 19:10:35 +0300
commit002d39b4a7a5ed7166e2acad84e0943c3def9492 (patch)
tree4307dd5161ec9779d59308a9b933e408cc2c6ca7 /http/http_client.hpp
parent62c416fb0d2f62e09d7f60754ff359ac2389e749 (diff)
downloadbmcweb-002d39b4a7a5ed7166e2acad84e0943c3def9492.tar.xz
Try to fix the lambda formatting issue
clang-tidy has a setting, LambdaBodyIndentation, which it says: "For callback-heavy code, it may improve readability to have the signature indented two levels and to use OuterScope." bmcweb is very callback heavy code. Try to enable it and see if that improves things. There are many cases where the length of a lambda call will change, and reindent the entire lambda function. This is really bad for code reviews, as it's difficult to see the lines changed. This commit should resolve it. This does have the downside of reindenting a lot of functions, which is unfortunate, but probably worth it in the long run. All changes except for the .clang-format file were made by the robot. Tested: Code compiles, whitespace changes only. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: Ib4aa2f1391fada981febd25b67dcdb9143827f43
Diffstat (limited to 'http/http_client.hpp')
-rw-r--r--http/http_client.hpp201
1 files changed, 98 insertions, 103 deletions
diff --git a/http/http_client.hpp b/http/http_client.hpp
index a6e1669240..06d4a1ca64 100644
--- a/http/http_client.hpp
+++ b/http/http_client.hpp
@@ -127,18 +127,18 @@ class ConnectionInfo : public std::enable_shared_from_this<ConnectionInfo>
const boost::beast::error_code ec,
const std::vector<boost::asio::ip::tcp::endpoint>&
endpointList) {
- if (ec || (endpointList.empty()))
- {
- BMCWEB_LOG_ERROR << "Resolve failed: " << ec.message();
- self->state = ConnState::resolveFailed;
- self->waitAndRetry();
- return;
- }
- BMCWEB_LOG_DEBUG << "Resolved " << self->host << ":"
- << std::to_string(self->port)
- << ", id: " << std::to_string(self->connId);
- self->doConnect(endpointList);
- };
+ if (ec || (endpointList.empty()))
+ {
+ BMCWEB_LOG_ERROR << "Resolve failed: " << ec.message();
+ self->state = ConnState::resolveFailed;
+ self->waitAndRetry();
+ return;
+ }
+ BMCWEB_LOG_DEBUG << "Resolved " << self->host << ":"
+ << std::to_string(self->port)
+ << ", id: " << std::to_string(self->connId);
+ self->doConnect(endpointList);
+ };
resolver.asyncResolve(host, port, std::move(respHandler));
}
@@ -153,28 +153,27 @@ class ConnectionInfo : public std::enable_shared_from_this<ConnectionInfo>
<< ", id: " << std::to_string(connId);
conn.expires_after(std::chrono::seconds(30));
- conn.async_connect(
- endpointList, [self(shared_from_this())](
- const boost::beast::error_code ec,
- const boost::asio::ip::tcp::endpoint& endpoint) {
- if (ec)
- {
- BMCWEB_LOG_ERROR << "Connect "
- << endpoint.address().to_string() << ":"
- << std::to_string(endpoint.port())
- << ", id: " << std::to_string(self->connId)
- << " failed: " << ec.message();
- self->state = ConnState::connectFailed;
- self->waitAndRetry();
- return;
- }
- BMCWEB_LOG_DEBUG
- << "Connected to: " << endpoint.address().to_string() << ":"
- << std::to_string(endpoint.port())
- << ", id: " << std::to_string(self->connId);
- self->state = ConnState::connected;
- self->sendMessage();
- });
+ conn.async_connect(endpointList,
+ [self(shared_from_this())](
+ const boost::beast::error_code ec,
+ const boost::asio::ip::tcp::endpoint& endpoint) {
+ if (ec)
+ {
+ BMCWEB_LOG_ERROR << "Connect " << endpoint.address().to_string()
+ << ":" << std::to_string(endpoint.port())
+ << ", id: " << std::to_string(self->connId)
+ << " failed: " << ec.message();
+ self->state = ConnState::connectFailed;
+ self->waitAndRetry();
+ return;
+ }
+ BMCWEB_LOG_DEBUG
+ << "Connected to: " << endpoint.address().to_string() << ":"
+ << std::to_string(endpoint.port())
+ << ", id: " << std::to_string(self->connId);
+ self->state = ConnState::connected;
+ self->sendMessage();
+ });
}
void sendMessage()
@@ -189,19 +188,18 @@ class ConnectionInfo : public std::enable_shared_from_this<ConnectionInfo>
conn, req,
[self(shared_from_this())](const boost::beast::error_code& ec,
const std::size_t& bytesTransferred) {
- if (ec)
- {
- BMCWEB_LOG_ERROR << "sendMessage() failed: "
- << ec.message();
- self->state = ConnState::sendFailed;
- self->waitAndRetry();
- return;
- }
- BMCWEB_LOG_DEBUG << "sendMessage() bytes transferred: "
- << bytesTransferred;
- boost::ignore_unused(bytesTransferred);
+ if (ec)
+ {
+ BMCWEB_LOG_ERROR << "sendMessage() failed: " << ec.message();
+ self->state = ConnState::sendFailed;
+ self->waitAndRetry();
+ return;
+ }
+ BMCWEB_LOG_DEBUG << "sendMessage() bytes transferred: "
+ << bytesTransferred;
+ boost::ignore_unused(bytesTransferred);
- self->recvMessage();
+ self->recvMessage();
});
}
@@ -217,51 +215,48 @@ class ConnectionInfo : public std::enable_shared_from_this<ConnectionInfo>
conn, buffer, *parser,
[self(shared_from_this())](const boost::beast::error_code& ec,
const std::size_t& bytesTransferred) {
- if (ec)
- {
- BMCWEB_LOG_ERROR << "recvMessage() failed: "
- << ec.message();
- self->state = ConnState::recvFailed;
- self->waitAndRetry();
- return;
- }
- BMCWEB_LOG_DEBUG << "recvMessage() bytes transferred: "
- << bytesTransferred;
- BMCWEB_LOG_DEBUG << "recvMessage() data: "
- << self->parser->get().body();
+ if (ec)
+ {
+ BMCWEB_LOG_ERROR << "recvMessage() failed: " << ec.message();
+ self->state = ConnState::recvFailed;
+ self->waitAndRetry();
+ return;
+ }
+ BMCWEB_LOG_DEBUG << "recvMessage() bytes transferred: "
+ << bytesTransferred;
+ BMCWEB_LOG_DEBUG << "recvMessage() data: "
+ << self->parser->get().body();
- unsigned int respCode = self->parser->get().result_int();
- BMCWEB_LOG_DEBUG << "recvMessage() Header Response Code: "
+ unsigned int respCode = self->parser->get().result_int();
+ BMCWEB_LOG_DEBUG << "recvMessage() Header Response Code: "
+ << respCode;
+
+ // 2XX response is considered to be successful
+ if ((respCode < 200) || (respCode >= 300))
+ {
+ // The listener failed to receive the Sent-Event
+ BMCWEB_LOG_ERROR << "recvMessage() Listener Failed to "
+ "receive Sent-Event. Header Response Code: "
<< respCode;
+ self->state = ConnState::recvFailed;
+ self->waitAndRetry();
+ return;
+ }
- // 2XX response is considered to be successful
- if ((respCode < 200) || (respCode >= 300))
- {
- // The listener failed to receive the Sent-Event
- BMCWEB_LOG_ERROR
- << "recvMessage() Listener Failed to "
- "receive Sent-Event. Header Response Code: "
- << respCode;
- self->state = ConnState::recvFailed;
- self->waitAndRetry();
- return;
- }
+ // Send is successful
+ // Reset the counter just in case this was after retrying
+ self->retryCount = 0;
+
+ // Keep the connection alive if server supports it
+ // Else close the connection
+ BMCWEB_LOG_DEBUG << "recvMessage() keepalive : "
+ << self->parser->keep_alive();
- // Send is successful
- // Reset the counter just in case this was after retrying
- self->retryCount = 0;
-
- // Keep the connection alive if server supports it
- // Else close the connection
- BMCWEB_LOG_DEBUG << "recvMessage() keepalive : "
- << self->parser->keep_alive();
-
- // Copy the response into a Response object so that it can be
- // processed by the callback function.
- self->res.clear();
- self->res.stringResponse = self->parser->release();
- self->callback(self->parser->keep_alive(), self->connId,
- self->res);
+ // Copy the response into a Response object so that it can be
+ // processed by the callback function.
+ self->res.clear();
+ self->res.stringResponse = self->parser->release();
+ self->callback(self->parser->keep_alive(), self->connId, self->res);
});
}
@@ -311,23 +306,23 @@ class ConnectionInfo : public std::enable_shared_from_this<ConnectionInfo>
timer.expires_after(retryPolicy.retryIntervalSecs);
timer.async_wait(
[self(shared_from_this())](const boost::system::error_code ec) {
- if (ec == boost::asio::error::operation_aborted)
- {
- BMCWEB_LOG_DEBUG
- << "async_wait failed since the operation is aborted"
- << ec.message();
- }
- else if (ec)
- {
- BMCWEB_LOG_ERROR << "async_wait failed: " << ec.message();
- // Ignore the error and continue the retry loop to attempt
- // sending the event as per the retry policy
- }
- self->runningTimer = false;
+ if (ec == boost::asio::error::operation_aborted)
+ {
+ BMCWEB_LOG_DEBUG
+ << "async_wait failed since the operation is aborted"
+ << ec.message();
+ }
+ else if (ec)
+ {
+ BMCWEB_LOG_ERROR << "async_wait failed: " << ec.message();
+ // Ignore the error and continue the retry loop to attempt
+ // sending the event as per the retry policy
+ }
+ self->runningTimer = false;
- // Let's close the connection and restart from resolve.
- self->doCloseAndRetry();
- });
+ // Let's close the connection and restart from resolve.
+ self->doCloseAndRetry();
+ });
}
void doClose()