vapor-community / sockets

🔌 Non-blocking TCP socket layer, with event-driven server and client.
MIT License
575 stars 54 forks source link

Adding set/getReusePort to RawSocket #126

Closed kydos closed 6 years ago

kydos commented 7 years ago

Hello,

The semantics of SO_REUSEADDR and SO_REUSEPORT  is different and as a consequence both options are required when dealing with different cases. 

Below the code:

    public func setReusePort(_ newValue: Bool) throws {
        if isClosed { throw SocketsError(.socketIsClosed) }
        try descriptor.setBoolOption(level: SOL_SOCKET, name: SO_REUSEPORT, value: newValue)
    }

    public func getReusePort(_ newValue: Bool) throws -> Bool {
        if isClosed { throw SocketsError(.socketIsClosed) }
        return try descriptor.getBoolOption(level: SOL_SOCKET, name: SO_REUSEPORT)
    }

Ciao, Kydos

tanner0101 commented 7 years ago

Are you asking for a method for setting SO_REUSEADDR to be added?

kydos commented 7 years ago

The method that sets the SO_REUSEADDR is already in place but that is not sufficient in some cases, e.g. UPD socket bound to 0.0.0.0:1234 that joins a multicast address say 239.255.0.1 and for which you may have multiple apps joining the same (multicast-addres,port) on the same host. On MacOS that requires you to set SO_REUSEPORT.

Makes sense?

tanner0101 commented 6 years ago

We support reuse port now in Vapor 3.