Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit21adf36

Browse files
committed
Replaced use of boost::bind with std::bind.
1 parentd81c429 commit21adf36

17 files changed

+203
-196
lines changed

‎boost/network/protocol/http/client/connection/async_normal.hpp‎

Lines changed: 86 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,11 @@
1212
#include<iterator>
1313
#include<cstdint>
1414
#include<boost/algorithm/string/trim.hpp>
15-
#include<boost/array.hpp>
1615
#include<boost/asio/deadline_timer.hpp>
1716
#include<boost/asio/placeholders.hpp>
1817
#include<boost/asio/strand.hpp>
1918
#include<boost/asio/streambuf.hpp>
2019
#include<boost/assert.hpp>
21-
#include<boost/bind/protect.hpp>
2220
#include<boost/logic/tribool.hpp>
2321
#include<boost/network/constants.hpp>
2422
#include<boost/network/detail/debug.hpp>
@@ -102,16 +100,19 @@ struct http_async_connection
102100
string_type host_ =host(request);
103101
std::uint16_t source_port = request.source_port();
104102

103+
auto self =this->shared_from_this();
105104
resolve_(resolver_, host_, port_,
106-
request_strand_.wrap(boost::bind(
107-
&this_type::handle_resolved,this_type::shared_from_this(),
108-
host_, port_, source_port, get_body, callback, generator,
109-
boost::arg<1>(), boost::arg<2>())));
105+
request_strand_.wrap(
106+
[=] (boost::system::error_codeconst &ec,
107+
resolver_iterator_pair endpoint_range) {
108+
self->handle_resolved(host_, port_, source_port, get_body,
109+
callback, generator, ec, endpoint_range);
110+
}));
110111
if (timeout_ >0) {
111112
timer_.expires_from_now(boost::posix_time::seconds(timeout_));
112-
timer_.async_wait(request_strand_.wrap(
113-
boost::bind(&this_type::handle_timeout,this_type::shared_from_this(),
114-
boost::arg<1>())));
113+
timer_.async_wait(request_strand_.wrap([=] (boost::system::error_codeconst &ec) {
114+
self->handle_timeout(ec);
115+
}));
115116
}
116117
return response_;
117118
}
@@ -145,13 +146,14 @@ struct http_async_connection
145146
// that there's still more endpoints to try connecting to.
146147
resolver_iterator iter =boost::begin(endpoint_range);
147148
asio::ip::tcp::endpointendpoint(iter->endpoint().address(), port);
149+
auto self =this->shared_from_this();
148150
delegate_->connect(
149151
endpoint, host, source_port,
150-
request_strand_.wrap(boost::bind(
151-
&this_type::handle_connected,this_type::shared_from_this(), host,
152-
port, source_port, get_body, callback, generator,
153-
std::make_pair(++iter,resolver_iterator()),
154-
placeholders::error)));
152+
request_strand_.wrap([=] (boost::system::error_codeconst &ec) {
153+
auto iter_copy = iter;
154+
self->handle_connected(host,port, source_port, get_body, callback,
155+
generator,std::make_pair(++iter_copy,resolver_iterator()), ec);
156+
}));
155157
}else {
156158
set_errors(ec ? ec : boost::asio::error::host_not_found);
157159
boost::iterator_range<constchar*> range;
@@ -169,23 +171,27 @@ struct http_async_connection
169171
set_errors(asio::error::timed_out);
170172
}elseif (!ec) {
171173
BOOST_ASSERT(delegate_.get() !=0);
174+
auto self =this->shared_from_this();
172175
delegate_->write(
173176
command_streambuf,
174-
request_strand_.wrap(boost::bind(
175-
&this_type::handle_sent_request,this_type::shared_from_this(),
176-
get_body, callback, generator, placeholders::error,
177-
placeholders::bytes_transferred)));
177+
request_strand_.wrap([=] (boost::system::error_codeconst &ec,
178+
std::size_t bytes_transferred) {
179+
self->handle_sent_request(get_body, callback, generator,
180+
ec, bytes_transferred);
181+
}));
178182
}else {
179183
if (!boost::empty(endpoint_range)) {
180184
resolver_iterator iter =boost::begin(endpoint_range);
181185
asio::ip::tcp::endpointendpoint(iter->endpoint().address(), port);
186+
auto self =this->shared_from_this();
182187
delegate_->connect(
183188
endpoint, host, source_port,
184-
request_strand_.wrap(boost::bind(
185-
&this_type::handle_connected,this_type::shared_from_this(),
186-
host, port, source_port, get_body, callback, generator,
187-
std::make_pair(++iter,resolver_iterator()),
188-
placeholders::error)));
189+
request_strand_.wrap([=] (boost::system::error_codeconst &ec) {
190+
auto iter_copy = iter;
191+
self->handle_connected(host, port, source_port, get_body, callback,
192+
generator,std::make_pair(++iter_copy,resolver_iterator()),
193+
ec);
194+
}));
189195
}else {
190196
set_errors(ec ? ec : boost::asio::error::host_not_found);
191197
boost::iterator_range<constchar*> range;
@@ -211,22 +217,27 @@ struct http_async_connection
211217
std::copy(chunk.begin(), chunk.end(),
212218
std::ostreambuf_iterator<typename char_<Tag>::type>(
213219
&command_streambuf));
220+
auto self =this->shared_from_this();
214221
delegate_->write(
215222
command_streambuf,
216-
request_strand_.wrap(boost::bind(
217-
&this_type::handle_sent_request,
218-
this_type::shared_from_this(), get_body, callback, generator,
219-
placeholders::error, placeholders::bytes_transferred)));
223+
request_strand_.wrap([=] (boost::system::error_codeconst &ec,
224+
std::size_t bytes_transferred) {
225+
self->handle_sent_request(get_body, callback, generator,
226+
ec, bytes_transferred);
227+
}));
220228
return;
221229
}
222230
}
231+
232+
auto self =this->shared_from_this();
223233
delegate_->read_some(
224234
boost::asio::mutable_buffers_1(this->part.data(),
225235
this->part.size()),
226-
request_strand_.wrap(boost::bind(
227-
&this_type::handle_received_data,this_type::shared_from_this(),
228-
version, get_body, callback, placeholders::error,
229-
placeholders::bytes_transferred)));
236+
request_strand_.wrap([=] (boost::system::error_codeconst &ec,
237+
std::size_t bytes_transferred) {
238+
self->handle_received_data(version, get_body, callback,
239+
ec, bytes_transferred);
240+
}));
230241
}else {
231242
set_errors(is_timedout_ ? asio::error::timed_out : ec);
232243
}
@@ -248,15 +259,17 @@ struct http_async_connection
248259
(!ec || ec == boost::asio::error::eof || is_ssl_short_read_error)) {
249260
logic::tribool parsed_ok;
250261
size_t remainder;
262+
auto self =this->shared_from_this();
251263
switch (state) {
252264
case version:
253265
if (ec == boost::asio::error::eof)return;
254266
parsed_ok =this->parse_version(
255267
delegate_,
256-
request_strand_.wrap(boost::bind(
257-
&this_type::handle_received_data,
258-
this_type::shared_from_this(), version, get_body, callback,
259-
placeholders::error, placeholders::bytes_transferred)),
268+
request_strand_.wrap([=] (boost::system::error_codeconst &ec,
269+
std::size_t bytes_transferred) {
270+
self->handle_received_data(version, get_body, callback,
271+
ec, bytes_transferred);
272+
}),
260273
bytes_transferred);
261274
if (!parsed_ok ||indeterminate(parsed_ok)) {
262275
return;
@@ -265,22 +278,23 @@ struct http_async_connection
265278
if (ec == boost::asio::error::eof)return;
266279
parsed_ok =this->parse_status(
267280
delegate_,
268-
request_strand_.wrap(boost::bind(
269-
&this_type::handle_received_data,
270-
this_type::shared_from_this(), status, get_body, callback,
271-
placeholders::error, placeholders::bytes_transferred)),
281+
request_strand_.wrap([=] (boost::system::error_codeconst &ec,
282+
std::size_t bytes_transferred) {
283+
self->handle_received_data(status, get_body, callback,
284+
ec, bytes_transferred);
285+
}),
272286
bytes_transferred);
273287
if (!parsed_ok ||indeterminate(parsed_ok)) {
274288
return;
275289
}
276290
case status_message:
277291
if (ec == boost::asio::error::eof)return;
278292
parsed_ok =this->parse_status_message(
279-
delegate_, request_strand_.wrap(boost::bind(
280-
&this_type::handle_received_data,
281-
this_type::shared_from_this(), status_message,
282-
get_body, callback, placeholders::error,
283-
placeholders::bytes_transferred)),
293+
delegate_, request_strand_.wrap([=] (boost::system::error_codeconst &,
294+
std::size_t bytes_transferred) {
295+
self->handle_received_data(status_message, get_body, callback,
296+
ec, bytes_transferred);
297+
}),
284298
bytes_transferred);
285299
if (!parsed_ok ||indeterminate(parsed_ok)) {
286300
return;
@@ -293,10 +307,11 @@ struct http_async_connection
293307
// to get more data for the body is scheduled.
294308
fusion::tie(parsed_ok, remainder) =this->parse_headers(
295309
delegate_,
296-
request_strand_.wrap(boost::bind(
297-
&this_type::handle_received_data,
298-
this_type::shared_from_this(), headers, get_body, callback,
299-
placeholders::error, placeholders::bytes_transferred)),
310+
request_strand_.wrap([=] (boost::system::error_codeconst &ec,
311+
std::size_t bytes_transferred) {
312+
self->handle_received_data(headers, get_body, callback,
313+
ec, bytes_transferred);
314+
}),
300315
bytes_transferred);
301316

302317
if (!parsed_ok ||indeterminate(parsed_ok)) {
@@ -335,22 +350,26 @@ struct http_async_connection
335350
// wait before scheduling another read.
336351
callback(make_iterator_range(begin, end), ec);
337352

353+
auto self =this->shared_from_this();
338354
delegate_->read_some(
339355
boost::asio::mutable_buffers_1(this->part.data(),
340356
this->part.size()),
341-
request_strand_.wrap(boost::bind(
342-
&this_type::handle_received_data,
343-
this_type::shared_from_this(), body, get_body, callback,
344-
placeholders::error, placeholders::bytes_transferred)));
357+
request_strand_.wrap([=] (boost::system::error_codeconst &ec,
358+
std::size_t bytes_transferred) {
359+
self->handle_received_data(body, get_body, callback,
360+
ec, bytes_transferred);
361+
}));
345362
}else {
346363
// Here we handle the body data ourself and append to an
347364
// ever-growing string buffer.
365+
auto self =this->shared_from_this();
348366
this->parse_body(
349367
delegate_,
350-
request_strand_.wrap(boost::bind(
351-
&this_type::handle_received_data,
352-
this_type::shared_from_this(), body, get_body, callback,
353-
placeholders::error, placeholders::bytes_transferred)),
368+
request_strand_.wrap([=] (boost::system::error_codeconst &ec,
369+
std::size_t bytes_transferred) {
370+
self->handle_received_data(body, get_body, callback,
371+
ec, bytes_transferred);
372+
}),
354373
remainder);
355374
}
356375
return;
@@ -399,23 +418,26 @@ struct http_async_connection
399418
typename protocol_base::buffer_type::const_iterator end = begin;
400419
std::advance(end, bytes_transferred);
401420
callback(make_iterator_range(begin, end), ec);
421+
auto self =this->shared_from_this();
402422
delegate_->read_some(
403423
boost::asio::mutable_buffers_1(this->part.data(),
404424
this->part.size()),
405-
request_strand_.wrap(boost::bind(
406-
&this_type::handle_received_data,
407-
this_type::shared_from_this(), body, get_body, callback,
408-
placeholders::error, placeholders::bytes_transferred)));
425+
request_strand_.wrap([=] (boost::system::error_codeconst &ec,
426+
std::size_t bytes_transferred) {
427+
self->handle_received_data(body, get_body, callback,
428+
ec, bytes_transferred);
429+
}));
409430
}else {
410431
// Here we don't have a body callback. Let's make sure that we
411432
// deal with the remainder from the headers part in case we do
412433
// have data that's still in the buffer.
413434
this->parse_body(
414435
delegate_,
415-
request_strand_.wrap(boost::bind(
416-
&this_type::handle_received_data,
417-
this_type::shared_from_this(), body, get_body, callback,
418-
placeholders::error, placeholders::bytes_transferred)),
436+
request_strand_.wrap([=] (boost::system::error_codeconst &ec,
437+
std::size_t bytes_transferred) {
438+
self->handle_received_data(body, get_body, callback,
439+
ec, bytes_transferred);
440+
}),
419441
bytes_transferred);
420442
}
421443
}

‎boost/network/protocol/http/client/connection/ssl_delegate.ipp‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
#include<cstdint>
1111
#include<boost/asio/ssl.hpp>
12-
#include<boost/bind.hpp>
1312
#include<boost/network/protocol/http/client/connection/ssl_delegate.hpp>
1413

1514
boost::network::http::impl::ssl_delegate::ssl_delegate(
@@ -71,12 +70,12 @@ void boost::network::http::impl::ssl_delegate::connect(
7170

7271
if (always_verify_peer_)
7372
socket_->set_verify_callback(boost::asio::ssl::rfc2818_verification(host));
73+
auto self =this->shared_from_this();
7474
socket_->lowest_layer().async_connect(
7575
endpoint,
76-
::boost::bind(
77-
&boost::network::http::impl::ssl_delegate::handle_connected,
78-
boost::network::http::impl::ssl_delegate::shared_from_this(),
79-
asio::placeholders::error, handler));
76+
[=] (boost::system::error_codeconst &ec) {
77+
self->handle_connected(ec, handler);
78+
});
8079
}
8180

8281
voidboost::network::http::impl::ssl_delegate::handle_connected(

‎boost/network/protocol/http/client/connection/sync_normal.hpp‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,10 @@ struct http_sync_connection
7777
}
7878
if (timeout_ >0) {
7979
timer_.expires_from_now(boost::posix_time::seconds(timeout_));
80-
timer_.async_wait(boost::bind(&this_type::handle_timeout,
81-
this_type::shared_from_this(),
82-
boost::arg<1>()));
80+
auto self =this->shared_from_this();
81+
timer_.async_wait([=] (boost::system::error_codeconst &ec) {
82+
self->handle_timeout(ec);
83+
});
8384
}
8485
}
8586

‎boost/network/protocol/http/client/connection/sync_ssl.hpp‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#include<boost/asio/streambuf.hpp>
1515
#include<boost/function.hpp>
1616
#include<boost/algorithm/string/predicate.hpp>
17-
#include<boost/bind.hpp>
1817
#include<boost/network/protocol/http/request.hpp>
1918
#include<boost/network/protocol/http/traits/resolver_policy.hpp>
2019

@@ -120,9 +119,10 @@ struct https_sync_connection
120119
}
121120
if (timeout_ >0) {
122121
timer_.expires_from_now(boost::posix_time::seconds(timeout_));
123-
timer_.async_wait(boost::bind(&this_type::handle_timeout,
124-
this_type::shared_from_this(),
125-
boost::arg<1>()));
122+
auto self =this->shared_from_this();
123+
timer_.async_wait([=] (boost::system::error_codeconst &ec) {
124+
self->handle_timeout(ec);
125+
});
126126
}
127127
}
128128

‎boost/network/protocol/http/policies/async_connection.hpp‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@
1010
// http://www.boost.org/LICENSE_1_0.txt)
1111

1212
#include<memory>
13+
#include<functional>
1314
#include<boost/algorithm/string/predicate.hpp>
14-
#include<boost/bind.hpp>
15-
#include<boost/function.hpp>
1615
#include<boost/network/protocol/http/client/connection/async_base.hpp>
1716
#include<boost/network/protocol/http/message/wrappers/protocol.hpp>
1817
#include<boost/network/protocol/http/traits/resolver_policy.hpp>
@@ -77,12 +76,11 @@ struct async_connection_policy : resolver_policy<Tag>::type {
7776
optional<string_type>const& ciphers = optional<string_type>(),
7877
long ssl_options = 0) {
7978
string_type protocol_ =protocol(request_);
79+
namespaceph= std::placeholders;
8080
connection_ptrconnection_(newconnection_impl(
8181
follow_redirect_, always_verify_peer,
82-
boost::bind(&async_connection_policy<Tag, version_major,
83-
version_minor>::resolve,
84-
this, boost::arg<1>(), boost::arg<2>(), boost::arg<3>(),
85-
boost::arg<4>()),
82+
std::bind(&async_connection_policy<Tag, version_major,
83+
version_minor>::resolve,this, ph::_1, ph::_2, ph::_3, ph::_4),
8684
resolver,boost::iequals(protocol_,string_type("https")), timeout_,
8785
certificate_filename, verify_path, certificate_file, private_key_file,
8886
ciphers, ssl_options));

‎boost/network/protocol/http/policies/async_resolver.hpp‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#include<boost/function.hpp>
1717
#include<boost/algorithm/string/case_conv.hpp>
1818
#include<boost/fusion/tuple/tuple_tie.hpp>
19-
#include<boost/bind/bind.hpp>
2019

2120
namespaceboost {
2221
namespacenetwork {
@@ -63,12 +62,13 @@ struct async_resolver : std::enable_shared_from_this<async_resolver<Tag> > {
6362

6463
typename resolver_type::queryq(host,
6564
std::to_string(port));
66-
resolver_.async_resolve(q, resolver_strand_->wrap(boost::bind(
67-
&async_resolver<Tag>::handle_resolve,
68-
async_resolver<Tag>::shared_from_this(),
69-
boost::to_lower_copy(host), once_resolved,
70-
boost::asio::placeholders::error,
71-
boost::asio::placeholders::iterator)));
65+
auto self =this->shared_from_this();
66+
resolver_.async_resolve(q, resolver_strand_->wrap([=] (boost::system::error_codeconst &ec,
67+
resolver_iterator endpoint_iterator) {
68+
self->handle_resolve(boost::to_lower_copy(host),
69+
once_resolved,
70+
ec, endpoint_iterator);
71+
}));
7272
}
7373

7474
voidhandle_resolve(string_type/*unused*/const &host,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp