variant_stream fixes and added an operator<< for tcp::endpoint

This commit is contained in:
Arvid Norberg 2007-09-22 16:21:07 +00:00
parent 765a815844
commit a26bd55ff9
2 changed files with 28 additions and 20 deletions

View File

@ -98,6 +98,16 @@ namespace libtorrent
typedef asio::basic_deadline_timer<libtorrent::ptime> deadline_timer; typedef asio::basic_deadline_timer<libtorrent::ptime> deadline_timer;
inline std::ostream& operator<<(std::ostream& os, tcp::endpoint const& ep)
{
address const& a = ep.address();
if (a.is_v6())
os << "[" << a.to_string() << "]:" << ep.port();
else
os << a.to_string() << ":" << ep.port();
return os;
}
namespace detail namespace detail
{ {
template<class OutIt> template<class OutIt>

View File

@ -232,18 +232,18 @@ namespace aux
// -------------- remote_endpoint ----------- // -------------- remote_endpoint -----------
template <class EndpointType, class Error_Handler = boost::mpl::void_> template <class EndpointType>
struct remote_endpoint_visitor struct remote_endpoint_visitor_ec
: boost::static_visitor<EndpointType> : boost::static_visitor<EndpointType>
{ {
remote_endpoint_visitor(Error_Handler const& error_handler) remote_endpoint_visitor_ec(asio::error_code& ec)
: error_handler(error_handler) : error_code(ec)
{} {}
template <class T> template <class T>
EndpointType operator()(T* p) const EndpointType operator()(T* p) const
{ {
return p->remote_endpoint(error_handler); return p->remote_endpoint(error_code);
} }
EndpointType operator()(boost::blank) const EndpointType operator()(boost::blank) const
@ -251,11 +251,11 @@ namespace aux
return EndpointType(); return EndpointType();
} }
Error_Handler const& error_handler; asio::error_code& error_code;
}; };
template <class EndpointType> template <class EndpointType>
struct remote_endpoint_visitor<EndpointType, boost::mpl::void_> struct remote_endpoint_visitor
: boost::static_visitor<EndpointType> : boost::static_visitor<EndpointType>
{ {
template <class T> template <class T>
@ -272,18 +272,18 @@ namespace aux
// -------------- local_endpoint ----------- // -------------- local_endpoint -----------
template <class EndpointType, class Error_Handler = boost::mpl::void_> template <class EndpointType>
struct local_endpoint_visitor struct local_endpoint_visitor_ec
: boost::static_visitor<EndpointType> : boost::static_visitor<EndpointType>
{ {
local_endpoint_visitor(Error_Handler const& error_handler) local_endpoint_visitor_ec(asio::error_code& ec)
: error_handler(error_handler) : error_code(ec)
{} {}
template <class T> template <class T>
EndpointType operator()(T* p) const EndpointType operator()(T* p) const
{ {
return p->local_endpoint(error_handler); return p->local_endpoint(error_code);
} }
EndpointType operator()(boost::blank) const EndpointType operator()(boost::blank) const
@ -291,11 +291,11 @@ namespace aux
return EndpointType(); return EndpointType();
} }
Error_Handler const& error_handler; asio::error_code& error_code;
}; };
template <class EndpointType> template <class EndpointType>
struct local_endpoint_visitor<EndpointType, boost::mpl::void_> struct local_endpoint_visitor
: boost::static_visitor<EndpointType> : boost::static_visitor<EndpointType>
{ {
template <class T> template <class T>
@ -665,12 +665,11 @@ public:
return boost::apply_visitor(aux::remote_endpoint_visitor<endpoint_type>(), m_variant); return boost::apply_visitor(aux::remote_endpoint_visitor<endpoint_type>(), m_variant);
} }
template <class Error_Handler> endpoint_type remote_endpoint(asio::error_code& ec)
endpoint_type remote_endpoint(Error_Handler const& error_handler)
{ {
assert(instantiated()); assert(instantiated());
return boost::apply_visitor( return boost::apply_visitor(
aux::remote_endpoint_visitor<endpoint_type, Error_Handler>(error_handler), m_variant aux::remote_endpoint_visitor_ec<endpoint_type>(ec), m_variant
); );
} }
@ -680,12 +679,11 @@ public:
return boost::apply_visitor(aux::local_endpoint_visitor<endpoint_type>(), m_variant); return boost::apply_visitor(aux::local_endpoint_visitor<endpoint_type>(), m_variant);
} }
template <class Error_Handler> endpoint_type local_endpoint(asio::error_code& ec)
endpoint_type local_endpoint(Error_Handler const& error_handler)
{ {
assert(instantiated()); assert(instantiated());
return boost::apply_visitor( return boost::apply_visitor(
aux::local_endpoint_visitor<endpoint_type, Error_Handler>(error_handler), m_variant aux::local_endpoint_visitor_ec<endpoint_type>(ec), m_variant
); );
} }