MengRao / pollnet

A collection of non-blocking(polling) network libs for Linux, also support solarflare APIs(Tcpdirect/Efvi)
MIT License
213 stars 86 forks source link

Leaving multicast groups #5

Closed gaurang-lakesidetrading closed 2 years ago

gaurang-lakesidetrading commented 2 years ago

First of all, thanks for the project - I've been looking for an opensource ef_vi implementation to use!

I had a couple of questions: a) Is there an equivalent to the unix raw sockets IP_DROP_MEMBERSHIP to leave a multicast group so that the nic/application do not receive the data at all? b) If I need to initialize multiple UDP sockets receiving multicast data, would the usage pattern basically be (given the reads are non blocking):

std::vector<UDPReceiver> receivers;

UDPReceiver recv1;
recv1.init(interface, dest_ip1, dest_port1, sub_ip1);
UDPReceiver recv2;
recv2.init(interface, dest_ip2, dest_port2, sub_ip2);

receivers.push_back(recv1);
receivers.push_back(recv2);

while(true) {
    for(auto& recv : receivers) {
        recv.read([&](const uint8_t* data, uint32_t len) {
           //do something
      }
   }
}
MengRao commented 2 years ago

a) If the subscribed receiver is closed/destructed, the subscribed fd will be closed and automatically drop membership. b) Yes, if you are receiving from multiple addresses, you need to init multpile receivers and poll them all.

gaurang-lakesidetrading commented 2 years ago

Got it, thanks. So if I wanted to rejoin a mcast group, i would just create a new receiver that subscribed to that group again.

MengRao commented 2 years ago

Or you can close a receiver to unsubscribe the group, and later re-init it to join again.

MengRao commented 2 years ago

Also note that UdpReiever is not copyable (although not prohibited for now). So if you are using vector to hold the objects, remember to call reserve() so reallocation and copy can be avoided.

gaurang-lakesidetrading commented 2 years ago

Thank you for the tips!