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

Commitd3b68c9

Browse files
committed
Remove dependency on Boost.Parameter from server.
1 parent6da32c4 commitd3b68c9

File tree

10 files changed

+99
-258
lines changed

10 files changed

+99
-258
lines changed

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

Lines changed: 6 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
#include<boost/network/protocol/http/request.hpp>
1414
#include<boost/network/protocol/http/server/sync_server.hpp>
1515
#include<boost/network/protocol/http/server/async_server.hpp>
16-
#include<boost/network/protocol/http/server/parameters.hpp>
1716

1817
namespaceboost {namespacenetwork {namespacehttp {
1918

@@ -40,52 +39,21 @@ namespace boost { namespace network { namespace http {
4039
structserver : server_base<tags::http_server, Handler>::type {
4140
typedeftypename server_base<tags::http_server, Handler>::type
4241
server_base;
42+
typedef server_options<tags::http_server, Handler> options;
4343

44-
BOOST_PARAMETER_CONSTRUCTOR(
45-
server, (server_base), tag,
46-
(required
47-
(address, (typename server_base::string_typeconst &))
48-
(port, (typename server_base::string_typeconst &))
49-
(in_out(handler), (Handler &)))
50-
(optional
51-
(in_out(io_service), (boost::asio::io_service &))
52-
(reuse_address, (bool))
53-
(report_aborted, (bool))
54-
(receive_buffer_size, (int))
55-
(send_buffer_size, (int))
56-
(receive_low_watermark, (int))
57-
(send_low_watermark, (int))
58-
(non_blocking_io, (int))
59-
(linger, (bool))
60-
(linger_timeout, (int)))
61-
)
44+
explicitserver(optionsconst &options)
45+
: server_base(options) {}
6246
};
6347

6448
template<classHandler>
6549
structasync_server : server_base<tags::http_async_server, Handler>::type
6650
{
6751
typedeftypename server_base<tags::http_async_server, Handler>::type
6852
server_base;
53+
typedef server_options<tags::http_async_server, Handler> options;
6954

70-
BOOST_PARAMETER_CONSTRUCTOR(
71-
async_server, (server_base), tag,
72-
(required
73-
(address, (typename server_base::string_typeconst &))
74-
(port, (typename server_base::string_typeconst &))
75-
(in_out(handler), (Handler&))
76-
(in_out(thread_pool), (utils::thread_pool&)))
77-
(optional
78-
(in_out(io_service), (boost::asio::io_service&))
79-
(reuse_address, (bool))
80-
(report_aborted, (bool))
81-
(receive_buffer_size, (int))
82-
(send_buffer_size, (int))
83-
(receive_low_watermark, (int))
84-
(send_low_watermark, (int))
85-
(non_blocking_io, (bool))
86-
(linger, (bool))
87-
(linger_timeout, (int)))
88-
)
55+
explicitasync_server(optionsconst &options)
56+
: server_base(options) {}
8957
};
9058

9159
}// namespace http

‎boost/network/protocol/http/server/async_server.hpp

Lines changed: 41 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -23,29 +23,20 @@ namespace boost { namespace network { namespace http {
2323
typedeftypename boost::network::http::response_header<Tag>::type response_header;
2424
typedef async_connection<Tag,Handler> connection;
2525
typedef shared_ptr<connection> connection_ptr;
26-
typedef boost::unique_lock<boost::mutex> scoped_mutex_lock;
26+
typedef boost::unique_lock<boost::mutex> scoped_mutex_lock;
2727

28-
template<classArgPack>
29-
async_server_base(ArgPackconst & args)
30-
: server_storage_base(args,
31-
typename mpl::if_<
32-
is_same<
33-
typename parameter::value_type<ArgPack, tag::io_service,void>::type,
34-
void
35-
>,
36-
server_storage_base::no_io_service,
37-
server_storage_base::has_io_service
38-
>::type())
39-
, socket_options_base(args)
40-
, handler(args[_handler])
41-
, address_(args[_address])
42-
, port_(args[_port])
43-
, thread_pool(args[_thread_pool])
28+
explicitasync_server_base(server_options<Tag, Handler>const &options)
29+
: server_storage_base(options)
30+
, socket_options_base(options)
31+
, handler(options.handler())
32+
, address_(options.address())
33+
, port_(options.port())
34+
, thread_pool(options.thread_pool() ? options.thread_pool() : boost::make_shared<utils::thread_pool>())
4435
, acceptor(server_storage_base::service_)
4536
, stopping(false)
4637
, new_connection()
4738
, listening_mutex_()
48-
, stopping_mutex_()
39+
, stopping_mutex_()
4940
, listening(false)
5041
{}
5142

@@ -57,19 +48,19 @@ namespace boost { namespace network { namespace http {
5748
voidstop() {
5849
// stop accepting new requests and let all the existing
5950
// handlers finish.
60-
scoped_mutex_locklistening_lock(listening_mutex_);
61-
if (listening) {// we dont bother stopping if we arent currently listening
62-
scoped_mutex_lockstopping_lock(stopping_mutex_);
63-
stopping =true;
64-
system::error_code ignored;
65-
acceptor.close(ignored);
66-
listening =false;
67-
service_.post(boost::bind(&async_server_base::handle_stop,this));
68-
}
51+
scoped_mutex_locklistening_lock(listening_mutex_);
52+
if (listening) {// we dont bother stopping if we arent currently listening
53+
scoped_mutex_lockstopping_lock(stopping_mutex_);
54+
stopping =true;
55+
system::error_code ignored;
56+
acceptor.close(ignored);
57+
listening =false;
58+
service_.post(boost::bind(&async_server_base::handle_stop,this));
59+
}
6960
}
7061

7162
voidlisten() {
72-
scoped_mutex_locklistening_lock(listening_mutex_);
63+
scoped_mutex_locklistening_lock(listening_mutex_);
7364
BOOST_NETWORK_MESSAGE("Listening on" << address_ <<':' << port_);
7465
if (!listening)start_listening();// we only initialize our acceptor/sockets if we arent already listening
7566
if (!listening) {
@@ -81,53 +72,44 @@ namespace boost { namespace network { namespace http {
8172
private:
8273
Handler & handler;
8374
string_type address_, port_;
84-
utils::thread_pool & thread_pool;
75+
boost::shared_ptr<utils::thread_pool> thread_pool;
8576
asio::ip::tcp::acceptor acceptor;
8677
bool stopping;
8778
connection_ptr new_connection;
8879
boost::mutex listening_mutex_;
89-
boost::mutex stopping_mutex_;
80+
boost::mutex stopping_mutex_;
9081
bool listening;
91-
92-
voidhandle_stop() {
93-
scoped_mutex_lockstopping_lock(stopping_mutex_);
94-
if (stopping) service_.stop();// a user may have started listening again before the stop command is reached
95-
}
82+
83+
voidhandle_stop() {
84+
scoped_mutex_lockstopping_lock(stopping_mutex_);
85+
if (stopping) service_.stop();// a user may have started listening again before the stop command is reached
86+
}
9687

9788
voidhandle_accept(boost::system::error_codeconst & ec) {
98-
{
99-
scoped_mutex_lockstopping_lock(stopping_mutex_);
100-
if (stopping)return;// we dont want to add another handler instance, and we dont want to know about errors for a socket we dont need anymore
101-
}
89+
{
90+
scoped_mutex_lockstopping_lock(stopping_mutex_);
91+
if (stopping)return;// we dont want to add another handler instance, and we dont want to know about errors for a socket we dont need anymore
92+
}
10293
if (!ec) {
10394
socket_options_base::socket_options(new_connection->socket());
10495
new_connection->start();
10596
new_connection.reset(
106-
newconnection(
107-
service_
108-
, handler
109-
, thread_pool
110-
)
111-
);
112-
acceptor.async_accept(new_connection->socket(),
113-
boost::bind(
114-
&async_server_base<Tag,Handler>::handle_accept
115-
,this
116-
, boost::asio::placeholders::error
117-
)
118-
);
97+
newconnection(service_, handler, *thread_pool));
98+
acceptor.async_accept(
99+
new_connection->socket(),
100+
boost::bind(
101+
&async_server_base<Tag,Handler>::handle_accept,
102+
this,
103+
boost::asio::placeholders::error));
119104
}else {
120105
BOOST_NETWORK_MESSAGE("Error accepting connection, reason:" << ec);
121106
}
122107
}
123108

124109
voidstart_listening() {
125110
using boost::asio::ip::tcp;
126-
127111
system::error_code error;
128-
129-
service_.reset();// this allows repeated cycles of run -> stop -> run
130-
112+
service_.reset();// this allows repeated cycles of run -> stop -> run
131113
tcp::resolverresolver(service_);
132114
tcp::resolver::queryquery(address_, port_);
133115
tcp::resolver::iterator endpoint_iterator = resolver.resolve(query, error);
@@ -152,15 +134,15 @@ namespace boost { namespace network { namespace http {
152134
BOOST_NETWORK_MESSAGE("Error listening on socket: '" << error <<"' on" << address_ <<":" << port_);
153135
return;
154136
}
155-
new_connection.reset(newconnection(service_, handler, thread_pool));
137+
new_connection.reset(newconnection(service_, handler,*thread_pool));
156138
acceptor.async_accept(new_connection->socket(),
157139
boost::bind(
158140
&async_server_base<Tag,Handler>::handle_accept
159141
,this
160142
, boost::asio::placeholders::error));
161143
listening =true;
162-
scoped_mutex_lockstopping_lock(stopping_mutex_);
163-
stopping =false;// if we were in the process of stopping, we revoke that command and continue listening
144+
scoped_mutex_lockstopping_lock(stopping_mutex_);
145+
stopping =false;// if we were in the process of stopping, we revoke that command and continue listening
164146
BOOST_NETWORK_MESSAGE("Now listening on socket: '" << address_ <<":" << port_ <<"'");
165147
}
166148
};

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

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

‎boost/network/protocol/http/server/socket_options_base.hpp

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

9-
#include<boost/network/protocol/http/server/parameters.hpp>
10-
#include<boost/optional.hpp>
119
#include<boost/utility/in_place_factory.hpp>
1210

1311
namespaceboost {namespacenetwork {namespacehttp {
@@ -23,18 +21,17 @@ namespace boost { namespace network { namespace http {
2321
asio::socket_base::non_blocking_io non_blocking_io;
2422
asio::socket_base::linger linger;
2523

26-
template<classArgPack>
27-
socket_options_base(ArgPackconst & args)
28-
: acceptor_reuse_address(args[_reuse_address|false])
29-
, acceptor_report_aborted(args[_report_aborted|false])
30-
, non_blocking_io(args[_non_blocking_io|true])
31-
, linger(args[_linger|true], args[_linger_timeout|0])
32-
{
33-
set_optional(receive_buffer_size, args, _receive_buffer_size);
34-
set_optional(send_buffer_size, args, _send_buffer_size);
35-
set_optional(receive_low_watermark, args, _receive_low_watermark);
36-
set_optional(send_low_watermark, args, _send_low_watermark);
37-
}
24+
template<classTag,classHandler>
25+
explicitsocket_options_base(server_options<Tag, Handler>const &options)
26+
: acceptor_reuse_address(options.reuse_address())
27+
, acceptor_report_aborted(options.report_aborted())
28+
, receive_buffer_size(options.receive_buffer_size())
29+
, send_buffer_size(options.send_buffer_size())
30+
, receive_low_watermark(options.receive_low_watermark())
31+
, send_low_watermark(options.send_low_watermark())
32+
, non_blocking_io(options.non_blocking_io())
33+
, linger(options.linger(), options.linger_timeout())
34+
{}
3835

3936
voidacceptor_options(boost::asio::ip::tcp::acceptor & acceptor) {
4037
acceptor.set_option(acceptor_reuse_address);
@@ -50,35 +47,6 @@ namespace boost { namespace network { namespace http {
5047
if (send_buffer_size) socket.set_option(*send_buffer_size, ignored);
5148
if (send_low_watermark) socket.set_option(*send_low_watermark, ignored);
5249
}
53-
54-
private:
55-
56-
template<classOptional,classArgs,classKeyword>
57-
typename boost::enable_if<
58-
mpl::not_<
59-
boost::is_same<
60-
typename boost::parameter::value_type<Args, Keyword,void>::type
61-
,void
62-
>
63-
>
64-
,void
65-
>::type
66-
set_optional(Optional & option, Argsconst & args, Keywordconst & keyword) {
67-
option = in_place<typename Optional::value_type>(args[keyword]);
68-
}
69-
70-
template<classOptional,classArgs,classKeyword>
71-
typename boost::enable_if<
72-
boost::is_same<
73-
typename boost::parameter::value_type<Args, Keyword,void>::type
74-
,void
75-
>
76-
,void
77-
>::type
78-
set_optional(Optional &, Argsconst &, Keywordconst &) {
79-
// do nothing
80-
}
81-
8250
};
8351

8452
}/* http*/

‎boost/network/protocol/http/server/storage_base.hpp

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

9-
#include<boost/network/protocol/http/server/parameters.hpp>
9+
#include<boost/shared_ptr.hpp>
10+
#include<boost/make_shared.hpp>
11+
#include<boost/network/protocol/http/server/options.hpp>
1012

1113
namespaceboost {namespacenetwork {namespacehttp {
1214

1315
structserver_storage_base {
1416
structno_io_service {};
1517
structhas_io_service {};
1618
protected:
17-
template<classArgPack>
18-
server_storage_base(ArgPackconst &/* args*/, no_io_service)
19-
: self_service_(newboost::asio::io_service())
19+
template<classTag,classHandler>
20+
explicitserver_storage_base(server_options<Tag, Handler>const &options)
21+
: self_service_(options.io_service()? options.io_service() :boost::make_shared<boost::asio::io_service>())
2022
, service_(*self_service_)
2123
{}
2224

23-
template<classArgPack>
24-
server_storage_base(ArgPackconst & args, has_io_service)
25-
: self_service_(0)
26-
, service_(args[_io_service])
27-
{}
28-
29-
~server_storage_base() {
30-
delete self_service_;
31-
self_service_ =0;
32-
}
33-
34-
asio::io_service * self_service_;
25+
boost::shared_ptr<asio::io_service> self_service_;
3526
asio::io_service & service_;
3627
};
3728

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp