|
| 1 | +#ifndef BOOST_NETWORK_PROTOCOL_HTTP_SERVER_OPTIONS_20130128 |
| 2 | +#defineBOOST_NETWORK_PROTOCOL_HTTP_SERVER_OPTIONS_20130128 |
| 3 | + |
| 4 | +// Copyright 2013 Google, Inc. |
| 5 | +// Copyright 2013 Dean Michael Berris <dberris@google.com> |
| 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/asio/io_service.hpp> |
| 11 | +#include<boost/asio/socket_base.hpp> |
| 12 | +#include<boost/network/traits/string.hpp> |
| 13 | +#include<boost/network/utils/thread_pool.hpp> |
| 14 | +#include<boost/optional.hpp> |
| 15 | +#include<boost/shared_ptr.hpp> |
| 16 | + |
| 17 | +namespaceboost {namespacenetwork {namespacehttp { |
| 18 | + |
| 19 | +template<classTag,classHandler> |
| 20 | +structserver_options { |
| 21 | +typedeftypename string<Tag>::type string_type; |
| 22 | + |
| 23 | +explicitserver_options(Handler& handler) |
| 24 | + : io_service_() |
| 25 | + , handler_(handler) |
| 26 | + , address_("localhost") |
| 27 | + , port_("80") |
| 28 | + , reuse_address_(false) |
| 29 | + , report_aborted_(false) |
| 30 | + , non_blocking_io_(true) |
| 31 | + , linger_(true) |
| 32 | + , linger_timeout_(0) |
| 33 | + , receive_buffer_size_() |
| 34 | + , send_buffer_size_() |
| 35 | + , receive_low_watermark_() |
| 36 | + , send_low_watermark_() |
| 37 | + , thread_pool_() |
| 38 | + {} |
| 39 | + |
| 40 | +server_options(const server_options &other) |
| 41 | + : io_service_(other.io_service()) |
| 42 | + , handler_(other.handler_) |
| 43 | + , address_(other.address_) |
| 44 | + , port_(other.port_) |
| 45 | + , reuse_address_(other.reuse_address_) |
| 46 | + , report_aborted_(other.report_aborted_) |
| 47 | + , non_blocking_io_(other.non_blocking_io_) |
| 48 | + , linger_(other.linger_) |
| 49 | + , linger_timeout_(0) |
| 50 | + , receive_buffer_size_(other.receive_buffer_size_) |
| 51 | + , send_buffer_size_(other.send_buffer_size_) |
| 52 | + , receive_low_watermark_(other.receive_low_watermark_) |
| 53 | + , send_low_watermark_(other.send_low_watermark_) |
| 54 | + , thread_pool_(other.thread_pool_) |
| 55 | + {} |
| 56 | + |
| 57 | + server_options &operator= (server_options other) { |
| 58 | + other.swap(*this); |
| 59 | +return *this; |
| 60 | + } |
| 61 | + |
| 62 | +voidswap(server_options &other) { |
| 63 | +using std::swap; |
| 64 | +swap(io_service_, other.io_service_); |
| 65 | +swap(address_, other.address_); |
| 66 | +swap(port_, other.port_); |
| 67 | +swap(reuse_address_, other.reuse_address_); |
| 68 | +swap(report_aborted_, other.report_aborted_); |
| 69 | +swap(non_blocking_io_, other.non_blocking_io_); |
| 70 | +swap(linger_, other.linger_); |
| 71 | +swap(linger_timeout_, other.linger_timeout_); |
| 72 | +swap(receive_buffer_size_, other.receive_buffer_size_); |
| 73 | +swap(send_buffer_size_, other.send_buffer_size_); |
| 74 | +swap(receive_low_watermark_, other.receive_low_watermark_); |
| 75 | +swap(send_low_watermark_, other.send_low_watermark_); |
| 76 | +swap(thread_pool_, other.thread_pool_); |
| 77 | + } |
| 78 | + |
| 79 | + server_options &io_service(boost::shared_ptr<boost::asio::io_service> v) { io_service_ = v;return *this; } |
| 80 | + server_options &address(string_typeconst &v) { address_ = v;return *this; } |
| 81 | + server_options &port(string_typeconst &v) { port_ = v;return *this; } |
| 82 | + server_options &reuse_address(bool v) { reuse_address_ = v;return *this; } |
| 83 | + server_options &report_aborted(bool v) { report_aborted_ = v;return *this; } |
| 84 | + server_options &non_blocking_io(bool v) { non_blocking_io_ = v;return *this; } |
| 85 | + server_options &linger(bool v) { linger_ = v;return *this; } |
| 86 | + server_options &linger_timeout(size_t v) { linger_timeout_ = v;return *this; } |
| 87 | + server_options &receive_buffer_size(boost::asio::socket_base::receive_buffer_size v) { receive_buffer_size_ = v;return *this; } |
| 88 | + server_options &send_buffer_size(boost::asio::socket_base::send_buffer_size v) { send_buffer_size_ = v;return *this; } |
| 89 | + server_options &receive_low_watermark(boost::asio::socket_base::receive_low_watermark v) { receive_low_watermark_ = v;return *this; } |
| 90 | + server_options &send_low_watermark(boost::asio::socket_base::send_low_watermark v) { send_low_watermark_ = v;return *this; } |
| 91 | + server_options &thread_pool(boost::shared_ptr<utils::thread_pool> v) { thread_pool_ = v;return *this; } |
| 92 | + |
| 93 | + boost::shared_ptr<boost::asio::io_service>io_service()const {return io_service_; } |
| 94 | + string_typeaddress()const {return address_; } |
| 95 | + string_typeport()const {return port_; } |
| 96 | + Handler &handler()const {return handler_; } |
| 97 | +boolreuse_address()const {return reuse_address_; } |
| 98 | +boolreport_aborted()const {return report_aborted_; } |
| 99 | +boolnon_blocking_io()const {return non_blocking_io_; } |
| 100 | +boollinger()const {return linger_; } |
| 101 | +size_tlinger_timeout()const {return linger_timeout_; } |
| 102 | + boost::optional<boost::asio::socket_base::receive_buffer_size>receive_buffer_size()const {return receive_buffer_size_; } |
| 103 | + boost::optional<boost::asio::socket_base::send_buffer_size>send_buffer_size()const {return send_buffer_size_; } |
| 104 | + boost::optional<boost::asio::socket_base::receive_low_watermark>receive_low_watermark()const {return receive_low_watermark_; } |
| 105 | + boost::optional<boost::asio::socket_base::send_low_watermark>send_low_watermark()const {return send_low_watermark_; } |
| 106 | + boost::shared_ptr<utils::thread_pool>thread_pool()const {return thread_pool_; } |
| 107 | + |
| 108 | +private: |
| 109 | + boost::shared_ptr<boost::asio::io_service> io_service_; |
| 110 | + string_type address_; |
| 111 | + string_type port_; |
| 112 | + Handler &handler_; |
| 113 | +bool reuse_address_; |
| 114 | +bool report_aborted_; |
| 115 | +bool non_blocking_io_; |
| 116 | +bool linger_; |
| 117 | +size_t linger_timeout_; |
| 118 | + boost::optional<boost::asio::socket_base::receive_buffer_size> receive_buffer_size_; |
| 119 | + boost::optional<boost::asio::socket_base::send_buffer_size> send_buffer_size_; |
| 120 | + boost::optional<boost::asio::socket_base::receive_low_watermark> receive_low_watermark_; |
| 121 | + boost::optional<boost::asio::socket_base::send_low_watermark> send_low_watermark_; |
| 122 | + boost::shared_ptr<utils::thread_pool> thread_pool_; |
| 123 | +}; |
| 124 | + |
| 125 | +template<classTag,classHandler> |
| 126 | +inlinevoidswap(server_options<Tag, Handler> &a, server_options<Tag, Handler> &b) { |
| 127 | + a.swap(b); |
| 128 | +} |
| 129 | + |
| 130 | +}/* http*/ |
| 131 | +}/* network*/ |
| 132 | +}/* boost*/ |
| 133 | + |
| 134 | +#endif/* BOOST_NETWORK_PROTOCOL_HTTP_SERVER_OPTIONS_20130128*/ |