123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180 |
- #ifndef BOOST_BEAST_WEBSOCKET_STREAM_BASE_HPP
- #define BOOST_BEAST_WEBSOCKET_STREAM_BASE_HPP
- #include <boost/beast/core/detail/config.hpp>
- #include <boost/beast/websocket/detail/decorator.hpp>
- #include <boost/beast/core/role.hpp>
- #include <chrono>
- #include <type_traits>
- namespace boost {
- namespace beast {
- namespace websocket {
- struct stream_base
- {
-
- using duration =
- std::chrono::steady_clock::duration;
-
- using time_point =
- std::chrono::steady_clock::time_point;
-
- static
- time_point
- never() noexcept
- {
- return (time_point::max)();
- }
-
- static
- duration
- none() noexcept
- {
- return (duration::max)();
- }
-
- class decorator
- {
- detail::decorator d_;
- #ifndef BOOST_BEAST_DOXYGEN
- template<class, bool>
- friend class stream;
- #endif
- public:
-
- decorator(decorator&&) = default;
-
- template<class Decorator
- #ifndef BOOST_BEAST_DOXYGEN
- ,class = typename std::enable_if<
- detail::is_decorator<
- Decorator>::value>::type
- #endif
- >
- explicit
- decorator(Decorator&& f)
- : d_(std::forward<Decorator>(f))
- {
- }
- };
-
- struct timeout
- {
-
- duration handshake_timeout;
-
- duration idle_timeout;
-
- bool keep_alive_pings;
-
- static
- timeout
- suggested(role_type role) noexcept
- {
- timeout opt{};
- switch(role)
- {
- case role_type::client:
- opt.handshake_timeout = std::chrono::seconds(30);
- opt.idle_timeout = none();
- opt.keep_alive_pings = false;
- break;
- case role_type::server:
- opt.handshake_timeout = std::chrono::seconds(30);
- opt.idle_timeout = std::chrono::seconds(300);
- opt.keep_alive_pings = true;
- break;
- }
- return opt;
- }
- };
- protected:
- enum class status
- {
-
- handshake,
- open,
- closing,
- closed,
- failed
- };
- };
- }
- }
- }
- #endif
|