Skip to content

Commit 8f26ea8

Browse files
committed
Get one test to build.
This set of changes gets one of the server tests (async_run_stop_concurrency) to build correctly.
1 parent 7d35dc6 commit 8f26ea8

File tree

9 files changed

+337
-88
lines changed

9 files changed

+337
-88
lines changed

boost/network/include/http/server.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
//
99
// This is the modular include file for using the HTTP Client
1010

11+
#include <boost/asio/io_service.hpp>
1112
#include <boost/network/protocol/http/server.hpp>
13+
#include <boost/network/utils/thread_pool.hpp>
14+
#include <boost/network/detail/debug.hpp>
1215

1316
#endif
Lines changed: 62 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,98 +1,80 @@
1-
// Copyright 2009 (c) Tarro, Inc.
2-
// Copyright 2009 (c) Dean Michael Berris <mikhailberis@gmail.com>
3-
// Copyright 2010 (c) Glyn Matthews
4-
// Copyright 2003-2008 (c) Chris Kholhoff
1+
// Copyright 2009 Tarroo, Inc.
2+
// Copyright 2010 Glyn Matthews
3+
// Copyright 2003-2008 Chris Kholhoff
4+
// Copyright 2009-2012 Dean Michael Berris <dberris@gmail.com>
5+
// Copyright 2012 Google, Inc.
56
// Distributed under the Boost Software License, Version 1.0.
67
// (See accompanying file LICENSE_1_0.txt or copy at
78
// http://www.boost.org/LICENSE_1_0.txt)
89

910
#ifndef BOOST_NETWORK_HTTP_SERVER_HPP_
1011
#define BOOST_NETWORK_HTTP_SERVER_HPP_
1112

12-
#include <boost/network/protocol/http/response.hpp>
13-
#include <boost/network/protocol/http/request.hpp>
14-
#include <boost/network/protocol/http/server/sync_server.hpp>
15-
#include <boost/network/protocol/http/server/async_server.hpp>
16-
#include <boost/network/protocol/http/server/parameters.hpp>
13+
#include <boost/shared_ptr.hpp>
14+
15+
namespace boost { namespace network { namespace utils {
16+
17+
struct thread_pool;
18+
19+
} // namespace utils
20+
21+
} // namespace network
22+
23+
} // namespace boost
1724

1825
namespace boost { namespace network { namespace http {
19-
20-
template <class Tag, class Handler, class Enable = void>
21-
struct server_base {
22-
typedef unsupported_tag<Tag> type;
23-
};
24-
25-
template <class Tag, class Handler>
26-
struct server_base<Tag, Handler, typename enable_if<is_async<Tag> >::type> {
27-
typedef async_server_base<Tag, Handler> type;
28-
};
29-
30-
template <class Tag, class Handler>
31-
struct server_base<Tag, Handler, typename enable_if<is_sync<Tag> >::type> {
32-
typedef sync_server_base<Tag, Handler> type;
33-
};
34-
35-
template <class Tag, class Handler>
36-
struct basic_server : server_base<Tag, Handler>::type
37-
{};
38-
39-
template <class Handler>
40-
struct server : server_base<tags::http_server, Handler>::type {
41-
typedef typename server_base<tags::http_server, Handler>::type
42-
server_base;
43-
44-
BOOST_PARAMETER_CONSTRUCTOR(
45-
server, (server_base), tag,
46-
(required
47-
(address, (typename server_base::string_type const &))
48-
(port, (typename server_base::string_type const &))
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-
)
62-
};
63-
64-
template <class Handler>
65-
struct async_server : server_base<tags::http_async_server, Handler>::type
66-
{
67-
typedef typename server_base<tags::http_async_server, Handler>::type
68-
server_base;
69-
70-
BOOST_PARAMETER_CONSTRUCTOR(
71-
async_server, (server_base), tag,
72-
(required
73-
(address, (typename server_base::string_type const &))
74-
(port, (typename server_base::string_type const &))
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-
)
89-
};
26+
27+
class server_options;
28+
class sync_server_impl;
29+
class async_server_impl;
30+
class async_server_connection;
31+
struct request;
32+
struct response;
33+
34+
35+
template <class SyncHandler>
36+
class sync_server {
37+
public:
38+
sync_server(server_options const &options, SyncHandler &handler);
39+
void run();
40+
void stop();
41+
void listen();
42+
~sync_server();
43+
44+
typedef http::request request;
45+
typedef http::response response;
46+
private:
47+
sync_server_impl *pimpl_;
48+
sync_server(sync_server const &other); // = delete
49+
sync_server& operator=(sync_server other); // = delete
50+
};
51+
52+
template <class AsyncHandler>
53+
class async_server {
54+
public:
55+
explicit async_server(server_options const &options, AsyncHandler &handler, utils::thread_pool &pool);
56+
void run();
57+
void stop();
58+
void listen();
59+
~async_server();
60+
61+
typedef http::request request;
62+
typedef shared_ptr<async_server_connection> connection_ptr;
63+
private:
64+
async_server_impl *pimpl_;
65+
async_server(async_server const &other); // = delete
66+
async_server& operator=(async_server other); // = delete
67+
};
9068

9169
} // namespace http
9270

9371
} // namespace network
9472

9573
} // namespace boost
9674

75+
// We're hiding the implementation from here, but still explicitly including
76+
// it here. This is mostly a style point, to keep this header clean.
77+
#include <boost/network/protocol/http/server/server.ipp>
78+
9779
#endif // BOOST_NETWORK_HTTP_SERVER_HPP_
9880

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#ifndef BOOST_NETWORK_PROTOCOL_HTTP_SERVER_ASYNC_IMPL_20120318
2+
#define BOOST_NETWORK_PROTOCOL_HTTP_SERVER_ASYNC_IMPL_20120318
3+
4+
// Copyright 2012 Dean Michael Berris <dberris@google.com>.
5+
// Copyright 2012 Google, Inc.
6+
// Distributed under the Boost Software License, Version 1.0.
7+
// (See accompanying file LICENSE_1_0.txt or copy at
8+
// http://www.boost.org/LICENSE_1_0.txt)
9+
10+
#include <boost/function.hpp>
11+
#include <boost/shared_ptr.hpp>
12+
13+
namespace boost { namespace network { namespace utils {
14+
15+
struct thread_pool;
16+
17+
} // namespace util
18+
19+
} // namespace network
20+
21+
} // namespace boost
22+
23+
namespace boost { namespace network { namespace http {
24+
25+
class async_server_connection;
26+
27+
class async_server_impl {
28+
public:
29+
typedef shared_ptr<async_server_connection> connection_ptr;
30+
async_server_impl(server_options const &options,
31+
function<void(request const &, connection_ptr)> handler,
32+
utils::thread_pool &thread_pool);
33+
void run();
34+
void stop();
35+
void listen();
36+
37+
private:
38+
server_options options_;
39+
std::string address_, port_;
40+
asio::io_service *service_;
41+
asio::ip::tcp::acceptor *acceptor_;
42+
shared_ptr<async_server_connection> new_connection_;
43+
mutex listening_mutex_;
44+
bool listening_, owned_service_;
45+
function<void(request const &, connection_ptr)> handler_;
46+
utils::thread_pool &pool_;
47+
};
48+
49+
} // namespace http
50+
51+
} // namespace network
52+
53+
} // namespace boost
54+
55+
#endif // BOOST_NETWORK_PROTOCOL_HTTP_SERVER_ASYNC_IMPL_20120318
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
#ifndef BOOST_NETWORK_PROTOCOL_HTTP_SERVER_OPTIONS_HPP_20120318
2+
#define BOOST_NETWORK_PROTOCOL_HTTP_SERVER_OPTIONS_HPP_20120318
3+
4+
// Copyright 2012 Dean Michael Berris <dberris@google.com>.
5+
// Copyright 2012 Google, Inc.
6+
// Distributed under the Boost Software License, Version 1.0.
7+
// (See accompanying file LICENSE_1_0.txt or copy at
8+
// http://www.boost.org/LICENSE_1_0.txt)
9+
10+
#include <string>
11+
12+
namespace boost { namespace asio {
13+
14+
class io_service;
15+
16+
} // namespace asio
17+
18+
} // namespace boost
19+
20+
namespace boost { namespace network { namespace http {
21+
22+
class server_options_pimpl;
23+
24+
class server_options {
25+
public:
26+
server_options();
27+
server_options(server_options const &other);
28+
void swap(server_options &other);
29+
server_options& operator=(server_options rhs);
30+
31+
server_options& address(std::string const &address="0.0.0.0");
32+
std::string const address() const;
33+
34+
server_options& port(std::string const &port="80");
35+
std::string const port() const;
36+
37+
server_options& io_service(asio::io_service *service = 0);
38+
asio::io_service *io_service() const;
39+
40+
server_options& reuse_address(bool setting=true);
41+
bool reuse_address();
42+
43+
server_options& report_aborted(bool setting=false);
44+
bool report_aborted();
45+
46+
// Set the receive buffer size for a socket. -1 means just use the default.
47+
server_options& receive_buffer_size(int buffer_size=-1);
48+
int receive_buffer_size();
49+
50+
// Set the send buffer size for a socket. -1 means just use the default.
51+
server_options& send_buffer_size(int buffer_size=-1);
52+
int send_buffer_size();
53+
54+
// Set the receive low watermark for a socket. -1 means just use the default.
55+
server_options& receive_low_watermark(int low_watermark=-1);
56+
int receive_low_watermark();
57+
58+
// Set the send low watermark for a socket. -1 means just use the default.
59+
server_options& send_low_watermark(int low_watermark=-1);
60+
int send_low_watermark();
61+
62+
server_options& non_blocking_io(bool setting=true);
63+
bool non_blocking_io();
64+
65+
server_options& linger(bool setting=false);
66+
bool linger();
67+
68+
// Set the socket linger timeout. This is only relevant if linger is true
69+
// (see linger above). -1 means just use the default.
70+
server_options& linger_timeout(int setting=-1);
71+
int linger_timeout();
72+
73+
private:
74+
server_options_pimpl *pimpl_;
75+
};
76+
77+
} // namespace http
78+
79+
} // namespace network
80+
81+
} // namespace boost
82+
83+
#endif // BOOST_NETWORK_PROTOCOL_HTTP_SERVER_OPTIONS_HPP_20120318
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#ifndef BOOST_NETWORK_PROTOCOL_HTTP_SERVER_SERVER_IPP_20120318
2+
#define BOOST_NETWORK_PROTOCOL_HTTP_SERVER_SERVER_IPP_20120318
3+
4+
// Copyright 2012 Dean Michael Berris <dberris@google.com>.
5+
// Copyright 2012 Google, Inc.
6+
// Distributed under the Boost Software License, Version 1.0.
7+
// (See accompanying file LICENSE_1_0.txt or copy at
8+
// http://www.boost.org/LICENSE_1_0.txt)
9+
10+
#include <boost/network/protocol/http/server/options.hpp>
11+
#include <boost/network/protocol/http/server/sync_impl.hpp>
12+
#include <boost/network/protocol/http/server/async_impl.hpp>
13+
14+
namespace boost { namespace network { namespace http {
15+
16+
template <class SyncHandler>
17+
sync_server<SyncHandler>::sync_server(server_options const &options, SyncHandler &handler)
18+
: pimpl_(new sync_server_impl(options, handler))
19+
{}
20+
21+
template <class SyncHandler>
22+
void sync_server<SyncHandler>::run() {
23+
pimpl_->run();
24+
}
25+
26+
template <class SyncHandler>
27+
void sync_server<SyncHandler>::stop() {
28+
pimpl_->stop();
29+
}
30+
31+
template <class SyncHandler>
32+
void sync_server<SyncHandler>::listen() {
33+
pimpl_->listen();
34+
}
35+
36+
template <class SyncHandler>
37+
sync_server<SyncHandler>::~sync_server() {
38+
delete pimpl_;
39+
}
40+
41+
template <class AsyncHandler>
42+
async_server<AsyncHandler>::async_server(server_options const &options, AsyncHandler &handler, utils::thread_pool &pool)
43+
: pimpl_(new async_server_impl(options, handler, pool))
44+
{}
45+
46+
template <class AsyncHandler>
47+
void async_server<AsyncHandler>::run() {
48+
pimpl_->run();
49+
}
50+
51+
template <class AsyncHandler>
52+
void async_server<AsyncHandler>::stop() {
53+
pimpl_->stop();
54+
}
55+
56+
template <class AsyncHandler>
57+
void async_server<AsyncHandler>::listen() {
58+
pimpl_->listen();
59+
}
60+
61+
template <class SyncHandler>
62+
async_server<SyncHandler>::~async_server() {
63+
delete pimpl_;
64+
}
65+
66+
} // namespace http
67+
68+
} // namespace network
69+
70+
} // namespace boost
71+
72+
#endif // BOOST_NETWORK_PROTOCOL_HTTP_SERVER_SERVER_IPP_20120318

0 commit comments

Comments
 (0)