basic_endpoint.hpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. //
  2. // ip/impl/basic_endpoint.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2013 Christopher M. Kohlhoff (chris at kohlhoff dot com)
  6. //
  7. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  8. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  9. //
  10. #ifndef BOOST_ASIO_IP_IMPL_BASIC_ENDPOINT_HPP
  11. #define BOOST_ASIO_IP_IMPL_BASIC_ENDPOINT_HPP
  12. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  13. # pragma once
  14. #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
  15. #if !defined(BOOST_ASIO_NO_IOSTREAM)
  16. #include <boost/asio/detail/throw_error.hpp>
  17. #include <boost/asio/detail/push_options.hpp>
  18. namespace boost {
  19. namespace asio {
  20. namespace ip {
  21. template <typename Elem, typename Traits, typename InternetProtocol>
  22. std::basic_ostream<Elem, Traits>& operator<<(
  23. std::basic_ostream<Elem, Traits>& os,
  24. const basic_endpoint<InternetProtocol>& endpoint)
  25. {
  26. boost::asio::ip::detail::endpoint tmp_ep(endpoint.address(), endpoint.port());
  27. boost::system::error_code ec;
  28. std::string s = tmp_ep.to_string(ec);
  29. if (ec)
  30. {
  31. if (os.exceptions() & std::basic_ostream<Elem, Traits>::failbit)
  32. boost::asio::detail::throw_error(ec);
  33. else
  34. os.setstate(std::basic_ostream<Elem, Traits>::failbit);
  35. }
  36. else
  37. for (std::string::iterator i = s.begin(); i != s.end(); ++i)
  38. os << os.widen(*i);
  39. return os;
  40. }
  41. } // namespace ip
  42. } // namespace asio
  43. } // namespace boost
  44. #include <boost/asio/detail/pop_options.hpp>
  45. #endif // !defined(BOOST_ASIO_NO_IOSTREAM)
  46. #endif // BOOST_ASIO_IP_IMPL_BASIC_ENDPOINT_HPP