Skip to content

Commit 7d932bf

Browse files
committed
Updating client connection interfaces; some refactoring.
1 parent 9ad624a commit 7d932bf

File tree

4 files changed

+66
-46
lines changed

4 files changed

+66
-46
lines changed

boost/network/protocol/http/client/client_connection.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ struct client_connection {
2323
request_base const & request,
2424
bool get_body,
2525
callback_type callback) = 0;
26+
virtual client_connection * clone() const = 0;
2627
virtual void reset() = 0;
2728
virtual ~client_connection() = 0;
2829
};

boost/network/protocol/http/client/client_connection.ipp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,18 @@
88
// http://www.boost.org/LICENSE_1_0.txt)
99

1010
#include <boost/network/protocol/http/client/client_connection.hpp>
11+
#include <boost/assert.hpp>
1112

1213
namespace boost { namespace network { namespace http {
1314

1415
client_connection::~client_connection() {
15-
// default implementation, for linkage only.
16+
// For exposition only.
17+
BOOST_ASSERT(false && "This should not ever be called.");
18+
}
19+
20+
client_connection * client_connection::clone() const {
21+
// For exposition only.
22+
BOOST_ASSERT(false && "This should not ever be called.");
1623
}
1724

1825

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,22 @@ namespace boost { namespace network { namespace http {
1919

2020
struct http_async_connection_pimpl;
2121

22-
struct http_async_connection
23-
: client_connection
24-
, enable_shared_from_this<http_async_connection> {
22+
struct http_async_connection : client_connection
23+
, enable_shared_from_this<http_async_connection> {
2524
using client_connection::callback_type;
2625
http_async_connection(shared_ptr<resolver_delegate> resolver_delegate,
2726
shared_ptr<connection_delegate> connection_delegate,
2827
asio::io_service & io_service,
2928
bool follow_redirects);
29+
http_async_connection * clone() const;
3030
virtual response send_request(std::string const & method,
3131
request_base const & request,
3232
bool get_body,
3333
callback_type callback); // override
3434
virtual void reset(); // override
3535
virtual ~http_async_connection();
3636
private:
37-
scoped_ptr<http_async_connection_pimpl> pimpl;
37+
shared_ptr<http_async_connection_pimpl> pimpl;
3838
};
3939

4040
} // namespace http

boost/network/protocol/http/client/connection/async_normal.ipp

Lines changed: 53 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -14,51 +14,50 @@ namespace boost { namespace network { namespace http {
1414

1515
namespace placeholders = boost::asio::placeholders;
1616

17-
struct http_async_connection
18-
: client_connection
19-
, boost::enable_shared_from_this<http_async_connection>
17+
struct http_async_connection_pimpl : boost::enable_shared_from_this<http_async_connection_pimpl>
2018
{
19+
http_async_connection_pimpl(
20+
resolver_delegate_ptr resolver_delegate,
21+
asio::io_service & io_service,
22+
bool follow_redirect,
23+
connection_delegate_ptr delegate)
24+
:
25+
follow_redirect_(follow_redirect),
26+
request_strand_(io_service),
27+
resolver_delegate_(resolver_delegate),
28+
delegate_(delegate) {}
2129

22-
http_async_connection(resolver_delegate_ptr resolver_delegate,
23-
asio::io_service & io_service,
24-
bool follow_redirect,
25-
connection_delegate_ptr delegate)
26-
:
27-
follow_redirect_(follow_redirect),
28-
request_strand_(io_service),
29-
resolver_delegate_(resolver_delegate),
30-
delegate_(delegate) {}
31-
32-
// This is the main entry point for the connection/request pipeline. We're
33-
// overriding async_connection_base<...>::start(...) here which is called
34-
// by the client.
35-
virtual response start(request const & request,
36-
string_type const & method,
37-
bool get_body,
38-
body_callback_function_type callback) {
39-
response response_;
40-
this->init_response(response_, get_body);
41-
linearize(request, method, version_major, version_minor,
42-
std::ostreambuf_iterator<typename char_<Tag>::type>(&command_streambuf));
43-
this->method = method;
44-
boost::uint16_t port_ = port(request);
45-
resolver_delegate_->resolve(host(request),
46-
port_,
47-
request_strand_.wrap(
48-
boost::bind(
49-
&this_type::handle_resolved,
50-
this_type::shared_from_this(),
51-
port_,
52-
get_body,
53-
callback,
54-
_1,
55-
_2)));
56-
return response_;
57-
}
30+
// This is the main entry point for the connection/request pipeline. We're
31+
// overriding async_connection_base<...>::start(...) here which is called
32+
// by the client.
33+
response start(request const & request,
34+
string_type const & method,
35+
bool get_body,
36+
body_callback_function_type callback) {
37+
response response_;
38+
this->init_response(response_, get_body);
39+
linearize(request, method, version_major, version_minor,
40+
std::ostreambuf_iterator<typename char_<Tag>::type>(&command_streambuf));
41+
this->method = method;
42+
boost::uint16_t port_ = port(request);
43+
resolver_delegate_->resolve(
44+
host(request),
45+
port_,
46+
request_strand_.wrap(
47+
boost::bind(
48+
&this_type::handle_resolved,
49+
this_type::shared_from_this(),
50+
port_,
51+
get_body,
52+
callback,
53+
_1,
54+
_2)));
55+
return response_;
56+
}
5857

59-
private:
58+
private:
6059

61-
http_async_connection(http_async_connection const &); // = delete
60+
http_async_connection_pimpl(http_async_connection_pimpl const &); // = delete
6261

6362
void set_errors(boost::system::error_code const & ec) {
6463
boost::system::system_error error(ec);
@@ -385,6 +384,19 @@ private:
385384
string_type method;
386385
};
387386

387+
// END OF PIMPL DEFINITION
388+
389+
http_async_connection::http_async_connection(shared_ptr<resolver_delegate> resolver_delegate,
390+
shared_ptr<connection_delegate> connection_delegate,
391+
asio::io_service & io_service,
392+
bool follow_redirects)
393+
: pimpl(new (std::nothrow) http_async_connection_pimpl(resolver_delegate,
394+
connection_delegate,
395+
io_service,
396+
follow_redirects))
397+
{}
398+
399+
http_async_connection::http
388400

389401
} /* http */
390402

0 commit comments

Comments
 (0)