1// 2// Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com) 3// 4// Distributed under the Boost Software License, Version 1.0. (See accompanying 5// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6// 7// Official repository: https://github.com/boostorg/beast 8// 9 10#ifndef BOOST_BEAST_IMPL_ERROR_IPP 11#define BOOST_BEAST_IMPL_ERROR_IPP 12 13#include <boost/beast/core/error.hpp> 14 15namespace boost { 16namespace beast { 17 18namespace detail { 19 20class error_codes : public error_category 21{ 22public: 23 const char* 24 name() const noexcept override 25 { 26 return "boost.beast"; 27 } 28 29 BOOST_BEAST_DECL 30 std::string 31 message(int ev) const override 32 { 33 switch(static_cast<error>(ev)) 34 { 35 default: 36 case error::timeout: return 37 "The socket was closed due to a timeout"; 38 } 39 } 40 41 BOOST_BEAST_DECL 42 error_condition 43 default_error_condition(int ev) const noexcept override 44 { 45 switch(static_cast<error>(ev)) 46 { 47 default: 48 // return {ev, *this}; 49 case error::timeout: 50 return condition::timeout; 51 } 52 } 53}; 54 55class error_conditions : public error_category 56{ 57public: 58 BOOST_BEAST_DECL 59 const char* 60 name() const noexcept override 61 { 62 return "boost.beast"; 63 } 64 65 BOOST_BEAST_DECL 66 std::string 67 message(int cv) const override 68 { 69 switch(static_cast<condition>(cv)) 70 { 71 default: 72 case condition::timeout: 73 return "The operation timed out"; 74 } 75 } 76}; 77 78} // detail 79 80error_code 81make_error_code(error e) 82{ 83 static detail::error_codes const cat{}; 84 return error_code{static_cast< 85 std::underlying_type<error>::type>(e), cat}; 86} 87 88error_condition 89make_error_condition(condition c) 90{ 91 static detail::error_conditions const cat{}; 92 return error_condition{static_cast< 93 std::underlying_type<condition>::type>(c), cat}; 94} 95 96} // beast 97} // boost 98 99#endif 100