beast, beast::asio improvements and fixes:

* New maybe_const_t alias for maybe_const
* New asio::enable_wait_for_async for safe cleanup
* New asio::memory_buffer, a managed boost::asio compatible buffer
* shared_handler improvements:
   - Can be 'empty' (no stored handler).
   - Default constructible as 'empty'.
   - Safe evaluation in bool contexts, false==empty
* Fix is_call_possible metafunction:
   - Works on empty argument lists
   - Works with reference types
* Replace SafeBool idiom with C++11 explicit operator bool
* Move IPAddress function definitions to the header
* Move cyclic_iterator to container/
* Remove unused BufferType
* Remove obsolete classes:
   - NamedPipe
   - ReadWriteLock
   - ScopedReadLock
   - ScopedWriteLock
   - LockGuard
This commit is contained in:
Vinnie Falco
2014-03-16 20:32:14 -07:00
parent 6546c30e17
commit d4a5c0353d
45 changed files with 1192 additions and 1469 deletions

View File

@@ -25,150 +25,6 @@
namespace beast {
namespace IP {
Address::Address ()
: m_type (ipv4)
{
}
Address::Address (AddressV4 const& addr)
: m_type (ipv4)
, m_v4 (addr)
{
}
Address::Address (AddressV6 const& addr)
: m_type (ipv6)
, m_v6 (addr)
{
}
Address& Address::operator= (AddressV4 const& addr)
{
m_type = ipv4;
m_v6 = AddressV6();
m_v4 = addr;
return *this;
}
Address& Address::operator= (AddressV6 const& addr)
{
m_type = ipv6;
m_v4 = AddressV4();
m_v6 = addr;
return *this;
}
std::pair <Address, bool> Address::from_string (std::string const& s)
{
std::stringstream is (s);
Address addr;
is >> addr;
if (! is.fail() && is.rdbuf()->in_avail() == 0)
return std::make_pair (addr, true);
return std::make_pair (Address (), false);
}
std::string Address::to_string () const
{
return (is_v4 ())
? IP::to_string (to_v4())
: IP::to_string (to_v6());
}
AddressV4 const& Address::to_v4 () const
{
if (m_type != ipv4)
throw std::bad_cast();
return m_v4;
}
AddressV6 const& Address::to_v6 () const
{
if (m_type != ipv6)
throw std::bad_cast();
return m_v6;
}
bool operator== (Address const& lhs, Address const& rhs)
{
if (lhs.is_v4 ())
{
if (rhs.is_v4 ())
return lhs.to_v4() == rhs.to_v4();
}
else
{
if (rhs.is_v6 ())
return lhs.to_v6() == rhs.to_v6();
}
return false;
}
bool operator< (Address const& lhs, Address const& rhs)
{
if (lhs.m_type < rhs.m_type)
return true;
if (lhs.is_v4 ())
return lhs.to_v4() < rhs.to_v4();
return lhs.to_v6() < rhs.to_v6();
}
//------------------------------------------------------------------------------
bool is_loopback (Address const& addr)
{
return (addr.is_v4 ())
? is_loopback (addr.to_v4 ())
: is_loopback (addr.to_v6 ());
}
bool is_unspecified (Address const& addr)
{
return (addr.is_v4 ())
? is_unspecified (addr.to_v4 ())
: is_unspecified (addr.to_v6 ());
}
bool is_multicast (Address const& addr)
{
return (addr.is_v4 ())
? is_multicast (addr.to_v4 ())
: is_multicast (addr.to_v6 ());
}
bool is_private (Address const& addr)
{
return (addr.is_v4 ())
? is_private (addr.to_v4 ())
: is_private (addr.to_v6 ());
}
bool is_public (Address const& addr)
{
return (addr.is_v4 ())
? is_public (addr.to_v4 ())
: is_public (addr.to_v6 ());
}
//------------------------------------------------------------------------------
std::size_t hash_value (Address const& addr)
{
return (addr.is_v4 ())
? hash_value (addr.to_v4())
: hash_value (addr.to_v6());
}
std::istream& operator>> (std::istream& is, Address& addr)
{
// VFALCO TODO Support ipv6!
AddressV4 addrv4;
is >> addrv4;
addr = Address (addrv4);
return is;
}
//------------------------------------------------------------------------------
class IPAddressTests : public UnitTest