Boost logo

Boost-Commit :

From: chris_at_[hidden]
Date: 2007-09-24 09:21:03


Author: chris_kohlhoff
Date: 2007-09-24 09:21:03 EDT (Mon, 24 Sep 2007)
New Revision: 39504
URL: http://svn.boost.org/trac/boost/changeset/39504

Log:
Check whether exceptions are enabled on the output iostream and throw or not
throw errors accordingly.

Text files modified:
   trunk/boost/asio/ip/address_v4.hpp | 7 ++++++-
   trunk/boost/asio/ip/address_v6.hpp | 7 ++++++-
   trunk/boost/asio/ip/basic_endpoint.hpp | 40 ++++++++++++++++++++++++++++++++--------
   3 files changed, 44 insertions(+), 10 deletions(-)

Modified: trunk/boost/asio/ip/address_v4.hpp
==============================================================================
--- trunk/boost/asio/ip/address_v4.hpp (original)
+++ trunk/boost/asio/ip/address_v4.hpp 2007-09-24 09:21:03 EDT (Mon, 24 Sep 2007)
@@ -269,7 +269,12 @@
   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);

Modified: trunk/boost/asio/ip/address_v6.hpp
==============================================================================
--- trunk/boost/asio/ip/address_v6.hpp (original)
+++ trunk/boost/asio/ip/address_v6.hpp 2007-09-24 09:21:03 EDT (Mon, 24 Sep 2007)
@@ -387,7 +387,12 @@
   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);

Modified: trunk/boost/asio/ip/basic_endpoint.hpp
==============================================================================
--- trunk/boost/asio/ip/basic_endpoint.hpp (original)
+++ trunk/boost/asio/ip/basic_endpoint.hpp 2007-09-24 09:21:03 EDT (Mon, 24 Sep 2007)
@@ -342,11 +342,23 @@
     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 @@
     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))


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk