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

Commit6da32c4

Browse files
committed
Removing client dependency on Boost.Parameter.
1 parent6ba8f9a commit6da32c4

File tree

10 files changed

+45
-190
lines changed

10 files changed

+45
-190
lines changed

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

Lines changed: 11 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
#include<map>
2525

2626
#include<boost/network/protocol/http/client/facade.hpp>
27-
#include<boost/network/protocol/http/client/parameters.hpp>
2827
#include<boost/network/protocol/http/client/macros.hpp>
28+
#include<boost/network/protocol/http/client/options.hpp>
2929

3030
namespaceboost {namespacenetwork {namespacehttp {
3131

@@ -41,38 +41,18 @@ namespace boost { namespace network { namespace http {
4141
typedef basic_response<Tag> response;
4242
typedeftypename string<Tag>::type string_type;
4343
typedef Tag tag_type;
44+
typedef client_options<Tag> options;
4445

45-
//Constructor
46+
//Constructors
4647
// =================================================================
47-
// This is a Boost.Parameter-based constructor forwarder, whose
48-
// implementation is actually forwarded to the base type.
49-
//
50-
// The supported parameters are:
51-
// _follow_redirects : bool -- whether to follow HTTP redirect
52-
// responses (default: false)
53-
// _cache_resolved : bool -- whether to cache the resolved
54-
// endpoints (default: false)
55-
// _io_service : boost::asio::io_service &
56-
// -- supply an io_service to the
57-
// client
58-
// _openssl_certificate : string
59-
// -- the name of the certificate file
60-
// to use
61-
// _openssl_verify_path : string
62-
// -- the name of the directory from
63-
// which the certificate authority
64-
// files can be found
65-
66-
BOOST_PARAMETER_CONSTRUCTOR(
67-
basic_client, (base_facade_type), tag,
68-
(optional
69-
(in_out(io_service), (boost::asio::io_service&))
70-
(follow_redirects, (bool))
71-
(cache_resolved, (bool))
72-
(openssl_certificate, (string_type))
73-
(openssl_verify_path, (string_type))
74-
))
75-
48+
// This constructor takes a single options argument of type
49+
// client_options. See boost/network/protocol/http/client/options.hpp
50+
// for more details.
51+
explicitbasic_client(optionsconst & options)
52+
: base_facade_type(options) {}
53+
54+
// This default constructor sets up the default options.
55+
basic_client() : base_facade_type(options()) {}
7656
//
7757
// =================================================================
7858

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

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
#include<boost/asio/io_service.hpp>
1212
#include<boost/asio/strand.hpp>
1313
#include<boost/thread/thread.hpp>
14+
#include<boost/shared_ptr.hpp>
15+
#include<boost/make_shared.hpp>
1416
#include<boost/bind.hpp>
1517

1618
namespaceboost {namespacenetwork {namespacehttp {
@@ -37,9 +39,9 @@ namespace boost { namespace network { namespace http {
3739
function<void(boost::iterator_range<charconst *>const &, system::error_codeconst &)>
3840
body_callback_function_type;
3941

40-
async_client(bool cache_resolved,bool follow_redirect, optional<string_type>const & certificate_filename, optional<string_type>const & verify_path)
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)
4143
: connection_base(cache_resolved, follow_redirect),
42-
service_ptr(newboost::asio::io_service),
44+
service_ptr(service.get() ? service :boost::make_shared<boost::asio::io_service>()),
4345
service_(*service_ptr),
4446
resolver_(service_),
4547
sentinel_(new boost::asio::io_service::work(service_)),
@@ -55,27 +57,13 @@ namespace boost { namespace network { namespace http {
5557
)));
5658
}
5759

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-
connection_base::resolver_strand_.reset(new
68-
boost::asio::io_service::strand(service_));
69-
}
70-
7160
~async_client()throw ()
7261
{
7362
sentinel_.reset();
7463
if (lifetime_thread_.get()) {
7564
lifetime_thread_->join();
7665
lifetime_thread_.reset();
7766
}
78-
delete service_ptr;
7967
}
8068

8169
basic_response<Tag>constrequest_skeleton(
@@ -90,7 +78,7 @@ namespace boost { namespace network { namespace http {
9078
return connection_->send_request(method, request_, get_body, callback);
9179
}
9280

93-
boost::asio::io_service * service_ptr;
81+
boost::shared_ptr<boost::asio::io_service> service_ptr;
9482
boost::asio::io_service & service_;
9583
resolver_type resolver_;
9684
boost::shared_ptr<boost::asio::io_service::work> sentinel_;

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

Lines changed: 14 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include<boost/network/protocol/http/request.hpp>
1010
#include<boost/network/protocol/http/response.hpp>
1111
#include<boost/network/protocol/http/client/pimpl.hpp>
12-
#include<boost/network/protocol/http/client/parameters.hpp>
12+
#include<boost/network/protocol/http/client/options.hpp>
1313

1414
namespaceboost {namespacenetwork {namespacehttp {
1515

@@ -28,45 +28,20 @@ namespace boost { namespace network { namespace http {
2828
typedef basic_client_impl<Tag,version_major,version_minor> pimpl_type;
2929
typedef function<void(iterator_range<charconst *>const &,system::error_codeconst &)> body_callback_function_type;
3030

31-
template<classArgPack>
32-
basic_client_facade(ArgPackconst & args)
31+
basic_client_facade(client_options<Tag>const &options)
3332
{
34-
init_pimpl(args,
35-
typename mpl::if_<
36-
is_same<
37-
typename parameter::value_type<ArgPack, tag::io_service,void>::type,
38-
void
39-
>,
40-
no_io_service,
41-
has_io_service
42-
>::type());
33+
init_pimpl(options);
4334
}
4435

45-
BOOST_PARAMETER_MEMBER_FUNCTION((responseconst), head, tag, (required (request,(requestconst &)))) {
36+
responseconsthead(requestconst &request) {
4637
return pimpl->request_skeleton(request,"HEAD",false,body_callback_function_type());
4738
}
4839

49-
BOOST_PARAMETER_MEMBER_FUNCTION((responseconst), get , tag,
50-
(required
51-
(request,(requestconst &))
52-
)
53-
(optional
54-
(body_handler,(body_callback_function_type),body_callback_function_type())
55-
)
56-
) {
40+
responseconstget(requestconst &request, body_callback_function_type body_handler = body_callback_function_type()) {
5741
return pimpl->request_skeleton(request,"GET",true, body_handler);
5842
}
5943

60-
BOOST_PARAMETER_MEMBER_FUNCTION((responseconst), post, tag,
61-
(required
62-
(request,(request))// yes sir, we make a copy of the original request.
63-
)
64-
(optional
65-
(body,(string_typeconst &),string_type())
66-
(content_type,(string_typeconst &),string_type())
67-
(body_handler,(body_callback_function_type),body_callback_function_type())
68-
)
69-
) {
44+
responseconstpost(request request, string_typeconst &body = string_type(), string_typeconst &content_type = string_type(), body_callback_function_type body_handler = body_callback_function_type()) {
7045
if (body !=string_type()) {
7146
request <<remove_header("Content-Length")
7247
<<header("Content-Length", boost::lexical_cast<string_type>(body.size()))
@@ -88,16 +63,7 @@ namespace boost { namespace network { namespace http {
8863
return pimpl->request_skeleton(request,"POST",true, body_handler);
8964
}
9065

91-
BOOST_PARAMETER_MEMBER_FUNCTION((responseconst), put , tag,
92-
(required
93-
(request,(request))// yes sir, we make a copy of the original request.
94-
)
95-
(optional
96-
(body,(string_typeconst &),string_type())
97-
(content_type,(string_typeconst &),string_type())
98-
(body_handler,(body_callback_function_type),body_callback_function_type())
99-
)
100-
) {
66+
responseconstput(request request, string_typeconst &body = string_type(), string_typeconst &content_type = string_type(), body_callback_function_type body_handler = body_callback_function_type()) {
10167
if (body !=string_type()) {
10268
request <<remove_header("Content-Length")
10369
<<header("Content-Length", boost::lexical_cast<string_type>(body.size()))
@@ -119,14 +85,7 @@ namespace boost { namespace network { namespace http {
11985
return pimpl->request_skeleton(request,"PUT",true, body_handler);
12086
}
12187

122-
BOOST_PARAMETER_MEMBER_FUNCTION((responseconst), delete_, tag,
123-
(required
124-
(request,(requestconst &))
125-
)
126-
(optional
127-
(body_handler,(body_callback_function_type),body_callback_function_type())
128-
)
129-
) {
88+
responseconstdelete_(requestconst &request, body_callback_function_type body_handler = body_callback_function_type()) {
13089
return pimpl->request_skeleton(request,"DELETE",true, body_handler);
13190
}
13291

@@ -141,31 +100,15 @@ namespace boost { namespace network { namespace http {
141100

142101
boost::shared_ptr<pimpl_type> pimpl;
143102

144-
template<classArgPack>
145-
voidinit_pimpl(ArgPackconst & args, no_io_service) {
103+
voidinit_pimpl(client_options<Tag>const & options) {
146104
pimpl.reset(
147105
newpimpl_type(
148-
args[_cache_resolved|false]
149-
, args[_follow_redirects|false]
150-
, optional<string_type>(args[_openssl_certificate|optional<string_type>()])
151-
, optional<string_type>(args[_openssl_verify_path|optional<string_type>()])
152-
)
153-
);
106+
options.cache_resolved(),
107+
options.follow_redirects(),
108+
options.openssl_certificate(),
109+
options.openssl_verify_path(),
110+
options.io_service()));
154111
}
155-
156-
template<classArgPack>
157-
voidinit_pimpl(ArgPackconst & args, has_io_service) {
158-
pimpl.reset(
159-
newpimpl_type(
160-
args[_cache_resolved|false]
161-
, args[_follow_redirects|false]
162-
, args[_io_service]
163-
, optional<string_type>(args[_openssl_certificate|optional<string_type>()])
164-
, optional<string_type>(args[_openssl_verify_path|optional<string_type>()])
165-
)
166-
);
167-
}
168-
169112
};
170113

171114
}// namespace http

‎boost/network/protocol/http/client/parameters.hpp

Lines changed: 0 additions & 29 deletions
This file was deleted.

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

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,8 @@ namespace boost { namespace network { namespace http {
6767
typedeftypename impl::client_base<Tag,version_major,version_minor>::type base_type;
6868
typedeftypename base_type::string_type string_type;
6969

70-
basic_client_impl(bool cache_resolved,bool follow_redirect, optional<string_type>const & certificate_filename, optional<string_type>const & verify_path)
71-
: base_type(cache_resolved, follow_redirect, certificate_filename, verify_path)
72-
{}
73-
74-
basic_client_impl(bool cache_resolved,bool follow_redirect, boost::asio::io_service & service, optional<string_type>const & certificate_filename, optional<string_type>const & verify_path)
75-
: base_type(cache_resolved, follow_redirect, service, certificate_filename, verify_path)
76-
{}
70+
basic_client_impl(bool cache_resolved,bool follow_redirect, optional<string_type>const & certificate_filename, optional<string_type>const & verify_path, boost::shared_ptr<boost::asio::io_service> service)
71+
: base_type(cache_resolved, follow_redirect, service, certificate_filename, verify_path) {}
7772

7873
~basic_client_impl()
7974
{}

‎boost/network/protocol/http/client/sync_impl.hpp

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,38 +22,27 @@ namespace boost { namespace network { namespace http {
2222
typedef function<void(iterator_range<charconst *>const &, system::error_codeconst &)> body_callback_function_type;
2323
friendstructbasic_client_impl<Tag,version_major,version_minor>;
2424

25-
boost::asio::io_service * service_ptr;
25+
boost::shared_ptr<boost::asio::io_service> service_ptr;
2626
boost::asio::io_service & service_;
2727
resolver_type resolver_;
2828
optional<string_type> certificate_file, verify_path;
2929

3030
sync_client(bool cache_resolved,bool follow_redirect
31+
, boost::shared_ptr<boost::asio::io_service> service
3132
, optional<string_type>const & certificate_file = optional<string_type>()
3233
, optional<string_type>const & verify_path = optional<string_type>()
3334
)
3435
: connection_base(cache_resolved, follow_redirect),
35-
service_ptr(newboost::asio::io_service),
36+
service_ptr(service.get() ? service : make_shared<boost::asio::io_service>()),
3637
service_(*service_ptr),
3738
resolver_(service_)
3839
, certificate_file(certificate_file)
3940
, verify_path(verify_path)
4041
{}
4142

42-
sync_client(bool cache_resolved,bool follow_redirect, boost::asio::io_service & service
43-
, optional<string_type>const & certificate_file = optional<string_type>()
44-
, optional<string_type>const & verify_path = optional<string_type>()
45-
)
46-
: connection_base(cache_resolved, follow_redirect),
47-
service_ptr(0),
48-
service_(service),
49-
resolver_(service_)
50-
, certificate_file(certificate_file)
51-
, verify_path(verify_path)
52-
{}
53-
5443
~sync_client() {
5544
connection_base::cleanup();
56-
deleteservice_ptr;
45+
service_ptr.reset();
5746
}
5847

5948
basic_response<Tag>constrequest_skeleton(basic_request<Tag>const & request_, string_type method,bool get_body, body_callback_function_type callback) {

‎libs/network/example/http_client.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ int main(int argc, char * argv[]) {
6262
http_client::string_type destination_ =host(request);
6363

6464
request << ::boost::network::header("Connection","close");
65-
http_clientclient(http::_follow_redirects=true);
65+
http_client::options client_options;
66+
http_clientclient(client_options.follow_redirects(true));
6667
http_client::response response = client.get(request);
6768

6869
if (show_headers) {

‎libs/network/test/http/client_constructor_test.cpp

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,14 @@
1212
namespacehttp= boost::network::http;
1313

1414
BOOST_AUTO_TEST_CASE_TEMPLATE(http_client_constructor_test, client, client_types) {
15+
typename client::options options;
1516
client instance;
16-
boost::asio::io_service io_service;
17-
clientinstance2(io_service);
18-
clientinstance3(http::_io_service=io_service);
17+
clientinstance2(options.io_service(boost::make_shared<boost::asio::io_service>()));
1918
}
2019

2120
BOOST_AUTO_TEST_CASE_TEMPLATE(http_cient_constructor_params_test, client, client_types) {
22-
clientinstance(
23-
http::_follow_redirects=true,
24-
http::_cache_resolved=true
25-
);
26-
boost::asio::io_service io_service;
27-
clientinstance2(
28-
http::_follow_redirects=true,
29-
http::_io_service=io_service,
30-
http::_cache_resolved=true
31-
);
32-
clientinstance3(
33-
http::_openssl_certificate="foo",
34-
http::_openssl_verify_path="bar"
35-
);
21+
typename client::options options;
22+
clientinstance(options.follow_redirects(true).cache_resolved(true));
23+
clientinstance2(options.openssl_certificate("foo").openssl_verify_path("bar"));
24+
clientinstance3(options.follow_redirects(true).io_service(boost::make_shared<boost::asio::io_service>()).cache_resolved(true));
3625
}

‎libs/network/test/http/client_get_streaming_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(http_client_get_streaming_test, client, async_only
3434
body_handlerhandler_instance(body_string);
3535
{
3636
client client_;
37-
BOOST_CHECK_NO_THROW( response = client_.get(request,http::_body_handler=handler_instance) );
37+
BOOST_CHECK_NO_THROW( response = client_.get(request, handler_instance) );
3838
typename net::headers_range<typename client::response>::type range =headers(response)["Content-Type"];
3939
BOOST_CHECK ( !boost::empty(range) );
4040
BOOST_CHECK_EQUAL (body(response).size(),0u );

‎libs/network/test/http/client_get_timeout_test.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,3 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(http_get_test_timeout_1_0, client, client_types) {
2020
BOOST_CHECK_EQUAL (12121, port_ );
2121
BOOST_CHECK_THROW ( response_ = client_.get(request); temp =body(response_); , std::exception );
2222
}
23-

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp