77// http://www.boost.org/LICENSE_1_0.txt)
88
99#include < boost/network/protocol/http/server/parameters.hpp>
10+ #include < boost/optional.hpp>
11+ #include < boost/utility/in_place_factory.hpp>
1012
1113namespace boost {namespace network {namespace http {
1214
1315struct socket_options_base {
1416protected:
1517 asio::socket_base::reuse_address acceptor_reuse_address;
1618 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;
2123 asio::socket_base::non_blocking_io non_blocking_io;
2224 asio::socket_base::linger linger;
2325
2426template <class ArgPack >
2527socket_options_base (ArgPackconst & args)
2628 : acceptor_reuse_address(args[_reuse_address|false ])
2729 , 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 ])
3230 , non_blocking_io(args[_non_blocking_io|true ])
3331 , 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+ }
3538
3639void acceptor_options (boost::asio::ip::tcp::acceptor & acceptor) {
3740 acceptor.set_option (acceptor_reuse_address);
@@ -42,11 +45,40 @@ namespace boost { namespace network { namespace http {
4245 boost::system::error_code ignored;
4346 socket.io_control (non_blocking_io, ignored);
4447 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, Argsconst & args, Keywordconst & keyword) {
67+ option = in_place<typename Optional::value_type>(args[keyword]);
4968 }
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 &, Argsconst &, Keywordconst &) {
79+ // do nothing
80+ }
81+
5082 };
5183
5284}/* http*/