mirror of
https://github.com/pocoproject/poco.git
synced 2025-04-03 01:54:47 +02:00
Fix multicast leave group (#3929)
* Fix multicast leave group * Add test to join and leave a multicast group Co-authored-by: Denis CLAVIER <denis.clavier@c-s.fr>
This commit is contained in:
parent
ac0c62ebf4
commit
d4e2e00482
@ -257,8 +257,7 @@ NetworkInterface MulticastSocket::findFirstInterface(const IPAddress& groupAddre
|
|||||||
|
|
||||||
void MulticastSocket::leaveGroup(const IPAddress& groupAddress)
|
void MulticastSocket::leaveGroup(const IPAddress& groupAddress)
|
||||||
{
|
{
|
||||||
NetworkInterface intf;
|
leaveGroup(groupAddress, findFirstInterface(groupAddress));
|
||||||
leaveGroup(groupAddress, intf);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -51,6 +51,8 @@ void MulticastSocketTest::testMulticast()
|
|||||||
{
|
{
|
||||||
MulticastEchoServer echoServer;
|
MulticastEchoServer echoServer;
|
||||||
MulticastSocket ms(SocketAddress::IPv4);
|
MulticastSocket ms(SocketAddress::IPv4);
|
||||||
|
SocketAddress multicastAddress("234.2.2.2", 4040);
|
||||||
|
ms.joinGroup(multicastAddress.host());
|
||||||
ms.setReceiveTimeout(Poco::Timespan(5, 0));
|
ms.setReceiveTimeout(Poco::Timespan(5, 0));
|
||||||
int n = ms.sendTo("hello", 5, echoServer.group());
|
int n = ms.sendTo("hello", 5, echoServer.group());
|
||||||
assertTrue (n == 5);
|
assertTrue (n == 5);
|
||||||
@ -58,6 +60,7 @@ void MulticastSocketTest::testMulticast()
|
|||||||
n = ms.receiveBytes(buffer, sizeof(buffer));
|
n = ms.receiveBytes(buffer, sizeof(buffer));
|
||||||
assertTrue (n == 5);
|
assertTrue (n == 5);
|
||||||
assertTrue (std::string(buffer, n) == "hello");
|
assertTrue (std::string(buffer, n) == "hello");
|
||||||
|
ms.leaveGroup(multicastAddress.host());
|
||||||
ms.close();
|
ms.close();
|
||||||
}
|
}
|
||||||
catch (Poco::NotImplementedException&)
|
catch (Poco::NotImplementedException&)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user