-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Description
I am trying to implement an UDP multicast socket on Windows 10 with POCO. I can create the multicast socket and join a multicast group without issue. When I want to close the socket, I try to leave the multicast group previously joined, but it raises an NotFoundException from firstAddress() method.
Analysis
The NotFoundException is raised because _addressList is empty.
In fact, the method firstAddress() is called on object interfc from method leaveGroup(), but this object is empty since it is created just before in method leaveGroup() with the default constructor. This constructor does not initialize the attribute _addressList which remains empty.
So the problem come from the line 260 of MulticastSocket.cpp, and I don't know how this can work.
Solution
I think the method leaveGroup() should use findFirstInterface(groupAddress) instead of create a new NetworkInterface, as it is done in the method joinGroup() which works well.
I can do a merge request if needed.
Code example
Below an C++ implementation to reproduce the bug :
#include <Poco/Net/DatagramSocket.h>
#include <Poco/Net/SocketAddress.h>
#include <Poco/Net/MulticastSocket.h>
using Poco::Net::DatagramSocket;
using Poco::Net::SocketAddress;
using Poco::Net::MulticastSocket;
int main()
{
const std::string multicastAddress = "234.2.2.2";
const Poco::UInt16 multicastPort = 4040;
const std::string sourceAddress = "0.0.0.0";
SocketAddress sourceAddr(sourceAddress, multicastPort);
SocketAddress multicastAddr(multicastAddress, multicastPort);
MulticastSocket multicastSocket(sourceAddr, true);
multicastSocket.setLoopback(true);
multicastSocket.setLoopback(3);
multicastSocket.joinGroup(multicastAddr.host());
multicastSocket.leaveGroup(multicastAddr.host()); // Raise NotFoundException
return 0;
}