Skip to content

Commit 335dd84

Browse files
committed
WIP: Tons of logging, improving build times.
I've reorganized a few things trying to hunt down why certain things aren't happening as expected. I'm committing so that I can try and merge from cpp-netlib/cpp-netlib:master to catch what Glyn has pushed with the URI implementation. There's a few issues with trying to get the host and other parts of the message through the wrappers and I'm trying a merge to figure out if this has been fixed.
1 parent fcf4888 commit 335dd84

33 files changed

+270
-114
lines changed

boost/network/include/http/client.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@
99
// This is the modular include file for using the HTTP Client
1010

1111
#include <boost/network/protocol/http/client.hpp>
12+
#include <boost/network/message/wrappers.hpp>
13+
#include <boost/network/protocol/http/message/directives.hpp>
14+
#include <boost/network/protocol/http/message/modifiers.hpp>
15+
#include <boost/network/protocol/http/message/wrappers.hpp>
16+
#include <boost/network/message/directives.hpp>
17+
#include <boost/network/message/transformers.hpp>
1218

1319
#endif // BOOST_NETWORK_INCLUDE_HTTP_CLIENT_HPP_
1420

boost/network/protocol/http/client.ipp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,20 @@
99

1010
#include <boost/network/protocol/http/client.hpp>
1111
#include <boost/network/protocol/http/client/options.hpp>
12+
#include <boost/network/detail/debug.hpp>
1213

1314
namespace boost { namespace network { namespace http {
1415

1516
client::client()
16-
: base_facade_type()
17-
{}
17+
: base_facade_type() {
18+
BOOST_NETWORK_MESSAGE("client::client()");
19+
}
1820

1921
client::client(client_options const &options)
2022
: base_facade_type(options)
21-
{}
23+
{
24+
BOOST_NETWORK_MESSAGE("client::client(client_options const &)");
25+
}
2226

2327
} // namespace http
2428
} // namespace network

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

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <boost/network/protocol/http/client/connection_manager.hpp>
1717
#include <boost/network/protocol/http/client/simple_connection_manager.hpp>
1818
#include <boost/network/protocol/http/request.hpp>
19+
#include <boost/network/detail/debug.hpp>
1920

2021
namespace boost { namespace network { namespace http {
2122

@@ -41,12 +42,14 @@ struct client_base_pimpl {
4142
};
4243

4344
client_base::client_base()
44-
: pimpl(new (std::nothrow) client_base_pimpl(client_options()))
45-
{}
45+
: pimpl(new (std::nothrow) client_base_pimpl(client_options())) {
46+
BOOST_NETWORK_MESSAGE("client_base::client_base()");
47+
}
4648

4749
client_base::client_base(client_options const &options)
48-
: pimpl(new (std::nothrow) client_base_pimpl(options))
49-
{}
50+
: pimpl(new (std::nothrow) client_base_pimpl(options)) {
51+
BOOST_NETWORK_MESSAGE("client_base::client_base(client_options const &)");
52+
}
5053

5154
void client_base::clear_resolved_cache() {
5255
pimpl->clear_resolved_cache();
@@ -57,10 +60,12 @@ response const client_base::request_skeleton(request const & request_,
5760
bool get_body,
5861
body_callback_function_type callback,
5962
request_options const &options) {
63+
BOOST_NETWORK_MESSAGE("client_base::request_skeleton(...)");
6064
return pimpl->request_skeleton(request_, method, get_body, callback, options);
6165
}
6266

6367
client_base::~client_base() {
68+
BOOST_NETWORK_MESSAGE("client_base::~client_base()");
6469
delete pimpl;
6570
}
6671

@@ -70,13 +75,17 @@ client_base_pimpl::client_base_pimpl(client_options const &options)
7075
sentinel_(),
7176
connection_manager_(options.connection_manager()),
7277
owned_service_(false) {
78+
BOOST_NETWORK_MESSAGE("client_base_pimpl::client_base_pimpl(client_options const &)");
7379
if (service_ptr == 0) {
80+
BOOST_NETWORK_MESSAGE("creating owned io_service.");
7481
service_ptr = new(std::nothrow) asio::io_service;
7582
owned_service_ = true;
7683
}
77-
if (!connection_manager_.get())
84+
if (!connection_manager_.get()) {
85+
BOOST_NETWORK_MESSAGE("creating owned simple_connection_manager");
7886
connection_manager_.reset(
7987
new (std::nothrow) simple_connection_manager(options));
88+
}
8089
sentinel_.reset(new (std::nothrow) boost::asio::io_service::work(*service_ptr));
8190
lifetime_thread_.reset(new (std::nothrow) boost::thread(
8291
boost::bind(
@@ -89,6 +98,7 @@ client_base_pimpl::client_base_pimpl(client_options const &options)
8998

9099
client_base_pimpl::~client_base_pimpl()
91100
{
101+
BOOST_NETWORK_MESSAGE("client_base_pimpl::~client_base_pimpl()");
92102
sentinel_.reset();
93103
connection_manager_->reset();
94104
if (lifetime_thread_.get()) {
@@ -106,12 +116,14 @@ response const client_base_pimpl::request_skeleton(
106116
request_options const &options
107117
)
108118
{
119+
BOOST_NETWORK_MESSAGE("client_base_pimpl::request_skeleton(...)");
109120
shared_ptr<client_connection> connection_;
110121
connection_ = connection_manager_->get_connection(*service_ptr, request_, options_);
111122
return connection_->send_request(method, request_, get_body, callback, options);
112123
}
113124

114125
void client_base_pimpl::clear_resolved_cache() {
126+
BOOST_NETWORK_MESSAGE("client_base_pimpl::clear_resolved_cache()");
115127
connection_manager_->clear_resolved_cache();
116128
}
117129

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@
1010
#include <boost/function.hpp>
1111
#include <boost/range/iterator_range.hpp>
1212
#include <boost/system/error_code.hpp>
13-
#include <boost/network/protocol/http/request.hpp>
14-
#include <boost/network/protocol/http/response.hpp>
1513

1614
namespace boost { namespace network { namespace http {
1715

16+
struct request;
17+
struct response;
18+
1819
class request_options;
1920

2021
struct client_connection {

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,17 @@
99

1010
#include <boost/network/protocol/http/client/client_connection.hpp>
1111
#include <boost/assert.hpp>
12+
#include <boost/network/detail/debug.hpp>
1213

1314
namespace boost { namespace network { namespace http {
1415

1516
client_connection::~client_connection() {
17+
BOOST_NETWORK_MESSAGE("client_connection::~client_connection()");
1618
// Do nothing here.
1719
}
1820

1921
client_connection * client_connection::clone() const {
22+
BOOST_NETWORK_MESSAGE("client_connection::clone()");
2023
// For exposition only.
2124
BOOST_ASSERT(false && "This should not ever be called.");
2225
}

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

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ struct http_async_connection_pimpl : boost::enable_shared_from_this<http_async_c
3535
follow_redirect_(follow_redirect),
3636
request_strand_(io_service),
3737
resolver_delegate_(resolver_delegate),
38-
connection_delegate_(connection_delegate) {}
38+
connection_delegate_(connection_delegate) {
39+
BOOST_NETWORK_MESSAGE("http_async_connection_pimpl::http_async_connection_pimpl(...)");
40+
}
3941

4042
// This is the main entry point for the connection/request pipeline. We're
4143
// overriding async_connection_base<...>::start(...) here which is called
@@ -45,15 +47,25 @@ struct http_async_connection_pimpl : boost::enable_shared_from_this<http_async_c
4547
bool get_body,
4648
body_callback_function_type callback,
4749
request_options const &options) {
50+
BOOST_NETWORK_MESSAGE("http_async_connection_pimpl::start(...)");
4851
response response_;
4952
this->init_response(response_);
5053
// Use HTTP/1.1 -- at some point we might want to implement a different
5154
// connection type just for HTTP/1.0.
5255
// TODO: Implement a different connection type and factory for HTTP/1.0.
5356
linearize(request, method, 1, 1,
5457
std::ostreambuf_iterator<char>(&command_streambuf));
58+
#ifdef BOOST_NETWORK_DEBUG
59+
{
60+
std::ostringstream linearized;
61+
linearized << &command_streambuf;
62+
BOOST_NETWORK_MESSAGE("linearized request: ['" << linearized.str() << "']");
63+
}
64+
#endif
5565
this->method = method;
66+
BOOST_NETWORK_MESSAGE("method: " << this->method);
5667
boost::uint16_t port_ = port(request);
68+
BOOST_NETWORK_MESSAGE("port: " << port_);
5769
resolver_delegate_->resolve(
5870
host(request),
5971
port_,
@@ -70,6 +82,7 @@ struct http_async_connection_pimpl : boost::enable_shared_from_this<http_async_c
7082
}
7183

7284
http_async_connection_pimpl * clone() {
85+
BOOST_NETWORK_MESSAGE("http_async_connection_pimpl::clone()");
7386
return new (std::nothrow) http_async_connection_pimpl(
7487
this->resolver_delegate_,
7588
this->connection_delegate_,
@@ -86,16 +99,20 @@ struct http_async_connection_pimpl : boost::enable_shared_from_this<http_async_c
8699
http_async_connection_pimpl(http_async_connection_pimpl const &); // = delete
87100

88101
void init_response(response &r) {
102+
BOOST_NETWORK_MESSAGE("http_async_connection_pimpl::init_response(...)");
89103
impl::setter_access accessor;
90104
accessor.set_source_promise(r, this->source_promise);
91105
accessor.set_destination_promise(r, this->destination_promise);
92106
accessor.set_headers_promise(r, this->headers_promise);
93107
accessor.set_body_promise(r, this->body_promise);
94108
accessor.set_version_promise(r, this->version_promise);
95109
accessor.set_status_message_promise(r, this->status_message_promise);
110+
BOOST_NETWORK_MESSAGE("futures and promises lined up.");
96111
}
97112

98113
void set_errors(boost::system::error_code const & ec) {
114+
BOOST_NETWORK_MESSAGE("http_async_connection_pimpl::set_errors(...)");
115+
BOOST_NETWORK_MESSAGE("error: " << ec);
99116
boost::system::system_error error(ec);
100117
this->version_promise.set_exception(boost::copy_exception(error));
101118
this->status_promise.set_exception(boost::copy_exception(error));
@@ -104,17 +121,21 @@ struct http_async_connection_pimpl : boost::enable_shared_from_this<http_async_c
104121
this->source_promise.set_exception(boost::copy_exception(error));
105122
this->destination_promise.set_exception(boost::copy_exception(error));
106123
this->body_promise.set_exception(boost::copy_exception(error));
124+
BOOST_NETWORK_MESSAGE("promise+future exceptions set.");
107125
}
108126

109127
void handle_resolved(boost::uint16_t port,
110128
bool get_body,
111129
body_callback_function_type callback,
112130
boost::system::error_code const & ec,
113131
resolver_iterator_pair endpoint_range) {
132+
BOOST_NETWORK_MESSAGE("http_async_connection_pimpl::handle_resolved(...)");
114133
if (!ec && !boost::empty(endpoint_range)) {
115-
// Here we deal with the case that there was an error encountered and
116-
// that there's still more endpoints to try connecting to.
134+
// Here we deal with the case that there was no error encountered.
135+
BOOST_NETWORK_MESSAGE("resolved endpoint successfully");
117136
resolver_iterator iter = boost::begin(endpoint_range);
137+
BOOST_NETWORK_MESSAGE("trying connection to: "
138+
<< iter->endpoint().address() << ":" << port);
118139
asio::ip::tcp::endpoint endpoint(iter->endpoint().address(), port);
119140
connection_delegate_->connect(endpoint,
120141
request_strand_.wrap(
@@ -128,6 +149,7 @@ struct http_async_connection_pimpl : boost::enable_shared_from_this<http_async_c
128149
resolver_iterator()),
129150
placeholders::error)));
130151
} else {
152+
BOOST_NETWORK_MESSAGE("error encountered while resolving.");
131153
set_errors(ec ? ec : boost::asio::error::host_not_found);
132154
}
133155
}
@@ -137,7 +159,9 @@ struct http_async_connection_pimpl : boost::enable_shared_from_this<http_async_c
137159
body_callback_function_type callback,
138160
resolver_iterator_pair endpoint_range,
139161
boost::system::error_code const & ec) {
162+
BOOST_NETWORK_MESSAGE("http_async_connection_pimpl::handle_connected(...)");
140163
if (!ec) {
164+
BOOST_NETWORK_MESSAGE("connected successfully");
141165
BOOST_ASSERT(connection_delegate_.get() != 0);
142166
connection_delegate_->write(command_streambuf,
143167
request_strand_.wrap(
@@ -149,8 +173,10 @@ struct http_async_connection_pimpl : boost::enable_shared_from_this<http_async_c
149173
placeholders::error,
150174
placeholders::bytes_transferred)));
151175
} else {
176+
BOOST_NETWORK_MESSAGE("connection unsuccessful");
152177
if (!boost::empty(endpoint_range)) {
153178
resolver_iterator iter = boost::begin(endpoint_range);
179+
BOOST_NETWORK_MESSAGE("trying: " << iter->endpoint().address() << ":" << port);
154180
asio::ip::tcp::endpoint endpoint(iter->endpoint().address(), port);
155181
connection_delegate_->connect(endpoint,
156182
request_strand_.wrap(

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,4 @@ struct connection_delegate_factory {
3636
} /* network */
3737
} /* boost */
3838

39-
#ifdef BOOST_NETWORK_NO_LIB
40-
#include <boost/network/protocol/http/client/connection/connection_delegate_factory.ipp>
41-
#endif
42-
4339
#endif /* BOOST_NETWORK_PROTOCOL_HTTP_CLIENT_CONNECTION_DELEGATE_FACTORY_HPP_20110819 */

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,31 +14,40 @@
1414

1515
#include <boost/network/protocol/http/client/connection/connection_delegate_factory.hpp>
1616
#include <boost/network/protocol/http/client/options.hpp>
17+
#include <boost/network/detail/debug.hpp>
1718

1819
namespace boost { namespace network { namespace http {
1920

20-
connection_delegate_factory::connection_delegate_factory() {}
21+
connection_delegate_factory::connection_delegate_factory() {
22+
BOOST_NETWORK_MESSAGE("connection_delegate_factory::connection_delegate_factory()");
23+
}
2124

2225
connection_delegate_factory::connection_delegate_ptr
2326
connection_delegate_factory::create_connection_delegate(
2427
asio::io_service & service,
2528
bool https,
2629
client_options const &options) {
30+
BOOST_NETWORK_MESSAGE("connection_delegate_factory::create_connection_delegate(...)");
2731
connection_delegate_ptr delegate;
2832
if (https) {
2933
#ifdef BOOST_NETWORK_ENABLE_HTTPS
34+
BOOST_NETWORK_MESSAGE("creating an SSL delegate");
3035
delegate.reset(new ssl_delegate(service,
3136
options));
3237
#else
38+
BOOST_NETWORK_MESSAGE("creating an SSL delegate, but not supported");
3339
BOOST_THROW_EXCEPTION(std::runtime_error("HTTPS not supported."));
3440
#endif /* BOOST_NETWORK_ENABLE_HTTPS */
3541
} else {
42+
BOOST_NETWORK_MESSAGE("creating a normal delegate");
3643
delegate.reset(new normal_delegate(service));
3744
}
3845
return delegate;
3946
}
4047

41-
connection_delegate_factory::~connection_delegate_factory() {}
48+
connection_delegate_factory::~connection_delegate_factory() {
49+
BOOST_NETWORK_MESSAGE("connection_delegate_factory::~connection_delegate_factory()");
50+
}
4251

4352
} /* http */
4453

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,20 @@
88
// http://www.boost.org/LICENSE_1_0.txt)
99

1010
#include <boost/shared_ptr.hpp>
11-
#include <boost/asio/io_service.hpp>
12-
#include <boost/network/protocol/http/client/client_connection.hpp>
11+
12+
namespace boost { namespace asio {
13+
14+
class io_service;
15+
16+
} // namespace asio
17+
18+
} // namespace boost
1319

1420
namespace boost { namespace network { namespace http {
1521

1622
class client_options;
17-
1823
struct client_connection;
24+
struct request_base;
1925

2026
struct connection_factory {
2127
virtual shared_ptr<client_connection> create_connection(asio::io_service &service,
@@ -30,8 +36,4 @@ struct connection_factory {
3036

3137
} /* boost */
3238

33-
#ifdef BOOST_NETWORK_NO_LIB
34-
#include <boost/network/protocol/http/client/connection/connection_factory.ipp>
35-
#endif
36-
3739
#endif /* BOOST_NETWORK_PROTOCOL_HTTP_CLIENT_CONNECTION_CONNECTION_FACTORY_HPP_20111112 */

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,4 @@ struct normal_delegate : connection_delegate {
3838

3939
} /* boost */
4040

41-
#ifdef BOOST_NETWORK_NO_LIB
42-
#include <boost/network/protocol/http/client/connection/normal_delegate.ipp>
43-
#endif /* BOOST_NETWORK_NO_LIB */
44-
4541
#endif /* BOOST_NETWORK_PROTOCOL_HTTP_CLIENT_CONNECTION_NORMAL_DELEGATE_20110819 */

0 commit comments

Comments
 (0)