|
2 | 2 | #defineBOOST_NETWORK_PROTOCOL_HTTP_CLIENT_ASYNC_IMPL_HPP_20100623 |
3 | 3 |
|
4 | 4 | // Copyright Dean Michael Berris 2010. |
| 5 | +// Copyright 2011 Dean Michael Berris (dberris@google.com). |
| 6 | +// Copyright 2011 Google, Inc. |
5 | 7 | // Distributed under the Boost Software License, Version 1.0. |
6 | 8 | // (See accompanying file LICENSE_1_0.txt or copy at |
7 | 9 | // http://www.boost.org/LICENSE_1_0.txt) |
|
13 | 15 |
|
14 | 16 | namespaceboost {namespacenetwork {namespacehttp { |
15 | 17 |
|
16 | | -template<classTag,unsigned version_major,unsigned version_minor> |
17 | | -structbasic_client_impl; |
| 18 | +template<classTag,unsigned version_major,unsigned version_minor> |
| 19 | +structbasic_client_impl; |
18 | 20 |
|
19 | | -namespaceimpl { |
20 | | -template<classTag,unsigned version_major,unsigned version_minor> |
21 | | -structasync_client : |
22 | | -connection_policy<Tag,version_major,version_minor>::type |
23 | | -{ |
24 | | -typedef |
25 | | -typename connection_policy<Tag,version_major,version_minor>::type |
26 | | -connection_base; |
27 | | -typedef |
28 | | -typename resolver<Tag>::type |
29 | | -resolver_type; |
30 | | -typedef |
31 | | -typename string<Tag>::type |
32 | | -string_type; |
| 21 | +namespaceimpl { |
| 22 | +template<classTag,unsigned version_major,unsigned version_minor> |
| 23 | +structasync_client : |
| 24 | + connection_policy<Tag,version_major,version_minor>::type |
| 25 | + { |
| 26 | +typedef |
| 27 | +typename connection_policy<Tag,version_major,version_minor>::type |
| 28 | + connection_base; |
| 29 | +typedef |
| 30 | +typename resolver<Tag>::type |
| 31 | + resolver_type; |
| 32 | +typedef |
| 33 | +typename string<Tag>::type |
| 34 | + string_type; |
33 | 35 |
|
34 | | -typedef |
35 | | -function<void(boost::iterator_range<charconst *>const &, system::error_codeconst &)> |
36 | | -body_callback_function_type; |
| 36 | +typedef |
| 37 | + function<void(boost::iterator_range<charconst *>const &, system::error_codeconst &)> |
| 38 | + body_callback_function_type; |
37 | 39 |
|
38 | | -async_client(bool cache_resolved,bool follow_redirect, optional<string_type>const & certificate_filename, optional<string_type>const & verify_path) |
39 | | -: connection_base(cache_resolved, follow_redirect), |
40 | | -service_ptr(new boost::asio::io_service), |
41 | | -service_(*service_ptr), |
42 | | -resolver_(service_), |
43 | | -sentinel_(new boost::asio::io_service::work(service_)), |
44 | | -certificate_filename_(certificate_filename), |
45 | | -verify_path_(verify_path) |
46 | | -{ |
47 | | -connection_base::resolver_strand_.reset(new |
48 | | -boost::asio::io_service::strand(service_)); |
49 | | -lifetime_thread_.reset(newboost::thread( |
50 | | -boost::bind( |
51 | | -&boost::asio::io_service::run, |
52 | | -&service_ |
53 | | -))); |
54 | | -} |
| 40 | +async_client(bool cache_resolved,bool follow_redirect, optional<string_type>const & certificate_filename, optional<string_type>const & verify_path) |
| 41 | + : connection_base(cache_resolved, follow_redirect), |
| 42 | +service_ptr(new boost::asio::io_service), |
| 43 | + service_(*service_ptr), |
| 44 | + resolver_(service_), |
| 45 | + sentinel_(new boost::asio::io_service::work(service_)), |
| 46 | + certificate_filename_(certificate_filename), |
| 47 | + verify_path_(verify_path) |
| 48 | + { |
| 49 | + connection_base::resolver_strand_.reset(new |
| 50 | +boost::asio::io_service::strand(service_)); |
| 51 | + lifetime_thread_.reset(newboost::thread( |
| 52 | +boost::bind( |
| 53 | + &boost::asio::io_service::run, |
| 54 | + &service_ |
| 55 | + ))); |
| 56 | + } |
55 | 57 |
|
56 | | -async_client(bool cache_resolved,bool follow_redirect, boost::asio::io_service & service, optional<string_type>const & certificate_filename, optional<string_type>const & verify_path) |
57 | | -: connection_base(cache_resolved, follow_redirect), |
58 | | -service_ptr(0), |
59 | | -service_(service), |
60 | | -resolver_(service_), |
61 | | -sentinel_(new boost::asio::io_service::work(service_)), |
62 | | -certificate_filename_(certificate_filename), |
63 | | -verify_path_(verify_path) |
64 | | -{ |
65 | | -} |
| 58 | +async_client(bool cache_resolved,bool follow_redirect, boost::asio::io_service & service, optional<string_type>const & certificate_filename, optional<string_type>const & verify_path) |
| 59 | + : connection_base(cache_resolved, follow_redirect), |
| 60 | + service_ptr(0), |
| 61 | + service_(service), |
| 62 | + resolver_(service_), |
| 63 | + sentinel_(new boost::asio::io_service::work(service_)), |
| 64 | + certificate_filename_(certificate_filename), |
| 65 | + verify_path_(verify_path) |
| 66 | + { |
| 67 | + } |
66 | 68 |
|
67 | | -~async_client()throw () |
68 | | -{ |
69 | | -sentinel_.reset(); |
70 | | -if (lifetime_thread_.get()) { |
71 | | -lifetime_thread_->join(); |
72 | | -lifetime_thread_.reset(); |
73 | | -} |
74 | | -delete service_ptr; |
75 | | -} |
| 69 | +~async_client()throw () |
| 70 | + { |
| 71 | + sentinel_.reset(); |
| 72 | +if (lifetime_thread_.get()) { |
| 73 | + lifetime_thread_->join(); |
| 74 | + lifetime_thread_.reset(); |
| 75 | + } |
| 76 | +delete service_ptr; |
| 77 | + } |
76 | 78 |
|
77 | | -basic_response<Tag>constrequest_skeleton( |
78 | | -basic_request<Tag>const & request_, |
79 | | -string_typeconst & method, |
80 | | -bool get_body, |
81 | | -body_callback_function_type callback |
82 | | -) |
83 | | -{ |
84 | | -typename connection_base::connection_ptr connection_; |
85 | | -connection_ =connection_base::get_connection(resolver_, request_, certificate_filename_, verify_path_); |
86 | | -return connection_->send_request(method, request_, get_body, callback); |
87 | | -} |
| 79 | + basic_response<Tag>constrequest_skeleton( |
| 80 | + basic_request<Tag>const & request_, |
| 81 | + string_typeconst & method, |
| 82 | +bool get_body, |
| 83 | + body_callback_function_type callback |
| 84 | + ) |
| 85 | + { |
| 86 | +typename connection_base::connection_ptr connection_; |
| 87 | + connection_ =connection_base::get_connection(resolver_, request_, certificate_filename_, verify_path_); |
| 88 | +return connection_->send_request(method, request_, get_body, callback); |
| 89 | + } |
88 | 90 |
|
89 | | -boost::asio::io_service * service_ptr; |
90 | | -boost::asio::io_service & service_; |
91 | | -resolver_type resolver_; |
92 | | -boost::shared_ptr<boost::asio::io_service::work> sentinel_; |
93 | | -boost::shared_ptr<boost::thread> lifetime_thread_; |
94 | | -optional<string_type> certificate_filename_, verify_path_; |
95 | | -}; |
96 | | -}// namespace impl |
| 91 | + boost::asio::io_service * service_ptr; |
| 92 | + boost::asio::io_service & service_; |
| 93 | + resolver_type resolver_; |
| 94 | + boost::shared_ptr<boost::asio::io_service::work> sentinel_; |
| 95 | + boost::shared_ptr<boost::thread> lifetime_thread_; |
| 96 | + optional<string_type> certificate_filename_, verify_path_; |
| 97 | + }; |
| 98 | + }// namespace impl |
97 | 99 |
|
98 | 100 | }// namespace http |
99 | 101 |
|
|