37 lines
824 B
C++
37 lines
824 B
C++
#include "endpoint_description.h"
|
|
|
|
#include <boost/asio.hpp>
|
|
#include <boost/format.hpp>
|
|
|
|
namespace bts {
|
|
namespace qbus {
|
|
|
|
std::string endpoint_description(boost::asio::ip::tcp::endpoint const&ep)
|
|
{
|
|
try {
|
|
return (boost::format ("%s:%d") % ep.address ().to_string () % ep.port()).str();
|
|
} catch (boost::system::system_error &) {
|
|
return "<unknown>";
|
|
}
|
|
}
|
|
|
|
std::string local_endpoint_description(boost::asio::ip::tcp::socket const&s)
|
|
{
|
|
try {
|
|
return endpoint_description(s.local_endpoint());
|
|
} catch (boost::system::system_error &) {
|
|
return "<unknown>";
|
|
}
|
|
}
|
|
|
|
std::string remote_endpoint_description(boost::asio::ip::tcp::socket const&s)
|
|
{
|
|
try {
|
|
return endpoint_description(s.remote_endpoint());
|
|
} catch (boost::system::system_error &) {
|
|
return "<unknown>";
|
|
}
|
|
}
|
|
|
|
}}
|