Skip to content

Commit 0084d96

Browse files
committed
More work in progress, working (hard) towards getting the asynchronous plumbing to compile first...
1 parent 286eb28 commit 0084d96

File tree

10 files changed

+111
-28
lines changed

10 files changed

+111
-28
lines changed

boost/network/protocol/http/client.hpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,15 @@ namespace boost { namespace network { namespace http {
3030

3131
template <class Tag, unsigned version_major, unsigned version_minor>
3232
struct basic_client
33-
: basic_client_facade<basic_client<Tag,version_major,version_minor> >
33+
: basic_client_facade<Tag, basic_client<Tag,version_major,version_minor> >
3434
{
3535
private:
3636
typedef typename basic_client_impl<Tag,version_major,version_minor> pimpl_type;
37-
37+
typedef basic_client_facade<Tag, basic_client<Tag,version_major,version_minor> > base_facade_type;
3838
public:
3939
typedef basic_request<Tag> request;
4040
typedef basic_response<Tag> response;
41+
typedef Tag tag_type;
4142

4243
struct cache_resolved_type { };
4344

@@ -58,19 +59,19 @@ namespace boost { namespace network { namespace http {
5859
// Constructors
5960
// =================================================================
6061
basic_client()
61-
: pimpl(new pimpl_type(false, false))
62+
: base_facade_type(), pimpl(new pimpl_type(false, false))
6263
{}
6364

6465
explicit basic_client(cache_resolved_type (*)())
65-
: pimpl(new pimmpl_type(true, false))
66+
: base_facade_type(), pimpl(new pimpl_type(true, false))
6667
{}
6768

6869
explicit basic_client(follow_redirect_type (*)())
69-
: pimpl(new pimpl_type(false, true))
70+
: base_facade_type(), pimpl(new pimpl_type(false, true))
7071
{}
7172

7273
basic_client(cache_resolved_type (*)(), follow_redirect_type (*)())
73-
: pimpl(new pimpl_type(true, true))
74+
: base_facade_type(), pimpl(new pimpl_type(true, true))
7475
{}
7576

7677
//
@@ -83,6 +84,8 @@ namespace boost { namespace network { namespace http {
8384

8485
boost::shared_ptr<pimpl_type> pimpl;
8586

87+
friend struct basic_client_facade<Tag,basic_client<Tag,version_major,version_minor> > ;
88+
8689
basic_response<Tag> const request_skeleton(basic_request<Tag> const & request_, string_type method, bool get_body) {
8790
return pimpl->request_skeleton(request_, method, get_body);
8891
}

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
// http://www.boost.org/LICENSE_1_0.txt)
88

99
#include <boost/asio/io_service.hpp>
10+
#include <boost/asio/strand.hpp>
1011
#include <boost/thread/thread.hpp>
1112
#include <boost/bind.hpp>
1213

@@ -27,13 +28,19 @@ namespace boost { namespace network { namespace http {
2728
typedef
2829
typename resolver<Tag>::type
2930
resolver_type;
31+
typedef
32+
typename string<Tag>::type
33+
string_type;
3034

3135
async_client(bool cache_resolved, bool follow_redirect)
3236
: connection_base(cache_resolved, follow_redirect),
3337
service_(new boost::asio::io_service),
3438
resolver_(new resolver_type(*service_)),
3539
sentinel_(new boost::asio::io_service::work(*service_))
3640
{
41+
connection_base::service_ = service_;
42+
connection_base::resolver_strand_.reset(new
43+
boost::asio::io_service::strand(*service_));
3744
lifetime_thread_.reset(new boost::thread(
3845
boost::bind(
3946
&boost::asio::io_service::run,
@@ -50,9 +57,14 @@ namespace boost { namespace network { namespace http {
5057

5158
friend struct basic_client_impl<Tag,version_major,version_minor>;
5259

53-
basic_response<Tag> const request_skeleton(basic_request<Tag> const & request_, string_type method, bool get_body) {
60+
basic_response<Tag> const request_skeleton(
61+
basic_request<Tag> const & request_,
62+
string_type const & method,
63+
bool get_body
64+
)
65+
{
5466
typename connection_base::connection_ptr connection_;
55-
connection_ = connection_base::get_connection(service_, resolver_, request_);
67+
connection_ = connection_base::get_connection(resolver_, request_);
5668
return connection_->send_request(method, request_, get_body);
5769
}
5870

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,15 @@ namespace boost { namespace network { namespace http {
1414
template <class Tag>
1515
struct basic_response;
1616

17-
template <class Derived>
17+
template <class Tag, class Derived>
1818
struct basic_client_facade {
19-
typedef basic_request<typename Derived::tag> request;
20-
typedef basic_response<typename Derived::tag> response;
21-
typedef typename string<typename Derived::tag>::type string_type;
19+
20+
typedef typename string<Tag>::type string_type;
21+
typedef basic_request<Tag> request;
22+
typedef basic_response<Tag> response;
23+
24+
basic_client_facade()
25+
{}
2226

2327
response const head (request const & request_) {
2428
return static_cast<Derived*>(this)->request_skeleton(request_, "HEAD", false);

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

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <boost/static_assert.hpp>
1515

1616
#include <boost/network/protocol/http/traits/connection_policy.hpp>
17+
#include <boost/network/protocol/http/client/async_impl.hpp>
1718

1819
namespace boost { namespace network { namespace http {
1920

@@ -26,11 +27,24 @@ namespace boost { namespace network { namespace http {
2627
struct async_client;
2728

2829
template <class Tag, unsigned version_major, unsigned version_minor>
29-
struct sync_client
30+
struct sync_client :
31+
connection_policy<Tag, version_major, version_minor>::type
3032
{
3133
protected:
34+
typedef typename string<Tag>::type string_type;
35+
typedef typename connection_policy<Tag,version_major,version_minor>::type connection_base;
36+
typedef typename resolver<Tag>::type resolver_type;
3237
friend struct basic_client_impl<Tag,version_major,version_minor>;
3338

39+
boost::asio::io_service service_;
40+
resolver_type resolver_;
41+
42+
sync_client(bool cache_resolved, bool follow_redirect)
43+
: connection_base(cache_resolved, follow_redirect),
44+
service_(),
45+
resolver_(service_)
46+
{}
47+
3448
basic_response<Tag> const request_skeleton(basic_request<Tag> const & request_, string_type method, bool get_body) {
3549
typename connection_base::connection_ptr connection_;
3650
connection_ = connection_base::get_connection(resolver_, request_);
@@ -67,6 +81,7 @@ namespace boost { namespace network { namespace http {
6781
));
6882

6983
private:
84+
friend struct basic_client<Tag,version_major,version_minor>;
7085
typedef typename impl::client_base<Tag,version_major,version_minor>::type base_type;
7186
basic_client_impl(bool cache_resolved, bool follow_redirect)
7287
: base_type(cache_resolved, follow_redirect)
@@ -76,9 +91,6 @@ namespace boost { namespace network { namespace http {
7691
{}
7792
};
7893

79-
80-
};
81-
8294
} // namespace http
8395

8496
} // namespace network

boost/network/protocol/http/impl/async_connection_base.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ namespace boost { namespace network { namespace http { namespace impl {
3434
return dynamic_cast<async_connection_base<Tag,version_major,version_minor>*>(new http_async_connection<Tag,version_major,version_minor>(resolver));
3535
}
3636

37-
virtual response start(string_type const & hostname, string_type const & port, request const & request) = 0;
37+
virtual response start(request const & request, string_type const & method, bool get_body) = 0;
3838

3939
};
4040

boost/network/protocol/http/impl/http_async_connection.hpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,13 @@ namespace boost { namespace network { namespace http { namespace impl {
2424
typedef typename base::response response;
2525
typedef typename base::string_type string_type;
2626
typedef typename base::request request;
27+
typedef typename base::resolver_base::resolve_function resolve_function;
2728

2829
http_async_connection(
2930
boost::shared_ptr<resolver_type> resolver,
30-
resolver_function resolve,
31-
bool follow_redirect, )
32-
: resolver_(resolver),
31+
resolve_function resolve,
32+
bool follow_redirect
33+
) : resolver_(resolver),
3334
resolve_(resolve),
3435
follow_redirect_(follow_redirect)
3536
{}

boost/network/protocol/http/message/async_message.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ namespace boost { namespace network { namespace http {
3434
version_(other.version_),
3535
source_(other.source_),
3636
destination_(other.destination_),
37-
headers_(other.destination_),
37+
headers_(other.headers_),
3838
body_(other.body_)
3939
{}
4040

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#ifndef BOOST_NETWORK_PROTOCOL_HTTP_MESSAGE_DESTINATION_HPP_20100624
2+
#define BOOST_NETWORK_PROTOCOL_HTTP_MESSAGE_DESTINATION_HPP_20100624
3+
4+
// Copyright 2010 (c) Dean Michael Berris.
5+
// Distributed under the Boost Software License, Version 1.0.
6+
// (See accompanying file LICENSE_1_0.txt or copy at
7+
// http://www.boost.org/LICENSE_1_0.txt)
8+
9+
#include <boost/network/protocol/http/response_concept.hpp>
10+
#include <boost/concept/requires.hpp>
11+
12+
namespace boost { namespace network { namespace http {
13+
14+
template <class Tag>
15+
struct basic_response;
16+
17+
namespace impl {
18+
19+
template <class Tag>
20+
struct destination_wrapper {
21+
typedef typename string<Tag>::type string_type;
22+
basic_response<Tag> const & message_;
23+
destination_wrapper(basic_response<Tag> const & message)
24+
: message_(message) {}
25+
destination_wrapper(destination_wrapper const & other)
26+
: message_(other.message_) {}
27+
operator string_type const () {
28+
return message_.source();
29+
}
30+
};
31+
32+
} // namespace impl
33+
34+
template <class Tag>
35+
inline
36+
BOOST_CONCEPT_REQUIRES(((Response<basic_response<Tag> >)),
37+
(impl::destination_wrapper<Tag> const))
38+
destination(basic_response<Tag> const & message) {
39+
return impl::destination_wrapper<Tag>(message);
40+
}
41+
42+
} // namespace http
43+
44+
} // namespace network
45+
46+
} // namespace boost
47+
48+
#endif // BOOST_NETWORK_PROTOCOL_HTTP_MESSAGE_DESTINATION_HPP_20100624

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
// (See accompanying file LICENSE_1_0.txt or copy at
77
// http://www.boost.org/LICENSE_1_0.txt)
88

9+
#include <boost/enable_shared_from_this.hpp>
10+
911
namespace boost { namespace network { namespace http { namespace policies {
1012

1113
template <class Tag>
@@ -24,12 +26,10 @@ namespace boost { namespace network { namespace http { namespace policies {
2426
boost::shared_ptr<boost::asio::io_service> service_;
2527
boost::shared_ptr<boost::asio::io_service::strand> resolver_strand_;
2628

27-
explicit async_resolver(bool cache_resolved, boost::shared_ptr<boost::asio::io_service> service)
29+
explicit async_resolver(bool cache_resolved)
2830
: cache_resolved_(cache_resolved), endpoint_cache_()
2931
{
30-
service_ = service;
31-
resolver_strand_.reset(new
32-
boost::asio::io_service::strand(*service_));
32+
3333
}
3434

3535
void resolve(
@@ -38,8 +38,9 @@ namespace boost { namespace network { namespace http { namespace policies {
3838
boost::function<void(boost::system::error_code const &,resolver_iterator_pair)> once_resolved
3939
)
4040
{
41-
if (cache_resolved) {
42-
endpoint_cache::iterator iter = resolved_map_.find(boost::to_lower_copy(host));
41+
if (cache_resolved_) {
42+
endpoint_cache::iterator iter =
43+
endpoint_cache_.find(boost::to_lower_copy(host));
4344
if (iter != resolved_map_.end()) {
4445
boost::system::error_code ignored;
4546
once_resolved(ignored, iter->second);
@@ -79,7 +80,7 @@ namespace boost { namespace network { namespace http { namespace policies {
7980
bool inserted = false;
8081
if (!ec && cache_resolved) {
8182
boost::fusion::tie(iter, inserted) =
82-
resolved_map_.insert(
83+
endpoint_cache_.insert(
8384
std::make_pair(
8485
host,
8586
std::make_pair(

boost/network/protocol/http/response.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ namespace boost { namespace network { namespace http {
8989
#include <boost/network/protocol/http/message/wrappers/version.hpp>
9090
#include <boost/network/protocol/http/message/wrappers/status.hpp>
9191
#include <boost/network/protocol/http/message/wrappers/status_message.hpp>
92+
#include <boost/network/protocol/http/message/wrappers/destination.hpp>
93+
#include <boost/network/protocol/http/message/wrappers/source.hpp>
9294

9395
#include <boost/network/protocol/http/message/modifiers/version.hpp>
9496
#include <boost/network/protocol/http/message/modifiers/status.hpp>

0 commit comments

Comments
 (0)