moved IPAddress stream insertion operator to IPAddress.h, added stream insertion operator for SocketAddress, added BinaryWriter/BinaryReader insertion/extraction for SocketAddress, fixed serialization of IPAddress to BinaryWriter to support both IPv4 and IPv6 addresses

This commit is contained in:
Guenter Obiltschnig
2015-03-18 19:06:10 +01:00
parent c89cab6d6d
commit 2bbff0ca8f
6 changed files with 75 additions and 20 deletions

View File

@@ -21,6 +21,8 @@
#include "Poco/RefCountedObject.h"
#include "Poco/NumberParser.h"
#include "Poco/NumberFormatter.h"
#include "Poco/BinaryReader.h"
#include "Poco/BinaryWriter.h"
#include <algorithm>
#include <cstring>
@@ -268,3 +270,29 @@ Poco::UInt16 SocketAddress::resolveService(const std::string& service)
} } // namespace Poco::Net
Poco::BinaryWriter& operator << (Poco::BinaryWriter& writer, const Poco::Net::SocketAddress& value)
{
writer << value.host();
writer << value.port();
return writer;
}
Poco::BinaryReader& operator >> (Poco::BinaryReader& reader, Poco::Net::SocketAddress& value)
{
Poco::Net::IPAddress host;
reader >> host;
Poco::UInt16 port;
reader >> port;
value = Poco::Net::SocketAddress(host, port);
return reader;
}
inline std::ostream& operator << (std::ostream& ostr, const Poco::Net::SocketAddress& address)
{
ostr << address.toString();
return ostr;
}