Skip to content

Commit 19d6973

Browse files
committed
Updated server and connection so that they don't use the using directives at namespace scope.
1 parent 9d71407 commit 19d6973

File tree

3 files changed

+65
-70
lines changed

3 files changed

+65
-70
lines changed

boost/network/protocol/http/connection.hpp

Lines changed: 24 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -30,29 +30,18 @@
3030

3131
namespace boost { namespace network { namespace http {
3232

33-
using boost::asio::io_service;
34-
namespace system = boost::system;
35-
using boost::asio::ip::tcp;
36-
using boost::array;
37-
using boost::tribool;
38-
using boost::tuple;
39-
namespace tuples = boost::tuples;
40-
using boost::tuples::tie;
41-
using boost::bind;
42-
using boost::to_lower_copy;
43-
4433
template <class Tag, class Handler>
4534
struct connection : boost::enable_shared_from_this<connection<Tag,Handler> > {
4635

47-
connection(io_service & service, Handler & handler)
36+
connection(boost::asio::io_service & service, Handler & handler)
4837
: service_(service)
4938
, handler_(handler)
5039
, socket_(service_)
5140
, wrapper_(service_)
5241
{
5342
}
5443

55-
tcp::socket & socket() {
44+
boost::asio::ip::tcp::socket & socket() {
5645
return socket_;
5746
}
5847

@@ -62,13 +51,14 @@ namespace boost { namespace network { namespace http {
6251
// and then pass that request object to the
6352
// handler_ instance.
6453
//
54+
using boost::asio::ip::tcp;
6555
boost::system::error_code option_error;
6656
socket_.set_option(tcp::no_delay(true), option_error);
67-
if (option_error) handler_.log(system::system_error(option_error).what());
57+
if (option_error) handler_.log(boost::system::system_error(option_error).what());
6858
socket_.async_read_some(
6959
boost::asio::buffer(buffer_),
7060
wrapper_.wrap(
71-
bind(
61+
boost::bind(
7262
&connection<Tag,Handler>::handle_read_headers,
7363
connection<Tag,Handler>::shared_from_this(),
7464
boost::asio::placeholders::error,
@@ -83,14 +73,14 @@ namespace boost { namespace network { namespace http {
8373
struct is_content_length {
8474
template <class Header>
8575
bool operator()(Header const & header) {
86-
return to_lower_copy(header.name) == "content-length";
76+
return boost::to_lower_copy(header.name) == "content-length";
8777
}
8878
};
8979

90-
void handle_read_headers(system::error_code const &ec, size_t bytes_transferred) {
80+
void handle_read_headers(boost::system::error_code const &ec, size_t bytes_transferred) {
9181
if (!ec) {
92-
tribool done;
93-
array<char, BOOST_HTTP_SERVER_BUFFER_SIZE>::iterator new_start;
82+
boost::tribool done;
83+
boost::array<char, BOOST_HTTP_SERVER_BUFFER_SIZE>::iterator new_start;
9484
tie(done,new_start) = parser_.parse_headers(request_, buffer_.data(), buffer_.data() + bytes_transferred);
9585
if (done) {
9686
if (request_.method[0] == 'P') {
@@ -107,7 +97,7 @@ namespace boost { namespace network { namespace http {
10797
socket_,
10898
response_.to_buffers(),
10999
wrapper_.wrap(
110-
bind(
100+
boost::bind(
111101
&connection<Tag,Handler>::handle_write,
112102
connection<Tag,Handler>::shared_from_this(),
113103
boost::asio::placeholders::error
@@ -127,7 +117,7 @@ namespace boost { namespace network { namespace http {
127117
socket_,
128118
response_.to_buffers(),
129119
wrapper_.wrap(
130-
bind(
120+
boost::bind(
131121
&connection<Tag,Handler>::handle_write,
132122
connection<Tag,Handler>::shared_from_this(),
133123
boost::asio::placeholders::error
@@ -146,7 +136,7 @@ namespace boost { namespace network { namespace http {
146136
socket_.async_read_some(
147137
boost::asio::buffer(buffer_),
148138
wrapper_.wrap(
149-
bind(
139+
boost::bind(
150140
&connection<Tag,Handler>::handle_read_body_contents,
151141
connection<Tag,Handler>::shared_from_this(),
152142
boost::asio::placeholders::error,
@@ -164,7 +154,7 @@ namespace boost { namespace network { namespace http {
164154
socket_,
165155
response_.to_buffers(),
166156
wrapper_.wrap(
167-
bind(
157+
boost::bind(
168158
&connection<Tag,Handler>::handle_write,
169159
connection<Tag,Handler>::shared_from_this(),
170160
boost::asio::placeholders::error
@@ -177,7 +167,7 @@ namespace boost { namespace network { namespace http {
177167
socket_,
178168
response_.to_buffers(),
179169
wrapper_.wrap(
180-
bind(
170+
boost::bind(
181171
&connection<Tag,Handler>::handle_write,
182172
connection<Tag,Handler>::shared_from_this(),
183173
boost::asio::placeholders::error
@@ -191,7 +181,7 @@ namespace boost { namespace network { namespace http {
191181
socket_,
192182
response_.to_buffers(),
193183
wrapper_.wrap(
194-
bind(
184+
boost::bind(
195185
&connection<Tag,Handler>::handle_write,
196186
connection<Tag,Handler>::shared_from_this(),
197187
boost::asio::placeholders::error
@@ -202,7 +192,7 @@ namespace boost { namespace network { namespace http {
202192
socket_.async_read_some(
203193
boost::asio::buffer(buffer_),
204194
wrapper_.wrap(
205-
bind(
195+
boost::bind(
206196
&connection<Tag,Handler>::handle_read_headers,
207197
connection<Tag,Handler>::shared_from_this(),
208198
boost::asio::placeholders::error,
@@ -218,7 +208,7 @@ namespace boost { namespace network { namespace http {
218208
void handle_read_body_contents(boost::system::error_code const & ec, size_t bytes_to_read, size_t bytes_transferred) {
219209
if (!ec) {
220210
size_t difference = bytes_to_read - bytes_transferred;
221-
array<char,BOOST_HTTP_SERVER_BUFFER_SIZE>::iterator start = buffer_.begin(),
211+
boost::array<char,BOOST_HTTP_SERVER_BUFFER_SIZE>::iterator start = buffer_.begin(),
222212
past_end = start;
223213
std::advance(past_end, (std::min)(bytes_to_read,bytes_transferred));
224214
request_.body.append(buffer_.begin(), past_end);
@@ -228,7 +218,7 @@ namespace boost { namespace network { namespace http {
228218
socket_,
229219
response_.to_buffers(),
230220
wrapper_.wrap(
231-
bind(
221+
boost::bind(
232222
&connection<Tag,Handler>::handle_write,
233223
connection<Tag,Handler>::shared_from_this(),
234224
boost::asio::placeholders::error
@@ -239,7 +229,7 @@ namespace boost { namespace network { namespace http {
239229
socket_.async_read_some(
240230
boost::asio::buffer(buffer_),
241231
wrapper_.wrap(
242-
bind(
232+
boost::bind(
243233
&connection<Tag,Handler>::handle_read_body_contents,
244234
connection<Tag,Handler>::shared_from_this(),
245235
boost::asio::placeholders::error,
@@ -255,17 +245,18 @@ namespace boost { namespace network { namespace http {
255245

256246
void handle_write(boost::system::error_code const & ec) {
257247
if (!ec) {
248+
using boost::asio::ip::tcp;
258249
boost::system::error_code ignored_ec;
259250
socket_.shutdown(tcp::socket::shutdown_both, ignored_ec);
260251
socket_.close(ignored_ec);
261252
}
262253
}
263254

264-
io_service & service_;
255+
boost::asio::io_service & service_;
265256
Handler & handler_;
266-
tcp::socket socket_;
267-
io_service::strand wrapper_;
268-
array<char,BOOST_HTTP_SERVER_BUFFER_SIZE> buffer_;
257+
boost::asio::ip::tcp::socket socket_;
258+
boost::asio::io_service::strand wrapper_;
259+
boost::array<char,BOOST_HTTP_SERVER_BUFFER_SIZE> buffer_;
269260
request_parser parser_;
270261
basic_request<Tag> request_;
271262
basic_response<Tag> response_;

boost/network/protocol/http/server.hpp

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Copyright 2009 (c) Tarro, Inc.
22
// Copyright 2009 (c) Dean Michael Berris <mikhailberis@gmail.com>
3+
// Copyright 2010 (c) Glyn Matthews
34
// Copyright 2003-2008 (c) Chris Kholhoff
45
// Distributed under the Boost Software License, Version 1.0.
56
// (See accompanying file LICENSE_1_0.txt or copy at
@@ -11,28 +12,27 @@
1112

1213
#include <boost/shared_ptr.hpp>
1314
#include <boost/bind.hpp>
14-
#include <string>
1515
#include <boost/asio/ip/tcp.hpp>
1616
#include <boost/network/protocol/http/connection.hpp>
17+
#include <boost/network/traits/string.hpp>
1718

1819
namespace boost { namespace network { namespace http {
1920

20-
using boost::shared_ptr;
21-
using std::string;
22-
using boost::asio::ip::tcp;
23-
using boost::bind;
24-
2521
template <class Tag, class Handler>
2622
struct basic_server {
23+
typedef typename string<Tag>::type string_type;
2724
typedef basic_request<Tag> request;
2825
typedef basic_response<Tag> response;
2926

30-
basic_server(string const & address, string const & port, Handler & handler)
27+
basic_server(string_type const & address,
28+
string_type const & port,
29+
Handler & handler)
3130
: handler_(handler)
3231
, service_()
3332
, acceptor_(service_)
3433
, new_connection(new connection<Tag,Handler>(service_, handler))
3534
{
35+
using boost::asio::ip::tcp;
3636
tcp::resolver resolver(service_);
3737
tcp::resolver::query query(address, port);
3838
tcp::endpoint endpoint = *resolver.resolve(query);
@@ -41,7 +41,8 @@ namespace boost { namespace network { namespace http {
4141
acceptor_.bind(endpoint);
4242
acceptor_.listen();
4343
acceptor_.async_accept(new_connection->socket(),
44-
bind(&basic_server<Tag,Handler>::handle_accept, this, boost::asio::placeholders::error));
44+
boost::bind(&basic_server<Tag,Handler>::handle_accept,
45+
this, boost::asio::placeholders::error));
4546
}
4647

4748
void run() {
@@ -56,27 +57,30 @@ namespace boost { namespace network { namespace http {
5657
private:
5758

5859
Handler & handler_;
59-
io_service service_;
60-
tcp::acceptor acceptor_;
61-
shared_ptr<connection<Tag,Handler> > new_connection;
60+
boost::asio::io_service service_;
61+
boost::asio::ip::tcp::acceptor acceptor_;
62+
boost::shared_ptr<connection<Tag,Handler> > new_connection;
6263

6364
void handle_accept(boost::system::error_code const & ec) {
6465
if (!ec) {
6566
new_connection->start();
6667
new_connection.reset(new connection<Tag,Handler>(service_, handler_));
6768
acceptor_.async_accept(new_connection->socket(),
68-
bind(&basic_server<Tag,Handler>::handle_accept, this, boost::asio::placeholders::error));
69+
boost::bind(&basic_server<Tag,Handler>::handle_accept,
70+
this, boost::asio::placeholders::error));
6971
}
7072
}
7173
};
7274

7375
template <class Handler>
7476
struct server : basic_server<tags::http_server, Handler> {
75-
server(string const & address, string const & port, Handler & handler)
76-
: basic_server<tags::http_server,Handler>(address, port, handler) {}
77+
typedef basic_server<tags::http_server, Handler> server_base;
7778

78-
typedef typename basic_server<tags::http_server,Handler>::request request;
79-
typedef typename basic_server<tags::http_server,Handler>::response response;
79+
server(typename server_base::string_type const & address,
80+
typename server_base::string_type const & port,
81+
Handler & handler)
82+
: server_base(address, port, handler) {}
83+
8084
};
8185

8286
} // namespace http

libs/network/example/uri.cpp

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,34 +7,34 @@
77

88
//[ uri_main
99
/*`
10-
10+
This is a simple program that validates a URI.
1111
*/
1212
#include <boost/network/uri.hpp>
13+
#include <boost/network/uri/http/uri.hpp>
1314
#include <string>
1415
#include <iostream>
1516

16-
using namespace std;
17-
using namespace boost::network::uri;
18-
1917

2018
int main(int argc, char * argv[]) {
21-
string input;
22-
cout << "Please enter a URI to parse: ";
23-
cin >> input;
24-
25-
/*<< Create >>*/
26-
uri uri_(input);
27-
/*<< Create >>*/
28-
cout << "You've entered "
29-
<< (valid(uri_)? string("a valid") : string("an invalid"))
30-
<< " URI!" << endl;
31-
32-
/*<< Create >>*/
33-
http::uri http_uri_(input);
34-
/*<< Create >>*/
35-
cout << "It's also "
36-
<< (valid(http_uri_)? string("a valid HTTP URI") : string("an invalid HTTP URI."))
37-
<< "!" << endl;
19+
std::string input;
20+
std::cout << "Please enter a URI to parse: ";
21+
std::cin >> input;
22+
23+
/*<< Create a `boost::network::uri::uri` object from the input. >>*/
24+
boost::network::uri::uri uri_(input);
25+
/*<< Check if it's a valid URI. >>*/
26+
std::cout << "You've entered "
27+
<< (boost::network::uri::valid(uri_)?
28+
std::string("a valid") : std::string("an invalid"))
29+
<< " URI!" << std::endl;
30+
31+
/*<< Create a `boost::network::http::uri` object from the input. >>*/
32+
boost::network::uri::http::uri http_uri_(input);
33+
/*<< Check if it's a valid HTTP URI. >>*/
34+
std::cout << "It's also "
35+
<< (boost::network::uri::valid(http_uri_)?
36+
std::string("a valid HTTP URI") : std::string("an invalid HTTP URI."))
37+
<< "!" << std::endl;
3838

3939
return EXIT_SUCCESS;
4040
}

0 commit comments

Comments
 (0)