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

Commit7205bcd

Browse files
committed
Making the HTTP Async Server use the socket_options_base for setting parameter-set customizations on the socket options handled by the HTTP server.
1 parentabe9b59 commit7205bcd

File tree

3 files changed

+65
-40
lines changed

3 files changed

+65
-40
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@
99
#include<boost/network/protocol/http/server/async_connection.hpp>
1010
#include<boost/thread/mutex.hpp>
1111
#include<boost/network/protocol/http/server/storage_base.hpp>
12+
#include<boost/network/protocol/http/server/socket_options_base.hpp>
1213
#include<boost/network/utils/thread_pool.hpp>
1314

1415
namespaceboost {namespacenetwork {namespacehttp {
1516

1617
template<classTag,classHandler>
17-
structasync_server_base : server_storage_base {
18+
structasync_server_base : server_storage_base, socket_options_base {
1819
typedef basic_request<Tag> request;
1920
typedef basic_response<Tag> response;
2021
typedeftypename string<Tag>::type string_type;
@@ -33,6 +34,7 @@ namespace boost { namespace network { namespace http {
3334
server_storage_base::no_io_service,
3435
server_storage_base::has_io_service
3536
>::type())
37+
, socket_options_base(args)
3638
, handler(args[_handler])
3739
, address_(args[_address])
3840
, port_(args[_port])
@@ -57,9 +59,9 @@ namespace boost { namespace network { namespace http {
5759
}
5860

5961
voidlisten() {
62+
if (listening)return;
6063
boost::unique_lock<boost::mutex>listening_lock(listening_mutex_);
6164
if (!listening)start_listening();
62-
listening_lock.unlock();
6365
}
6466

6567
private:
@@ -76,6 +78,7 @@ namespace boost { namespace network { namespace http {
7678

7779
voidhandle_accept(boost::system::error_codeconst & ec) {
7880
if (!ec) {
81+
socket_options_base::socket_options(new_connection->socket());
7982
new_connection->start();
8083
if (!stopping) {
8184
new_connection.reset(
@@ -103,6 +106,7 @@ namespace boost { namespace network { namespace http {
103106
tcp::endpoint endpoint = *resolver.resolve(query);
104107
acceptor.open(endpoint.protocol());
105108
acceptor.bind(endpoint);
109+
socket_options_base::acceptor_options(acceptor);
106110
acceptor.listen();
107111
listening =true;
108112
new_connection.reset(newconnection(io_service, handler, thread_pool));
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#ifndef BOOST_NETWORK_PROTOCOL_HTTP_SERVER_SOCKET_OPTIONS_BASE_HPP_20101210
2+
#defineBOOST_NETWORK_PROTOCOL_HTTP_SERVER_SOCKET_OPTIONS_BASE_HPP_20101210
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/parameters.hpp>
10+
11+
namespaceboost {namespacenetwork {namespacehttp {
12+
13+
structsocket_options_base {
14+
protected:
15+
asio::socket_base::reuse_address acceptor_reuse_address;
16+
asio::socket_base::enable_connection_aborted acceptor_report_aborted;
17+
asio::socket_base::receive_buffer_size receive_buffer_size;
18+
asio::socket_base::send_buffer_size send_buffer_size;
19+
asio::socket_base::receive_low_watermark receive_low_watermark;
20+
asio::socket_base::send_low_watermark send_low_watermark;
21+
asio::socket_base::non_blocking_io non_blocking_io;
22+
asio::socket_base::linger linger;
23+
24+
template<classArgPack>
25+
socket_options_base(ArgPackconst & args)
26+
: acceptor_reuse_address(args[_reuse_address|false])
27+
, acceptor_report_aborted(args[_report_aborted|false])
28+
, receive_buffer_size(args[_receive_buffer_size|1024])
29+
, send_buffer_size(args[_send_buffer_size|1024])
30+
, receive_low_watermark(args[_receive_low_watermark|512])
31+
, send_low_watermark(args[_send_low_watermark|512])
32+
, non_blocking_io(args[_non_blocking_io|true])
33+
, linger(args[_linger|true], args[_linger_timeout|0])
34+
{}
35+
36+
voidacceptor_options(boost::asio::ip::tcp::acceptor & acceptor) {
37+
acceptor.set_option(acceptor_reuse_address);
38+
acceptor.set_option(acceptor_report_aborted);
39+
}
40+
41+
voidsocket_options(boost::asio::ip::tcp::socket & socket) {
42+
socket.set_option(receive_buffer_size);
43+
socket.set_option(receive_low_watermark);
44+
socket.set_option(send_buffer_size);
45+
socket.set_option(send_low_watermark);
46+
socket.io_control(non_blocking_io);
47+
socket.set_option(linger);
48+
}
49+
};
50+
51+
}/* http*/
52+
53+
}/* network*/
54+
55+
}/* boost*/
56+
57+
#endif/* BOOST_NETWORK_PROTOCOL_HTTP_SERVER_SOCKET_OPTIONS_BASE_HPP_20101210*/

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

Lines changed: 2 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -16,49 +16,12 @@
1616
#include<boost/network/protocol/http/server/sync_connection.hpp>
1717
#include<boost/network/protocol/http/server/parameters.hpp>
1818
#include<boost/network/protocol/http/server/storage_base.hpp>
19+
#include<boost/network/protocol/http/server/socket_options_base.hpp>
1920
#include<boost/network/traits/string.hpp>
2021
#include<boost/thread/mutex.hpp>
2122

2223
namespaceboost {namespacenetwork {namespacehttp {
2324

24-
structsocket_options_base {
25-
protected:
26-
asio::socket_base::reuse_address acceptor_reuse_address;
27-
asio::socket_base::enable_connection_aborted acceptor_report_aborted;
28-
asio::socket_base::receive_buffer_size receive_buffer_size;
29-
asio::socket_base::send_buffer_size send_buffer_size;
30-
asio::socket_base::receive_low_watermark receive_low_watermark;
31-
asio::socket_base::send_low_watermark send_low_watermark;
32-
asio::socket_base::non_blocking_io non_blocking_io;
33-
asio::socket_base::linger linger;
34-
35-
template<classArgPack>
36-
socket_options_base(ArgPackconst & args)
37-
: acceptor_reuse_address(args[_reuse_address|false])
38-
, acceptor_report_aborted(args[_report_aborted|false])
39-
, receive_buffer_size(args[_receive_buffer_size|1024])
40-
, send_buffer_size(args[_send_buffer_size|1024])
41-
, receive_low_watermark(args[_receive_low_watermark|512])
42-
, send_low_watermark(args[_send_low_watermark|512])
43-
, non_blocking_io(args[_non_blocking_io|true])
44-
, linger(args[_linger|true], args[_linger_timeout|0])
45-
{}
46-
47-
voidacceptor_options(boost::asio::ip::tcp::acceptor & acceptor) {
48-
acceptor.set_option(acceptor_reuse_address);
49-
acceptor.set_option(acceptor_report_aborted);
50-
}
51-
52-
voidsocket_options(boost::asio::ip::tcp::socket & socket) {
53-
socket.set_option(receive_buffer_size);
54-
socket.set_option(receive_low_watermark);
55-
socket.set_option(send_buffer_size);
56-
socket.set_option(send_low_watermark);
57-
socket.io_control(non_blocking_io);
58-
socket.set_option(linger);
59-
}
60-
};
61-
6225
template<classTag,classHandler>
6326
structsync_server_base : server_storage_base, socket_options_base {
6427
typedeftypename string<Tag>::type string_type;
@@ -98,6 +61,7 @@ namespace boost { namespace network { namespace http {
9861
}
9962

10063
voidlisten() {
64+
if (listening_)return;
10165
boost::unique_lock<boost::mutex>listening_lock(listening_mutex_);
10266
if (!listening_)start_listening();
10367
listening_lock.unlock();

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp