Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding join/leave to UDPSocket #127

Closed
kydos opened this issue Apr 28, 2017 · 3 comments
Closed

Adding join/leave to UDPSocket #127

kydos opened this issue Apr 28, 2017 · 3 comments
Assignees
Milestone

Comments

@kydos
Copy link

kydos commented Apr 28, 2017

It would be nice to add join/lease operations to the UDPSocket to facilitate the joining/leaving of multicast groups. Today the operation can be achieved by using setsockopt and could be already made a bit more user friendly by addressing the Issue #125. However, the most user-friendly solution would be to add join/leave operations straight on the UDPSocket class.

Below a possible implementation for the functionality:

  private func createMembershipRequest(_ ip: String, _ ifaddr: String) -> ip_mreq {
        let group = inet_addr(ip)
        let iface = inet_addr(ifaddr)
        var imr =  ip_mreq()
        imr.imr_multiaddr.s_addr = group;
        imr.imr_interface.s_addr = iface
        return imr
    }
    
    public func join(group mcastAddr: String, iface ifname: String) throws {
        let imr = self.createMembershipRequest(mcastAddr, ifname)
        try self.descriptor.setOption(level: IPPROTO_IP, name: IP_ADD_MEMBERSHIP, value: imr)
    
    }
    
    public func leave(group mcastAddr: String, iface ifname: String) throws {
        let imr = self.createMembershipRequest(mcastAddr, ifname)
        try self.descriptor.setOption(level: IPPROTO_IP, name: IP_ADD_MEMBERSHIP, value: imr)
    
    }

Ciao, Kydos

@tanner0101 tanner0101 self-assigned this May 1, 2017
@tanner0101 tanner0101 added this to the 2.0 milestone May 1, 2017
@tanner0101
Copy link
Collaborator

This code looks good. Would you want to submit a PR to implement this feature?

@kydos
Copy link
Author

kydos commented May 3, 2017

I've done a bunch of other enhancements on my branch. Let me finalise my contribution and then I'll do a Pull Request. Among other things I have a buffer a la java.nio.ByteBuffer to contribute along with send/rcv operations on the socket that operate on this ByteBuffer w/o allocating memory at each time.

I'll probably have things cleaned up and committed on my branch by later today.

-- Kydos

@tanner0101
Copy link
Collaborator

We've moved to a new, streaming TCP setup in Vapor 3. If you're interested in submitting code for that, please open a PR. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants