Wrap a few boost asio exceptions in fc exceptions
This commit is contained in:
parent
d44d72b0d9
commit
7966587021
1 changed files with 28 additions and 8 deletions
|
|
@ -10,9 +10,14 @@ namespace fc { namespace ip {
|
||||||
address::address( uint32_t ip )
|
address::address( uint32_t ip )
|
||||||
:_ip(ip){}
|
:_ip(ip){}
|
||||||
|
|
||||||
address::address( const fc::string& s ) {
|
address::address( const fc::string& s )
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
_ip = boost::asio::ip::address_v4::from_string(s.c_str()).to_ulong();
|
_ip = boost::asio::ip::address_v4::from_string(s.c_str()).to_ulong();
|
||||||
}
|
}
|
||||||
|
FC_RETHROW_EXCEPTIONS(error, "Error parsing IP address ${address}", ("address", s))
|
||||||
|
}
|
||||||
|
|
||||||
bool operator==( const address& a, const address& b ) {
|
bool operator==( const address& a, const address& b ) {
|
||||||
return uint32_t(a) == uint32_t(b);
|
return uint32_t(a) == uint32_t(b);
|
||||||
|
|
@ -21,14 +26,24 @@ namespace fc { namespace ip {
|
||||||
return uint32_t(a) != uint32_t(b);
|
return uint32_t(a) != uint32_t(b);
|
||||||
}
|
}
|
||||||
|
|
||||||
address& address::operator=( const fc::string& s ) {
|
address& address::operator=( const fc::string& s )
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
_ip = boost::asio::ip::address_v4::from_string(s.c_str()).to_ulong();
|
_ip = boost::asio::ip::address_v4::from_string(s.c_str()).to_ulong();
|
||||||
|
}
|
||||||
|
FC_RETHROW_EXCEPTIONS(error, "Error parsing IP address ${address}", ("address", s))
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
address::operator fc::string()const {
|
address::operator fc::string()const
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
return boost::asio::ip::address_v4(_ip).to_string().c_str();
|
return boost::asio::ip::address_v4(_ip).to_string().c_str();
|
||||||
}
|
}
|
||||||
|
FC_RETHROW_EXCEPTIONS(error, "Error parsing IP address to string")
|
||||||
|
}
|
||||||
address::operator uint32_t()const {
|
address::operator uint32_t()const {
|
||||||
return _ip;
|
return _ip;
|
||||||
}
|
}
|
||||||
|
|
@ -69,9 +84,14 @@ namespace fc { namespace ip {
|
||||||
FC_RETHROW_EXCEPTIONS(warn, "error converting string to IP endpoint")
|
FC_RETHROW_EXCEPTIONS(warn, "error converting string to IP endpoint")
|
||||||
}
|
}
|
||||||
|
|
||||||
endpoint::operator string()const {
|
endpoint::operator string()const
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
return string(_ip) + ':' + fc::string(boost::lexical_cast<std::string>(_port).c_str());
|
return string(_ip) + ':' + fc::string(boost::lexical_cast<std::string>(_port).c_str());
|
||||||
}
|
}
|
||||||
|
FC_RETHROW_EXCEPTIONS(warn, "error converting IP endpoint to string")
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return true if the ip is in the following ranges:
|
* @return true if the ip is in the following ranges:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue