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

Commit0be19a5

Browse files
committed
Okay, now we're just at the point where we can actually implement the asynchronous HTTP stuff!
1 parentd6f6506 commit0be19a5

File tree

9 files changed

+209
-11
lines changed

9 files changed

+209
-11
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@ namespace boost { namespace network { namespace http { namespace impl {
2424
typedef basic_request<Tag> request;
2525
typedef basic_response<Tag> response;
2626

27-
static async_connection_base<Tag,version_major,version_minor> *new_connection(resolve_function resolve, boost::shared_ptr<resolver_type> resolver,bool https) {
27+
static async_connection_base<Tag,version_major,version_minor> *new_connection(resolve_function resolve, boost::shared_ptr<resolver_type> resolver,boolfollow_redirect,boolhttps) {
2828
if (https) {
2929
#ifdef BOOST_NETWORK_ENABLE_HTTPS
30-
returndynamic_cast<async_connection_base<Tag,version_major,version_minor>*>(new https_async_connection<Tag,version_major,version_minor>(resolver));
30+
returndynamic_cast<async_connection_base<Tag,version_major,version_minor>*>(new https_async_connection<Tag,version_major,version_minor>(resolve,resolver, follow_redirect));
3131
#else
3232
throwstd::runtime_error("HTTPS not supported.");
3333
#endif
3434
}
35-
returndynamic_cast<async_connection_base<Tag,version_major,version_minor>*>(new http_async_connection<Tag,version_major,version_minor>(resolve,resolver));
35+
returndynamic_cast<async_connection_base<Tag,version_major,version_minor>*>(new http_async_connection<Tag,version_major,version_minor>(resolver,resolve,follow_redirect));
3636
}
3737

3838
virtual responsestart(requestconst & request, string_typeconst & method,bool get_body) = 0;

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ namespace boost { namespace network { namespace http { namespace impl {
1717

1818
template<classTag,unsigned version_major,unsigned version_minor>
1919
structhttp_async_connection
20-
: async_connection_base<Tag,version_major,version_minor> {
20+
: async_connection_base<Tag,version_major,version_minor>,
21+
boost::enable_shared_from_this<http_async_connection<Tag,version_major,version_minor> >
22+
{
2123
typedef async_connection_base<Tag,version_major,version_minor> base;
2224
typedeftypename base::resolver_type resolver_type;
2325
typedeftypename base::resolver_base::resolver_iterator_pair resolver_iterator_pair;
@@ -32,7 +34,8 @@ namespace boost { namespace network { namespace http { namespace impl {
3234
bool follow_redirect
3335
) : resolver_(resolver),
3436
resolve_(resolve),
35-
follow_redirect_(follow_redirect)
37+
follow_redirect_(follow_redirect),
38+
request_strand_(new boost::asio::io_service::strand(resolver->get_io_service()))
3639
{}
3740

3841
virtual responsestart(requestconst & request, string_typeconst & method,bool get_body) {
@@ -49,7 +52,7 @@ namespace boost { namespace network { namespace http { namespace impl {
4952

5053
// start things off by resolving the host.
5154
resolve_(resolver_,host(request),
52-
request_strand->wrap(
55+
request_strand_->wrap(
5356
boost::bind(
5457
&http_async_connection<Tag,version_major,version_minor>::handle_resolved,
5558
http_async_connection<Tag,version_major,version_minor>::shared_from_this(),
@@ -95,7 +98,10 @@ namespace boost { namespace network { namespace http { namespace impl {
9598
}
9699
}
97100

98-
resolve_function resolve;
101+
boost::shared_ptr<resolver_type> resolver_;
102+
resolve_function resolve_;
103+
bool follow_redirect_;
104+
boost::shared_ptr<boost::asio::io_service::strand> request_strand_;
99105
boost::promise<string_type> version_promise;
100106
boost::promise<boost::uint16_t> status_promise;
101107
boost::promise<string_type> status_message_promise;
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#ifndef BOOST_NETWORK_PROTOCOL_HTTP_MESSAGE_MODIFIER_BODY_HPP_20100624
2+
#defineBOOST_NETWORK_PROTOCOL_HTTP_MESSAGE_MODIFIER_BODY_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/support/is_async.hpp>
10+
#include<boost/thread/future.hpp>
11+
#include<boost/concept/requires.hpp>
12+
13+
namespaceboost {namespacenetwork {namespacehttp {
14+
15+
template<classTag>
16+
structbasic_response;
17+
18+
namespaceimpl {
19+
20+
template<classTag,classT>
21+
voidbody(basic_response<Tag> & response, Tconst & value, mpl::false_const &) {
22+
response <<body(value);
23+
}
24+
25+
template<classTag,classT>
26+
voidbody(basic_response<Tag> & response, boost::shared_future<T> future, mpl::true_const &) {
27+
response.body(future);
28+
}
29+
30+
}
31+
32+
template<classTag,classT>
33+
inline
34+
BOOST_CONCEPT_REQUIRES(((Response<basic_response<Tag> >)),
35+
(void))
36+
body(basic_response<Tag> & response, Tconst & value) {
37+
impl::body(response, value, is_async<Tag>());
38+
}
39+
40+
}// namespace http
41+
42+
}// namespace network
43+
44+
}// namespace boost
45+
46+
#endif// BOOST_NETWORK_PROTOCOL_HTTP_MESSAGE_MODIFIER_BODY_HPP_20100624
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#ifndef BOOST_NETWORK_PROTOCOL_HTTP_MESSAGE_MODIFIER_DESTINATION_HPP_20100624
2+
#defineBOOST_NETWORK_PROTOCOL_HTTP_MESSAGE_MODIFIER_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/support/is_async.hpp>
10+
#include<boost/thread/future.hpp>
11+
#include<boost/concept/requires.hpp>
12+
13+
namespaceboost {namespacenetwork {namespacehttp {
14+
15+
template<classTag>
16+
structbasic_response;
17+
18+
namespaceimpl {
19+
20+
template<classTag,classT>
21+
voiddestination(basic_response<Tag> & response, Tconst & value, mpl::false_const &) {
22+
response <<destination(value);
23+
}
24+
25+
template<classTag,classT>
26+
voiddestination(basic_response<Tag> & response, boost::shared_future<T> future, mpl::true_const &) {
27+
response.destination(future);
28+
}
29+
30+
}
31+
32+
template<classTag,classT>
33+
inline
34+
BOOST_CONCEPT_REQUIRES(((Response<basic_response<Tag> >)),
35+
(void))
36+
destination(basic_response<Tag> & response, Tconst & value) {
37+
impl::destination(response, value, is_async<Tag>());
38+
}
39+
40+
}// namespace http
41+
42+
}// namespace network
43+
44+
}// namespace boost
45+
46+
#endif// BOOST_NETWORK_PROTOCOL_HTTP_MESSAGE_MODIFIER_DESTINATION_HPP_20100624
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#ifndef BOOST_NETWORK_PROTOCOL_HTTP_MESSAGE_MODIFIER_HEADERS_HPP_20100624
2+
#defineBOOST_NETWORK_PROTOCOL_HTTP_MESSAGE_MODIFIER_HEADERS_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/support/is_async.hpp>
10+
#include<boost/thread/future.hpp>
11+
#include<boost/concept/requires.hpp>
12+
13+
namespaceboost {namespacenetwork {namespacehttp {
14+
15+
template<classTag>
16+
structbasic_response;
17+
18+
namespaceimpl {
19+
20+
template<classTag,classT>
21+
voidheaders(basic_response<Tag> & response, Tconst & value, mpl::false_const &) {
22+
response <<headers(value);
23+
}
24+
25+
template<classTag,classT>
26+
voidheaders(basic_response<Tag> & response, boost::shared_future<T> future, mpl::true_const &) {
27+
response.headers(future);
28+
}
29+
30+
}
31+
32+
template<classTag,classT>
33+
inline
34+
BOOST_CONCEPT_REQUIRES(((Response<basic_response<Tag> >)),
35+
(void))
36+
headers(basic_response<Tag> & response, Tconst & value) {
37+
impl::headers(response, value, is_async<Tag>());
38+
}
39+
40+
}// namespace http
41+
42+
}// namespace network
43+
44+
}// namespace boost
45+
46+
#endif// BOOST_NETWORK_PROTOCOL_HTTP_MESSAGE_MODIFIER_HEADERS_HPP_20100624
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#ifndef BOOST_NETWORK_PROTOCOL_HTTP_MESSAGE_MODIFIER_SOURCE_HPP_20100624
2+
#defineBOOST_NETWORK_PROTOCOL_HTTP_MESSAGE_MODIFIER_SOURCE_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/support/is_async.hpp>
10+
#include<boost/thread/future.hpp>
11+
#include<boost/concept/requires.hpp>
12+
13+
namespaceboost {namespacenetwork {namespacehttp {
14+
15+
template<classTag>
16+
structbasic_response;
17+
18+
namespaceimpl {
19+
20+
template<classTag,classT>
21+
voidsource(basic_response<Tag> & response, Tconst & value, mpl::false_const &) {
22+
response <<source(value);
23+
}
24+
25+
template<classTag,classT>
26+
voidsource(basic_response<Tag> & response, boost::shared_future<T> future, mpl::true_const &) {
27+
response.source(future);
28+
}
29+
30+
}
31+
32+
template<classTag,classT>
33+
inline
34+
BOOST_CONCEPT_REQUIRES(((Response<basic_response<Tag> >)),
35+
(void))
36+
source(basic_response<Tag> & response, Tconst & value) {
37+
impl::source(response, value, is_async<Tag>());
38+
}
39+
40+
}// namespace http
41+
42+
}// namespace network
43+
44+
}// namespace boost
45+
46+
#endif// BOOST_NETWORK_PROTOCOL_HTTP_MESSAGE_MODIFIER_SOURCE_HPP_20100624

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,11 @@ namespace boost { namespace network { namespace http {
3434
connection_impl(
3535
bool follow_redirect,
3636
resolver_function_type resolve,
37+
boost::shared_ptr<resolver_type> resolver,
3738
bool https
3839
)
3940
: pimpl(
40-
impl::async_connection_base<Tag,version_major,version_minor>::new_connection(resolve, follow_redirect, https)
41+
impl::async_connection_base<Tag,version_major,version_minor>::new_connection(resolve,resolver,follow_redirect, https)
4142
)
4243
{}
4344

@@ -61,6 +62,7 @@ namespace boost { namespace network { namespace http {
6162
this,
6263
_1, _2, _3
6364
)
65+
, resolver
6466
,boost::iequals(protocol(request_),string_type("https"))
6567
)
6668
);

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ namespace boost { namespace network { namespace http { namespace policies {
2121
typedef std::pair<resolver_iterator, resolver_iterator> resolver_iterator_pair;
2222
typedeftypename string<Tag>::type string_type;
2323
typedef boost::unordered_map<string_type, resolver_iterator_pair> endpoint_cache;
24+
typedef boost::function<void(boost::system::error_codeconst &,resolver_iterator_pair)> resolve_completion_function;
25+
typedef boost::function<void(boost::shared_ptr<resolver_type>,string_type,resolve_completion_function)> resolve_function;
2426
protected:
2527
bool cache_resolved_;
2628
endpoint_cache endpoint_cache_;
@@ -36,7 +38,7 @@ namespace boost { namespace network { namespace http { namespace policies {
3638
voidresolve(
3739
boost::shared_ptr<resolver_type> resolver_,
3840
string_typeconst & host,
39-
boost::function<void(boost::system::error_codeconst &,resolver_iterator_pair)> once_resolved
41+
resolve_completion_function once_resolved
4042
)
4143
{
4244
if (cache_resolved_) {
@@ -67,7 +69,7 @@ namespace boost { namespace network { namespace http { namespace policies {
6769

6870
voidhandle_resolve(
6971
string_typeconst & host,
70-
boost::function<void(boost::system::error_codeconst &,resolver_iterator)> once_resolved,
72+
resolve_completion_function once_resolved,
7173
boost::system::error_codeconst & ec,
7274
resolver_iterator endpoint_iterator
7375
)
@@ -79,7 +81,7 @@ namespace boost { namespace network { namespace http { namespace policies {
7981

8082
endpoint_cache::iterator iter;
8183
bool inserted =false;
82-
if (!ec &&cache_resolved) {
84+
if (!ec &&cache_resolved_) {
8385
boost::fusion::tie(iter, inserted) =
8486
endpoint_cache_.insert(
8587
std::make_pair(

‎boost/network/protocol/http/response.hpp‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,5 +95,9 @@ namespace boost { namespace network { namespace http {
9595
#include<boost/network/protocol/http/message/modifiers/version.hpp>
9696
#include<boost/network/protocol/http/message/modifiers/status.hpp>
9797
#include<boost/network/protocol/http/message/modifiers/status_message.hpp>
98+
#include<boost/network/protocol/http/message/modifiers/source.hpp>
99+
#include<boost/network/protocol/http/message/modifiers/destination.hpp>
100+
#include<boost/network/protocol/http/message/modifiers/headers.hpp>
101+
#include<boost/network/protocol/http/message/modifiers/body.hpp>
98102

99103
#endif// BOOST_NETWORK_PROTOCOL_HTTP_RESPONSE_HPP

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp