*breaking change* DatagramSocket/MulticastSocket constructor creates an unconnected and unbound/uninitialized socket

This commit is contained in:
Guenter Obiltschnig
2016-02-28 22:08:28 +01:00
parent 32f3f4a146
commit e4fbbe69ba
9 changed files with 28 additions and 13 deletions

View File

@@ -39,8 +39,16 @@ public:
};
DatagramSocket();
/// Creates an unconnected IPv4 datagram socket.
/// Creates an unconnected, unbound datagram socket.
///
/// Before the datagram socket can be used, bind(),
/// bind6() or connect() must be called.
///
/// Notice: The behavior of this constructor has changed
/// in release 2.0. Previously, the constructor created
/// an unbound IPv4 datagram socket.
//@ deprecated
explicit DatagramSocket(Unbound unbound);
/// Creates an unconnected, unbound datagram socket.

View File

@@ -41,8 +41,16 @@ class Net_API MulticastSocket: public DatagramSocket
{
public:
MulticastSocket();
/// Creates the multicast socket.
/// Creates an unconnected, unbound multicast socket.
///
/// Before the multicast socket can be used, bind(),
/// bind6() or connect() must be called.
///
/// Notice: The behavior of this constructor has changed
/// in release 2.0. Previously, the constructor created
/// an unbound IPv4 multicast socket.
//@ deprecated
explicit MulticastSocket(Unbound unbound);
/// Creates an unconnected, unbound multicast datagram socket.

View File

@@ -31,7 +31,7 @@ DatagramSocket::DatagramSocket(): Socket(new DatagramSocketImpl)
}
DatagramSocket::DatagramSocket(Unbound): Socket(new DatagramSocketImpl(POCO_INVALID_SOCKET))
DatagramSocket::DatagramSocket(Unbound): Socket(new DatagramSocketImpl)
{
}

View File

@@ -27,7 +27,6 @@ namespace Net {
DatagramSocketImpl::DatagramSocketImpl()
{
init(AF_INET);
}

View File

@@ -53,7 +53,7 @@ MulticastSocket::MulticastSocket()
}
MulticastSocket::MulticastSocket(Unbound unbound): DatagramSocket(unbound)
MulticastSocket::MulticastSocket(Unbound unbound): DatagramSocket()
{
}

View File

@@ -241,7 +241,7 @@ void NetworkInterfaceImpl::setPhyParams()
#if !defined(POCO_OS_FAMILY_WINDOWS) && !defined(POCO_VXWORKS)
struct ifreq ifr;
std::strncpy(ifr.ifr_name, _name.c_str(), IFNAMSIZ);
DatagramSocket ds;
DatagramSocket ds(SocketAddress::IPv4);
ds.impl()->ioctl(SIOCGIFFLAGS, &ifr);
setFlags(ifr.ifr_flags);

View File

@@ -76,14 +76,14 @@ void RemoteSyslogChannel::open()
{
if (_open) return;
// reset socket for the case that it has been previously closed
_socket = DatagramSocket();
if (_logHost.find(':') != std::string::npos)
_socketAddress = SocketAddress(_logHost);
else
_socketAddress = SocketAddress(_logHost, SYSLOG_PORT);
// reset socket for the case that it has been previously closed
_socket = DatagramSocket(_socketAddress.family());
if (_host.empty())
{
try

View File

@@ -64,7 +64,7 @@ void DatagramSocketTest::testEcho()
void DatagramSocketTest::testSendToReceiveFrom()
{
UDPEchoServer echoServer(SocketAddress("localhost", 0));
DatagramSocket ss;
DatagramSocket ss(SocketAddress::IPv4);
int n = ss.sendTo("hello", 5, SocketAddress("localhost", echoServer.port()));
assert (n == 5);
char buffer[256];
@@ -81,7 +81,7 @@ void DatagramSocketTest::testSendToReceiveFrom()
void DatagramSocketTest::testUnbound()
{
UDPEchoServer echoServer;
DatagramSocket ss(DatagramSocket::SOCKET_CREATE_UNBOUND);
DatagramSocket ss;
char buffer[256];
ss.connect(SocketAddress("localhost", echoServer.port()));
int n = ss.sendBytes("hello", 5);

View File

@@ -50,7 +50,7 @@ MulticastSocketTest::~MulticastSocketTest()
void MulticastSocketTest::testMulticast()
{
MulticastEchoServer echoServer;
MulticastSocket ms;
MulticastSocket ms(SocketAddress::IPv4);
int n = ms.sendTo("hello", 5, echoServer.group());
assert (n == 5);
char buffer[256];