From 331beee1a610af134bb7dd03ffa40266ad5f79b5 Mon Sep 17 00:00:00 2001 From: Christopher Kohlhoff Date: Mon, 24 Sep 2007 13:21:03 +0000 Subject: [PATCH] Check whether exceptions are enabled on the output iostream and throw or not throw errors accordingly. [SVN r39504] --- include/boost/asio/ip/address_v4.hpp | 7 ++++- include/boost/asio/ip/address_v6.hpp | 7 ++++- include/boost/asio/ip/basic_endpoint.hpp | 40 +++++++++++++++++++----- 3 files changed, 44 insertions(+), 10 deletions(-) diff --git a/include/boost/asio/ip/address_v4.hpp b/include/boost/asio/ip/address_v4.hpp index 5dad35fc..ed103c3f 100644 --- a/include/boost/asio/ip/address_v4.hpp +++ b/include/boost/asio/ip/address_v4.hpp @@ -269,7 +269,12 @@ std::basic_ostream& operator<<( boost::system::error_code ec; std::string s = addr.to_string(ec); if (ec) - os.setstate(std::ios_base::failbit); + { + if (os.exceptions() & std::ios::failbit) + boost::asio::detail::throw_error(ec); + else + os.setstate(std::ios_base::failbit); + } else for (std::string::iterator i = s.begin(); i != s.end(); ++i) os << os.widen(*i); diff --git a/include/boost/asio/ip/address_v6.hpp b/include/boost/asio/ip/address_v6.hpp index 029e289f..a95b56f5 100644 --- a/include/boost/asio/ip/address_v6.hpp +++ b/include/boost/asio/ip/address_v6.hpp @@ -387,7 +387,12 @@ std::basic_ostream& operator<<( boost::system::error_code ec; std::string s = addr.to_string(ec); if (ec) - os.setstate(std::ios_base::failbit); + { + if (os.exceptions() & std::ios::failbit) + boost::asio::detail::throw_error(ec); + else + os.setstate(std::ios_base::failbit); + } else for (std::string::iterator i = s.begin(); i != s.end(); ++i) os << os.widen(*i); diff --git a/include/boost/asio/ip/basic_endpoint.hpp b/include/boost/asio/ip/basic_endpoint.hpp index 66bfe993..557312cb 100644 --- a/include/boost/asio/ip/basic_endpoint.hpp +++ b/include/boost/asio/ip/basic_endpoint.hpp @@ -342,11 +342,23 @@ std::ostream& operator<<(std::ostream& os, const basic_endpoint& endpoint) { const address& addr = endpoint.address(); - if (addr.is_v4()) - os << addr.to_string(); + boost::system::error_code ec; + std::string a = addr.to_string(ec); + if (ec) + { + if (os.exceptions() & std::ios::failbit) + boost::asio::detail::throw_error(ec); + else + os.setstate(std::ios_base::failbit); + } else - os << '[' << addr.to_string() << ']'; - os << ':' << endpoint.port(); + { + if (addr.is_v4()) + os << a; + else + os << '[' << a << ']'; + os << ':' << endpoint.port(); + } return os; } #else // BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) @@ -356,11 +368,23 @@ std::basic_ostream& operator<<( const basic_endpoint& endpoint) { const address& addr = endpoint.address(); - if (addr.is_v4()) - os << addr.to_string(); + boost::system::error_code ec; + std::string a = addr.to_string(ec); + if (ec) + { + if (os.exceptions() & std::ios::failbit) + boost::asio::detail::throw_error(ec); + else + os.setstate(std::ios_base::failbit); + } else - os << '[' << addr.to_string() << ']'; - os << ':' << endpoint.port(); + { + if (addr.is_v4()) + os << a; + else + os << '[' << a << ']'; + os << ':' << endpoint.port(); + } return os; } #endif // BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))