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:
Denis CLAVIER 2023-01-24 12:46:10 +01:00 committed by GitHub
parent ac0c62ebf4
commit d4e2e00482
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 2 deletions

View File

@ -257,8 +257,7 @@ NetworkInterface MulticastSocket::findFirstInterface(const IPAddress& groupAddre
void MulticastSocket::leaveGroup(const IPAddress& groupAddress)
{
NetworkInterface intf;
leaveGroup(groupAddress, intf);
leaveGroup(groupAddress, findFirstInterface(groupAddress));
}

View File

@ -51,6 +51,8 @@ void MulticastSocketTest::testMulticast()
{
MulticastEchoServer echoServer;
MulticastSocket ms(SocketAddress::IPv4);
SocketAddress multicastAddress("234.2.2.2", 4040);
ms.joinGroup(multicastAddress.host());
ms.setReceiveTimeout(Poco::Timespan(5, 0));
int n = ms.sendTo("hello", 5, echoServer.group());
assertTrue (n == 5);
@ -58,6 +60,7 @@ void MulticastSocketTest::testMulticast()
n = ms.receiveBytes(buffer, sizeof(buffer));
assertTrue (n == 5);
assertTrue (std::string(buffer, n) == "hello");
ms.leaveGroup(multicastAddress.host());
ms.close();
}
catch (Poco::NotImplementedException&)