mirror of
https://github.com/boostorg/asio.git
synced 2026-02-26 14:52:09 +00:00
Check whether exceptions are enabled on the output iostream and throw or not
throw errors accordingly. [SVN r39504]
This commit is contained in:
@@ -269,7 +269,12 @@ std::basic_ostream<Elem, Traits>& 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);
|
||||
|
||||
@@ -387,7 +387,12 @@ std::basic_ostream<Elem, Traits>& 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);
|
||||
|
||||
@@ -342,11 +342,23 @@ std::ostream& operator<<(std::ostream& os,
|
||||
const basic_endpoint<InternetProtocol>& 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<Elem, Traits>& operator<<(
|
||||
const basic_endpoint<InternetProtocol>& 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))
|
||||
|
||||
Reference in New Issue
Block a user