ensure file descriptor is closed

This commit is contained in:
Will Szumski 2014-12-18 00:45:02 +00:00
commit 1b614ffc80

View file

@ -432,19 +432,21 @@ proc accept*(server: Socket, client: var Socket,
proc close*(socket: Socket) = proc close*(socket: Socket) =
## Closes a socket. ## Closes a socket.
when defined(ssl): try:
if socket.isSSL: when defined(ssl):
ErrClearError() if socket.isSSL:
# As we are closing the underlying socket immediately afterwards, ErrClearError()
# it is valid, under the TLS standard, to perform a unidirectional # As we are closing the underlying socket immediately afterwards,
# shutdown i.e not wait for the peers "close notify" alert with a second # it is valid, under the TLS standard, to perform a unidirectional
# call to SSLShutdown # shutdown i.e not wait for the peers "close notify" alert with a second
let res = SSLShutdown(socket.sslHandle) # call to SSLShutdown
if res == 0: let res = SSLShutdown(socket.sslHandle)
discard if res == 0:
elif res != 1: discard
socketError(socket, res) elif res != 1:
socket.fd.close() socketError(socket, res)
finally:
socket.fd.close()
proc toCInt*(opt: SOBool): cint = proc toCInt*(opt: SOBool): cint =
## Converts a ``SOBool`` into its Socket Option cint representation. ## Converts a ``SOBool`` into its Socket Option cint representation.