7
7
// http://www.boost.org/LICENSE_1_0.txt)
8
8
9
9
#include < boost/network/protocol/http/server/parameters.hpp>
10
+ #include < boost/optional.hpp>
11
+ #include < boost/utility/in_place_factory.hpp>
10
12
11
13
namespace boost { namespace network { namespace http {
12
14
13
15
struct socket_options_base {
14
16
protected:
15
17
asio::socket_base::reuse_address acceptor_reuse_address;
16
18
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;
19
+ boost::optional< asio::socket_base::receive_buffer_size> receive_buffer_size;
20
+ boost::optional< asio::socket_base::send_buffer_size> send_buffer_size;
21
+ boost::optional< asio::socket_base::receive_low_watermark> receive_low_watermark;
22
+ boost::optional< asio::socket_base::send_low_watermark> send_low_watermark;
21
23
asio::socket_base::non_blocking_io non_blocking_io;
22
24
asio::socket_base::linger linger;
23
25
24
26
template <class ArgPack >
25
27
socket_options_base (ArgPack const & args)
26
28
: acceptor_reuse_address(args[_reuse_address|false ])
27
29
, acceptor_report_aborted(args[_report_aborted|false ])
28
- , receive_buffer_size(args[_receive_buffer_size|4096 ])
29
- , send_buffer_size(args[_send_buffer_size|4096 ])
30
- , receive_low_watermark(args[_receive_low_watermark|1024 ])
31
- , send_low_watermark(args[_send_low_watermark|1024 ])
32
30
, non_blocking_io(args[_non_blocking_io|true ])
33
31
, linger(args[_linger|true ], args[_linger_timeout|0 ])
34
- {}
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
+ }
35
38
36
39
void acceptor_options (boost::asio::ip::tcp::acceptor & acceptor) {
37
40
acceptor.set_option (acceptor_reuse_address);
@@ -42,11 +45,40 @@ namespace boost { namespace network { namespace http {
42
45
boost::system::error_code ignored;
43
46
socket.io_control (non_blocking_io, ignored);
44
47
socket.set_option (linger, ignored);
45
- socket.set_option (receive_buffer_size, ignored);
46
- socket.set_option (receive_low_watermark, ignored);
47
- socket.set_option (send_buffer_size, ignored);
48
- socket.set_option (send_low_watermark, ignored);
48
+ if (receive_buffer_size) socket.set_option (*receive_buffer_size, ignored);
49
+ if (receive_low_watermark) socket.set_option (*receive_low_watermark, ignored);
50
+ if (send_buffer_size) socket.set_option (*send_buffer_size, ignored);
51
+ if (send_low_watermark) socket.set_option (*send_low_watermark, ignored);
52
+ }
53
+
54
+ private:
55
+
56
+ template <class Optional , class Args , class Keyword >
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, Args const & args, Keyword const & keyword) {
67
+ option = in_place<typename Optional::value_type>(args[keyword]);
49
68
}
69
+
70
+ template <class Optional , class Args , class Keyword >
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 &, Args const &, Keyword const &) {
79
+ // do nothing
80
+ }
81
+
50
82
};
51
83
52
84
} /* http */
0 commit comments