-
Notifications
You must be signed in to change notification settings - Fork 764
remove unused captures in lambdas #120
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -217,7 +217,8 @@ namespace SimpleWeb { | |
|
||
///Use this function if you need to recursively send parts of a longer message | ||
void send(const std::shared_ptr<Response> &response, const std::function<void(const boost::system::error_code&)>& callback=nullptr) const { | ||
boost::asio::async_write(*response->socket, response->streambuf, [this, response, callback](const boost::system::error_code& ec, size_t /*bytes_transferred*/) { | ||
boost::asio::async_write(*response->socket, response->streambuf, [response, callback](const boost::system::error_code& ec, size_t /*bytes_transferred*/) { | ||
(void) response; // response is not used here, but needs to captured to keep it alive because async_write is using response->*-fields | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would like not to have this line here. I think there is a comment somewhere that explains this, but not sure if this needs to be explained for every async call, as its already stated in the Boost.Asio reference. The reason response is captured is that its streambuf object (and the socket of course) needs to be kept alive. Sorry for my bad explanation above. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it only the comment which disturbs you or also the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mostly it's the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not having the
( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That is a good argument actually, but not sure if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See for instance http://www.boost.org/doc/libs/1_63_0/doc/html/boost_asio/example/cpp11/echo/async_tcp_echo_server.cpp. Compiling this example would also result in the same warnings with |
||
if(callback) | ||
callback(ec); | ||
}); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
response
is needed here to keep the object alive untilasync_write
is finished.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That sounds error-prone.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but it has to be done somewhere since Boost.Asio is still quite low-level and does not support smart pointer parameters.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated my pull-request. (added a comment, see below)