vapor-community / sockets

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

Fixes for a few crashes related to setsockopt() and getsockopt() #85

Closed andreasley closed 8 years ago

andreasley commented 8 years ago

In certain circumstances, setsockopt() and getsockopt() can fail (e.g. when the socket is already closed). The current version correctly detects that, but the properties for the options would force-try anyway and end up with a crash. This PR deprecates the properties in favor of throwing funcs.

tanner0101 commented 8 years ago

Looks like Travis is complaining:

/home/travis/build/vapor/socks/Tests/SocksCoreTests/OptionsTests.swift:43:59: error: use of unresolved identifier 'SOL_SOCKET'
            guard case ErrorReason.optionGetFailed(level: SOL_SOCKET, name: SO_SNDTIMEO, type: "timeval") = error.type else {
                                                          ^~~~~~~~~~
SwiftGlibc.SOL_SOCKET:1:12: note: did you mean 'SOL_SOCKET'?
public var SOL_SOCKET: Int32 { get }
           ^
/home/travis/build/vapor/socks/Tests/SocksCoreTests/OptionsTests.swift:43:77: error: use of unresolved identifier 'SO_SNDTIMEO'
            guard case ErrorReason.optionGetFailed(level: SOL_SOCKET, name: SO_SNDTIMEO, type: "timeval") = error.type else {
                                                                            ^~~~~~~~~~~
SwiftGlibc.SO_SNDTIMEO:1:12: note: did you mean 'SO_SNDTIMEO'?
public var SO_SNDTIMEO: Int32 { get }
loganwright commented 8 years ago

@tannernelson this looks good to me can you take a look at getting it in. @andreasley you're doing some amazing work on these lower level libraries, thanks so much for the additions!

tanner0101 commented 8 years ago

Thanks @andreasley