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

Commit961f68d

Browse files
committed
Stubbed out initial look of the Asynchonous Server implementation.
1 parentf347a5f commit961f68d

File tree

11 files changed

+331
-64
lines changed

11 files changed

+331
-64
lines changed

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

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,13 @@ namespace boost { namespace network { namespace http {
115115
* primarily and be solely a POD for performance
116116
* reasons.
117117
*/
118-
template<>
119-
structbasic_request<tags::http_server> {
120-
typedef tags::http_server tag;
121-
typedef string<tags::http_server>::type string_type;
122-
typedef vector<tags::http_server>::apply<request_header>::type vector_type;
118+
template<classTag>
119+
structpod_request_base {
120+
typedef Tag tag;
121+
typedeftypename string<Tag>::type string_type;
122+
typedeftypename vector<tags::http_server>::
123+
templateapply<request_header>::type
124+
vector_type;
123125
typedef vector_type headers_container_type;
124126
typedef boost::uint16_t port_type;
125127
mutable string_type source;
@@ -130,7 +132,7 @@ namespace boost { namespace network { namespace http {
130132
mutable vector_type headers;
131133
mutable string_type body;
132134

133-
voidswap(basic_request & r)const {
135+
voidswap(pod_request_base & r)const {
134136
using std::swap;
135137
swap(method, r.method);
136138
swap(source, r.source);
@@ -142,6 +144,12 @@ namespace boost { namespace network { namespace http {
142144
}
143145
};
144146

147+
template<>
148+
structbasic_request<tags::http_async_server> : pod_request_base<tags::http_async_server> {};
149+
150+
template<>
151+
structbasic_request<tags::http_server> : pod_request_base<tags::http_server> {};
152+
145153
template<classTag>
146154
inlinevoidswap(basic_request<Tag> & lhs, basic_request<Tag> & rhs) {
147155
lhs.swap(rhs);
@@ -155,6 +163,11 @@ namespace boost { namespace network { namespace http {
155163
vector<http::tags::http_server>::apply<http::request_header>
156164
{};
157165

166+
template<>
167+
structheaders_container<http::tags::http_async_server> :
168+
vector<http::tags::http_async_server>::apply<http::request_header>
169+
{};
170+
158171
namespacehttp {namespaceimpl {
159172

160173
template<>
@@ -179,6 +192,28 @@ namespace boost { namespace network { namespace http {
179192
}
180193
};
181194

195+
template<>
196+
structrequest_headers_wrapper<tags::http_async_server> {
197+
basic_request<tags::http_async_server>const & request_;
198+
request_headers_wrapper(basic_request<tags::http_async_server>const & request_)
199+
: request_(request_) {}
200+
typedef headers_container<tags::http_async_server>::type headers_container_type;
201+
operatorheaders_container_type () {
202+
return request_.headers;
203+
}
204+
};
205+
206+
template<>
207+
structbody_wrapper<basic_request<tags::http_async_server> > {
208+
typedef string<tags::http_async_server>::type string_type;
209+
basic_request<tags::http_async_server>const & request_;
210+
body_wrapper(basic_request<tags::http_async_server>const & request_)
211+
: request_(request_) {}
212+
operatorstring_type () {
213+
return request_.body;
214+
}
215+
};
216+
182217
}// namespace impl
183218

184219
}// namespace http

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

Lines changed: 32 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
// Distributed under the Boost Software License, Version 1.0.
66
// (See accompanying file LICENSE_1_0.txt or copy at
77
// http://www.boost.org/LICENSE_1_0.txt)
8-
//
98

109
#ifndef BOOST_NETWORK_HTTP_SERVER_HPP_
1110
#defineBOOST_NETWORK_HTTP_SERVER_HPP_
@@ -17,65 +16,32 @@
1716
#include<boost/network/protocol/http/request.hpp>
1817
#include<boost/network/protocol/http/connection.hpp>
1918
#include<boost/network/traits/string.hpp>
19+
#include<boost/network/protocol/http/server/sync_server.hpp>
20+
#include<boost/network/protocol/http/server/async_server.hpp>
2021

2122
namespaceboost {namespacenetwork {namespacehttp {
2223

2324
template<classTag,classHandler>
24-
structbasic_server {
25-
typedeftypename string<Tag>::type string_type;
26-
typedef basic_request<Tag> request;
27-
typedef basic_response<Tag> response;
25+
structserver_base :
26+
mpl::if_<
27+
is_async<Tag>
28+
, async_server_base<Tag, Handler>
29+
,typename mpl::if_<
30+
is_sync<Tag>
31+
, sync_server_base<Tag, Handler>
32+
, unsupported_tag<Tag>
33+
>::type
34+
>
35+
{};
2836

29-
basic_server(string_typeconst & address,
30-
string_typeconst & port,
31-
Handler & handler)
32-
: handler_(handler)
33-
, service_()
34-
, acceptor_(service_)
35-
, new_connection(new connection<Tag,Handler>(service_, handler))
36-
{
37-
using boost::asio::ip::tcp;
38-
tcp::resolverresolver(service_);
39-
tcp::resolver::queryquery(address, port);
40-
tcp::endpoint endpoint = *resolver.resolve(query);
41-
acceptor_.open(endpoint.protocol());
42-
acceptor_.bind(endpoint);
43-
acceptor_.listen();
44-
acceptor_.async_accept(new_connection->socket(),
45-
boost::bind(&basic_server<Tag,Handler>::handle_accept,
46-
this, boost::asio::placeholders::error));
47-
}
48-
49-
voidrun() {
50-
service_.run();
51-
}
52-
53-
voidstop() {
54-
// TODO Graceful stop here?
55-
service_.stop();
56-
}
57-
58-
private:
59-
60-
Handler & handler_;
61-
boost::asio::io_service service_;
62-
boost::asio::ip::tcp::acceptor acceptor_;
63-
boost::shared_ptr<connection<Tag,Handler> > new_connection;
64-
65-
voidhandle_accept(boost::system::error_codeconst & ec) {
66-
if (!ec) {
67-
new_connection->start();
68-
new_connection.reset(new connection<Tag,Handler>(service_, handler_));
69-
acceptor_.async_accept(new_connection->socket(),
70-
boost::bind(&basic_server<Tag,Handler>::handle_accept,
71-
this, boost::asio::placeholders::error));
72-
}
73-
}
74-
};
37+
template<classTag,classHandler>
38+
structbasic_server : server_base<Tag, Handler>::type
39+
{};
7540

7641
template<classHandler>
77-
structserver : basic_server<tags::http_server, Handler> {
78-
typedef basic_server<tags::http_server, Handler> server_base;
42+
structserver : server_base<tags::http_server, Handler>::type {
43+
typedeftypename server_base<tags::http_server, Handler>::type
44+
server_base;
7945

8046
server(typename server_base::string_typeconst & address,
8147
typename server_base::string_typeconst & port,
@@ -84,6 +50,19 @@ namespace boost { namespace network { namespace http {
8450

8551
};
8652

53+
template<classHandler>
54+
structasync_server : server_base<tags::http_async_server, Handler>::type
55+
{
56+
typedeftypename server_base<tags::http_async_server, Handler>::type
57+
server_base;
58+
59+
async_server(typename server_base::string_typeconst & address,
60+
typename server_base::string_typeconst & port,
61+
Handler & handler,
62+
utils::thread_pool & thread_pool)
63+
: server_base(address, port, handler, thread_pool) {}
64+
};
65+
8766
}// namespace http
8867

8968
}// namespace network
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#ifndef BOOST_NETWORK_PROTOCOL_HTTP_SERVER_CONNECTION_HPP_20101027
2+
#defineBOOST_NETWORK_PROTOCOL_HTTP_SERVER_CONNECTION_HPP_20101027
3+
4+
// Copyright 2010 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+
namespaceboost {namespacenetwork {namespacehttp {
10+
11+
template<classTag,classHandler>
12+
structasync_connection {
13+
enumstatus_t {
14+
ok =200
15+
, method_not_supported =306
16+
};
17+
template<classRange>
18+
voidset_headers(Range);
19+
voidset_status(status_t);
20+
template<classRange>
21+
voidwrite(Range);
22+
voidflush();
23+
voidclose();
24+
};
25+
26+
}/* http*/
27+
28+
}/* network*/
29+
30+
}/* boost*/
31+
32+
#endif/* BOOST_NETWORK_PROTOCOL_HTTP_SERVER_CONNECTION_HPP_20101027*/
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#ifndef BOOST_NETWORK_PROTOCOL_HTTP_SERVER_ASYNC_SERVER_HPP_20101025
2+
#defineBOOST_NETWORK_PROTOCOL_HTTP_SERVER_ASYNC_SERVER_HPP_20101025
3+
4+
// Copyright 2010 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/protocol/http/server/async_connection.hpp>
10+
#include<boost/network/protocol/http/server/header.hpp>
11+
#include<boost/network/utils/thread_pool.hpp>
12+
13+
namespaceboost {namespacenetwork {namespacehttp {
14+
15+
template<classTag,classHandler>
16+
structasync_server_base {
17+
typedef basic_request<Tag> request;
18+
typedef basic_response<Tag> response;
19+
typedef async_connection<Tag, Handler> connection;
20+
typedef response_header<Tag> response_header;
21+
typedeftypename string<Tag>::type string_type;
22+
23+
async_server_base(string_typeconst & address
24+
, string_typeconst & port
25+
, Handler & handler
26+
, utils::thread_pool & thread_pool)
27+
{}
28+
29+
voidrun() {};
30+
31+
};
32+
33+
}/* http*/
34+
35+
}/* network*/
36+
37+
}/* boost*/
38+
39+
#endif/* BOOST_NETWORK_PROTOCOL_HTTP_SERVER_ASYNC_SERVER_HPP_20101025*/
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#ifndef BOOST_NETWORK_PROTOCOL_HTTP_SERVER_HEADER_HPP_20101027
2+
#defineBOOST_NETWORK_PROTOCOL_HTTP_SERVER_HEADER_HPP_20101027
3+
4+
// Copyright 2010 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/traits/string.hpp>
10+
#include<algorithm>
11+
12+
namespaceboost {namespacenetwork {namespacehttp {
13+
14+
template<classTag>
15+
structresponse_header {
16+
typedeftypename string<Tag>::type string_type;
17+
string_type name, value;
18+
};
19+
20+
21+
template<classTag>
22+
voidswap(response_header<Tag> & l, response_header<Tag> & r) {
23+
std::swap(l.name, r.name);
24+
std::swap(l.value, r.value);
25+
}
26+
27+
}/* http*/
28+
29+
}/* network*/
30+
31+
}/* boost*/
32+
33+
#endif/* BOOST_NETWORK_PROTOCOL_HTTP_SERVER_HEADER_HPP_20101027*/
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
2+
// Copyright 2010 Dean Michael Berris.
3+
// Copyright 2010 Glyn Matthews.
4+
// Distributed under the Boost Software License, Version 1.0.
5+
// (See accompanying file LICENSE_1_0.txt or copy at
6+
// http://www.boost.org/LICENSE_1_0.txt)
7+
8+
#ifndef BOOST_NETWORK_PROTOCOL_HTTP_SERVER_SYNC_SERVER_HPP_20101025
9+
#defineBOOST_NETWORK_PROTOCOL_HTTP_SERVER_SYNC_SERVER_HPP_20101025
10+
11+
#include<boost/shared_ptr.hpp>
12+
#include<boost/bind.hpp>
13+
#include<boost/asio/ip/tcp.hpp>
14+
#include<boost/network/protocol/http/response.hpp>
15+
#include<boost/network/protocol/http/request.hpp>
16+
#include<boost/network/protocol/http/connection.hpp>
17+
#include<boost/network/traits/string.hpp>
18+
19+
namespaceboost {namespacenetwork {namespacehttp {
20+
21+
template<classTag,classHandler>
22+
structsync_server_base {
23+
typedeftypename string<Tag>::type string_type;
24+
typedef basic_request<Tag> request;
25+
typedef basic_response<Tag> response;
26+
27+
sync_server_base(string_typeconst & address,
28+
string_typeconst & port,
29+
Handler & handler)
30+
: handler_(handler)
31+
, service_()
32+
, acceptor_(service_)
33+
, new_connection(new connection<Tag,Handler>(service_, handler))
34+
{
35+
using boost::asio::ip::tcp;
36+
tcp::resolverresolver(service_);
37+
tcp::resolver::queryquery(address, port);
38+
tcp::endpoint endpoint = *resolver.resolve(query);
39+
acceptor_.open(endpoint.protocol());
40+
acceptor_.bind(endpoint);
41+
acceptor_.listen();
42+
acceptor_.async_accept(new_connection->socket(),
43+
boost::bind(&sync_server_base<Tag,Handler>::handle_accept,
44+
this, boost::asio::placeholders::error));
45+
}
46+
47+
voidrun() {
48+
service_.run();
49+
}
50+
51+
voidstop() {
52+
// TODO Graceful stop here?
53+
service_.stop();
54+
}
55+
56+
private:
57+
58+
Handler & handler_;
59+
boost::asio::io_service service_;
60+
boost::asio::ip::tcp::acceptor acceptor_;
61+
boost::shared_ptr<connection<Tag,Handler> > new_connection;
62+
63+
voidhandle_accept(boost::system::error_codeconst & ec) {
64+
if (!ec) {
65+
new_connection->start();
66+
new_connection.reset(new connection<Tag,Handler>(service_, handler_));
67+
acceptor_.async_accept(new_connection->socket(),
68+
boost::bind(&sync_server_base<Tag,Handler>::handle_accept,
69+
this, boost::asio::placeholders::error));
70+
}
71+
}
72+
};
73+
74+
}/* http*/
75+
76+
}/* network*/
77+
78+
}/* boost*/
79+
80+
#endif/* BOOST_NETWORK_PROTOCOL_HTTP_SERVER_SYNC_SERVER_HPP_20101025*/

‎boost/network/protocol/http/traits/vector.hpp‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,16 @@ namespace boost { namespace network {
2121

2222
};
2323

24+
template<>
25+
structvector<http::tags::http_async_server> {
26+
27+
template<classType>
28+
structapply {
29+
typedef std::vector<Type> type;
30+
};
31+
32+
};
33+
2434
}/* network*/
2535

2636
}/* boost*/

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp