|
15 | 15 | #include<boost/make_shared.hpp> |
16 | 16 | #include<boost/bind.hpp> |
17 | 17 |
|
18 | | -namespaceboost {namespacenetwork {namespacehttp { |
| 18 | +namespaceboost { |
| 19 | +namespacenetwork { |
| 20 | +namespacehttp { |
19 | 21 |
|
20 | | -template<classTag,unsigned version_major,unsigned version_minor> |
21 | | -structbasic_client_impl; |
| 22 | +template<classTag,unsigned version_major,unsigned version_minor> |
| 23 | +structbasic_client_impl; |
22 | 24 |
|
23 | | -namespaceimpl { |
24 | | -template<classTag,unsigned version_major,unsigned version_minor> |
25 | | -structasync_client : |
26 | | - connection_policy<Tag,version_major,version_minor>::type |
27 | | - { |
28 | | -typedef |
29 | | -typename connection_policy<Tag,version_major,version_minor>::type |
30 | | - connection_base; |
31 | | -typedef |
32 | | -typename resolver<Tag>::type |
33 | | - resolver_type; |
34 | | -typedef |
35 | | -typename string<Tag>::type |
36 | | - string_type; |
| 25 | +namespaceimpl { |
| 26 | +template<classTag,unsigned version_major,unsigned version_minor> |
| 27 | +structasync_client |
| 28 | + : connection_policy<Tag, version_major, version_minor>::type { |
| 29 | +typedeftypename connection_policy<Tag, version_major, version_minor>::type |
| 30 | + connection_base; |
| 31 | +typedeftypename resolver<Tag>::type resolver_type; |
| 32 | +typedeftypename string<Tag>::type string_type; |
37 | 33 |
|
38 | | -typedef |
39 | | - function<void(boost::iterator_range<charconst *>const &, system::error_codeconst &)> |
40 | | - body_callback_function_type; |
| 34 | +typedef function<void(boost::iterator_range<charconst*>const&, |
| 35 | + system::error_codeconst&)> body_callback_function_type; |
41 | 36 |
|
42 | | -async_client(bool cache_resolved,bool follow_redirect, boost::shared_ptr<boost::asio::io_service> service, optional<string_type>const & certificate_filename, optional<string_type>const & verify_path) |
43 | | - : connection_base(cache_resolved, follow_redirect), |
44 | | -service_ptr(service.get() ? service : boost::make_shared<boost::asio::io_service>()), |
| 37 | +typedef function<bool(string_type&)> body_generator_function_type; |
| 38 | + |
| 39 | +async_client(bool cache_resolved, |
| 40 | +bool follow_redirect, |
| 41 | + boost::shared_ptr<boost::asio::io_service> service, |
| 42 | + optional<string_type>const& certificate_filename, |
| 43 | + optional<string_type>const& verify_path) |
| 44 | + : connection_base(cache_resolved, follow_redirect), |
| 45 | +service_ptr(service.get() |
| 46 | + ? service |
| 47 | + : boost::make_shared<boost::asio::io_service>()), |
45 | 48 | service_(*service_ptr), |
46 | 49 | resolver_(service_), |
47 | 50 | sentinel_(new boost::asio::io_service::work(service_)), |
48 | 51 | certificate_filename_(certificate_filename), |
49 | | - verify_path_(verify_path) |
50 | | - { |
51 | | - connection_base::resolver_strand_.reset(new |
52 | | -boost::asio::io_service::strand(service_)); |
53 | | - lifetime_thread_.reset(newboost::thread( |
54 | | -boost::bind( |
55 | | - &boost::asio::io_service::run, |
56 | | - &service_ |
57 | | - ))); |
58 | | - } |
59 | | - |
60 | | -~async_client()throw () |
61 | | - { |
62 | | - sentinel_.reset(); |
63 | | -if (lifetime_thread_.get()) { |
64 | | - lifetime_thread_->join(); |
65 | | - lifetime_thread_.reset(); |
66 | | - } |
67 | | - } |
68 | | - |
69 | | - basic_response<Tag>constrequest_skeleton( |
70 | | - basic_request<Tag>const & request_, |
71 | | - string_typeconst & method, |
72 | | -bool get_body, |
73 | | - body_callback_function_type callback |
74 | | - ) |
75 | | - { |
76 | | -typename connection_base::connection_ptr connection_; |
77 | | - connection_ =connection_base::get_connection(resolver_, request_, certificate_filename_, verify_path_); |
78 | | -return connection_->send_request(method, request_, get_body, callback); |
79 | | - } |
80 | | - |
81 | | - boost::shared_ptr<boost::asio::io_service> service_ptr; |
82 | | - boost::asio::io_service & service_; |
83 | | - resolver_type resolver_; |
84 | | - boost::shared_ptr<boost::asio::io_service::work> sentinel_; |
85 | | - boost::shared_ptr<boost::thread> lifetime_thread_; |
86 | | - optional<string_type> certificate_filename_, verify_path_; |
87 | | - }; |
88 | | - }// namespace impl |
| 52 | + verify_path_(verify_path) { |
| 53 | + connection_base::resolver_strand_.reset( |
| 54 | +newboost::asio::io_service::strand(service_)); |
| 55 | + lifetime_thread_.reset(newboost::thread( |
| 56 | +boost::bind(&boost::asio::io_service::run, &service_))); |
| 57 | + } |
89 | 58 |
|
90 | | -}// namespace http |
| 59 | +~async_client()throw() { |
| 60 | + sentinel_.reset(); |
| 61 | +if (lifetime_thread_.get()) { |
| 62 | + lifetime_thread_->join(); |
| 63 | + lifetime_thread_.reset(); |
| 64 | + } |
| 65 | + } |
91 | 66 |
|
92 | | -}// namespace network |
| 67 | + basic_response<Tag>constrequest_skeleton( |
| 68 | + basic_request<Tag>const& request_, |
| 69 | + string_typeconst& method, |
| 70 | +bool get_body, |
| 71 | + body_callback_function_type callback, |
| 72 | + body_generator_function_type generator) { |
| 73 | +typename connection_base::connection_ptr connection_; |
| 74 | + connection_ =connection_base::get_connection( |
| 75 | + resolver_, request_, certificate_filename_, verify_path_); |
| 76 | +return connection_->send_request( |
| 77 | + method, request_, get_body, callback, generator); |
| 78 | + } |
93 | 79 |
|
94 | | -}// namespace boost |
| 80 | + boost::shared_ptr<boost::asio::io_service> service_ptr; |
| 81 | + boost::asio::io_service& service_; |
| 82 | + resolver_type resolver_; |
| 83 | + boost::shared_ptr<boost::asio::io_service::work> sentinel_; |
| 84 | + boost::shared_ptr<boost::thread> lifetime_thread_; |
| 85 | + optional<string_type> certificate_filename_, verify_path_; |
| 86 | +}; |
| 87 | +}// namespace impl |
| 88 | +}// namespace http |
| 89 | +}// namespace network |
| 90 | +}// namespace boost |
95 | 91 |
|
96 | | -#endif// BOOST_NETWORK_PROTOCOL_HTTP_CLIENT_ASYNC_IMPL_HPP_20100623 |
| 92 | +#endif// BOOST_NETWORK_PROTOCOL_HTTP_CLIENT_ASYNC_IMPL_HPP_20100623 |