mirror of
https://github.com/pocoproject/poco.git
synced 2025-04-01 01:16:55 +02:00
fixed #892: DatagramSocket is ipv4 by default (added new constructors for creating an unconnected and unbound DatagramSocket or MulticastSocket)
This commit is contained in:
parent
fa4e739860
commit
4f7b7a7734
@ -33,9 +33,17 @@ class Net_API DatagramSocket: public Socket
|
|||||||
/// UDP stream socket.
|
/// UDP stream socket.
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
enum Unbound
|
||||||
|
{
|
||||||
|
SOCKET_CREATE_UNBOUND
|
||||||
|
};
|
||||||
|
|
||||||
DatagramSocket();
|
DatagramSocket();
|
||||||
/// Creates an unconnected IPv4 datagram socket.
|
/// Creates an unconnected IPv4 datagram socket.
|
||||||
|
|
||||||
|
explicit DatagramSocket(Unbound unbound);
|
||||||
|
/// Creates an unconnected, unbound datagram socket.
|
||||||
|
|
||||||
explicit DatagramSocket(IPAddress::Family family);
|
explicit DatagramSocket(IPAddress::Family family);
|
||||||
/// Creates an unconnected datagram socket.
|
/// Creates an unconnected datagram socket.
|
||||||
///
|
///
|
||||||
|
@ -33,11 +33,7 @@ class Net_API DatagramSocketImpl: public SocketImpl
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
DatagramSocketImpl();
|
DatagramSocketImpl();
|
||||||
/// Creates a DatagramSocketImpl.
|
/// Creates an unconnected, unbound datagram socket.
|
||||||
///
|
|
||||||
/// If the system supports IPv6, the socket will
|
|
||||||
/// be an IPv6 socket. Otherwise, it will be
|
|
||||||
/// an IPv4 socket.
|
|
||||||
|
|
||||||
explicit DatagramSocketImpl(IPAddress::Family family);
|
explicit DatagramSocketImpl(IPAddress::Family family);
|
||||||
/// Creates an unconnected datagram socket.
|
/// Creates an unconnected datagram socket.
|
||||||
|
@ -41,7 +41,10 @@ class Net_API MulticastSocket: public DatagramSocket
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MulticastSocket();
|
MulticastSocket();
|
||||||
/// Creates the MulticastSocket.
|
/// Creates the multicast socket.
|
||||||
|
|
||||||
|
explicit MulticastSocket(Unbound unbound);
|
||||||
|
/// Creates an unconnected, unbound multicast datagram socket.
|
||||||
|
|
||||||
explicit MulticastSocket(IPAddress::Family family);
|
explicit MulticastSocket(IPAddress::Family family);
|
||||||
/// Creates an unconnected datagram socket.
|
/// Creates an unconnected datagram socket.
|
||||||
|
@ -31,6 +31,11 @@ DatagramSocket::DatagramSocket(): Socket(new DatagramSocketImpl)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
DatagramSocket::DatagramSocket(Unbound): Socket(new DatagramSocketImpl(POCO_INVALID_SOCKET))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
DatagramSocket::DatagramSocket(IPAddress::Family family): Socket(new DatagramSocketImpl(family))
|
DatagramSocket::DatagramSocket(IPAddress::Family family): Socket(new DatagramSocketImpl(family))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -53,6 +53,11 @@ MulticastSocket::MulticastSocket()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
MulticastSocket::MulticastSocket(Unbound unbound): DatagramSocket(unbound)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
MulticastSocket::MulticastSocket(IPAddress::Family family): DatagramSocket(family)
|
MulticastSocket::MulticastSocket(IPAddress::Family family): DatagramSocket(family)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -78,6 +78,21 @@ void DatagramSocketTest::testSendToReceiveFrom()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void DatagramSocketTest::testUnbound()
|
||||||
|
{
|
||||||
|
UDPEchoServer echoServer;
|
||||||
|
DatagramSocket ss(DatagramSocket::SOCKET_CREATE_UNBOUND);
|
||||||
|
char buffer[256];
|
||||||
|
ss.connect(SocketAddress("localhost", echoServer.port()));
|
||||||
|
int n = ss.sendBytes("hello", 5);
|
||||||
|
assert (n == 5);
|
||||||
|
n = ss.receiveBytes(buffer, sizeof(buffer));
|
||||||
|
assert (n == 5);
|
||||||
|
assert (std::string(buffer, n) == "hello");
|
||||||
|
ss.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void DatagramSocketTest::testBroadcast()
|
void DatagramSocketTest::testBroadcast()
|
||||||
{
|
{
|
||||||
UDPEchoServer echoServer;
|
UDPEchoServer echoServer;
|
||||||
@ -136,6 +151,7 @@ CppUnit::Test* DatagramSocketTest::suite()
|
|||||||
|
|
||||||
CppUnit_addTest(pSuite, DatagramSocketTest, testEcho);
|
CppUnit_addTest(pSuite, DatagramSocketTest, testEcho);
|
||||||
CppUnit_addTest(pSuite, DatagramSocketTest, testSendToReceiveFrom);
|
CppUnit_addTest(pSuite, DatagramSocketTest, testSendToReceiveFrom);
|
||||||
|
CppUnit_addTest(pSuite, DatagramSocketTest, testUnbound);
|
||||||
#if (POCO_OS != POCO_OS_FREE_BSD) // works only with local net bcast and very randomly
|
#if (POCO_OS != POCO_OS_FREE_BSD) // works only with local net bcast and very randomly
|
||||||
CppUnit_addTest(pSuite, DatagramSocketTest, testBroadcast);
|
CppUnit_addTest(pSuite, DatagramSocketTest, testBroadcast);
|
||||||
#endif
|
#endif
|
||||||
|
@ -28,6 +28,7 @@ public:
|
|||||||
|
|
||||||
void testEcho();
|
void testEcho();
|
||||||
void testSendToReceiveFrom();
|
void testSendToReceiveFrom();
|
||||||
|
void testUnbound();
|
||||||
void testBroadcast();
|
void testBroadcast();
|
||||||
|
|
||||||
void setUp();
|
void setUp();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user