@@ -35,7 +35,8 @@ struct pooled_connection_policy : resolver_policy<Tag>::type {
35
35
resolver_type&, string_type const &, string_type const &)>
36
36
resolver_function_type;
37
37
typedef std::function<void (iterator_range<char const *> const &,
38
- std::error_code const &)> body_callback_function_type;
38
+ std::error_code const &)>
39
+ body_callback_function_type;
39
40
typedef std::function<bool (string_type&)> body_generator_function_type;
40
41
41
42
void cleanup () { host_connection_map ().swap (host_connections_); }
@@ -103,8 +104,7 @@ struct pooled_connection_policy : resolver_policy<Tag>::type {
103
104
basic_response<Tag> response_;
104
105
// check if the socket is open first
105
106
if (!pimpl->is_open ()) {
106
- pimpl->init_socket (request_.host (),
107
- std::to_string (request_.port ()));
107
+ pimpl->init_socket (request_.host (), std::to_string (request_.port ()));
108
108
}
109
109
response_ = basic_response<Tag>();
110
110
response_ << ::boost::network::source (request_.host ());
@@ -132,7 +132,7 @@ struct pooled_connection_policy : resolver_policy<Tag>::type {
132
132
pimpl->read_body (response_, response_buffer);
133
133
}
134
134
135
- typename headers_range<basic_response<Tag> >::type connection_range =
135
+ typename headers_range<basic_response<Tag>>::type connection_range =
136
136
headers (response_)[" Connection" ];
137
137
if (version_major == 1 && version_minor == 1 &&
138
138
!boost::empty (connection_range) &&
@@ -145,10 +145,10 @@ struct pooled_connection_policy : resolver_policy<Tag>::type {
145
145
if (connection_follow_redirect_) {
146
146
std::uint16_t status = response_.status ();
147
147
if (status >= 300 && status <= 307 ) {
148
- typename headers_range<basic_response<Tag> >::type location_range =
148
+ typename headers_range<basic_response<Tag>>::type location_range =
149
149
headers (response_)[" Location" ];
150
150
typename range_iterator<
151
- typename headers_range<basic_request<Tag> >::type>::type
151
+ typename headers_range<basic_request<Tag>>::type>::type
152
152
location_header = std::begin (location_range);
153
153
if (location_header != std::end (location_range)) {
154
154
request_.uri (location_header->second );
@@ -168,7 +168,7 @@ struct pooled_connection_policy : resolver_policy<Tag>::type {
168
168
}
169
169
170
170
std::shared_ptr<http::impl::sync_connection_base<Tag, version_major,
171
- version_minor> > pimpl;
171
+ version_minor>> pimpl;
172
172
resolver_type& resolver_;
173
173
bool connection_follow_redirect_;
174
174
get_connection_function get_connection_;
@@ -182,7 +182,8 @@ struct pooled_connection_policy : resolver_policy<Tag>::type {
182
182
183
183
typedef std::shared_ptr<connection_impl> connection_ptr;
184
184
185
- typedef std::unordered_map<string_type, std::weak_ptr<connection_impl>> host_connection_map;
185
+ typedef std::unordered_map<string_type, std::weak_ptr<connection_impl>>
186
+ host_connection_map;
186
187
std::mutex host_mutex_;
187
188
host_connection_map host_connections_;
188
189
bool follow_redirect_;
@@ -198,7 +199,7 @@ struct pooled_connection_policy : resolver_policy<Tag>::type {
198
199
optional<string_type> const & private_key_file = optional<string_type>(),
199
200
optional<string_type> const & ciphers = optional<string_type>()) {
200
201
string_type index =
201
- (request_.host () + ' :' ) + std::to_string (request_.port ());
202
+ (request_.host () + ' :' ) + std::to_string (request_.port ());
202
203
std::unique_lock<std::mutex> lock (host_mutex_);
203
204
auto it = host_connections_.find (index );
204
205
if (it != host_connections_.end ()) {
@@ -209,19 +210,30 @@ struct pooled_connection_policy : resolver_policy<Tag>::type {
209
210
}
210
211
211
212
namespace ph = std::placeholders;
212
- connection_ptr connection ( new connection_impl (
213
+ auto connection = std::make_shared< connection_impl> (
213
214
resolver, follow_redirect_, request_.host (),
214
215
std::to_string (request_.port ()),
215
216
// resolver function
216
- std::bind (&pooled_connection_policy<Tag, version_major,
217
- version_minor>::resolve, this , ph::_1, ph::_2, ph::_3),
217
+ [this ](
218
+ resolver_type& resolver, string_type const & host,
219
+ std::uint16_t port,
220
+ typename resolver_type::resolve_completion_function once_resolved) {
221
+ this ->resolve (resolver, host, port, once_resolved);
222
+ },
218
223
// connection factory
219
- std::bind (&pooled_connection_policy<Tag, version_major,
220
- version_minor>::get_connection,
221
- this , ph::_1, ph::_2, always_verify_peer, ph::_3, ph::_4, ph::_5, ph::_6, ph::_7),
224
+ [this , always_verify_peer](
225
+ resolver_type& resolver, basic_request<Tag> const & request, bool ,
226
+ optional<string_type> const & certificate_filename,
227
+ optional<string_type> const & verify_path,
228
+ optional<string_type> const & private_key_file,
229
+ optional<string_type> const & ciphers) {
230
+ return this ->get_connection (resolver, request, always_verify_peer,
231
+ certificate_filename, verify_path,
232
+ private_key_file, ciphers);
233
+ },
222
234
boost::iequals (request_.protocol (), string_type (" https" )),
223
235
always_verify_peer, timeout_, certificate_filename, verify_path,
224
- certificate_file, private_key_file, ciphers, 0 )) ;
236
+ certificate_file, private_key_file, ciphers, 0 );
225
237
host_connections_.insert (std::make_pair (index , connection));
226
238
return connection;
227
239
}
0 commit comments