diff options
author | Will Szumski <will@cowboycoders.org> | 2014-12-18 00:45:02 +0000 |
---|---|---|
committer | Will Szumski <will@cowboycoders.org> | 2014-12-18 00:45:02 +0000 |
commit | 1b614ffc8044d9efcf5ae5c9ad59f2416e8ccfa2 (patch) | |
tree | 8baec4e240d6c0c38c10a6a70e95a146ecceac5f | |
parent | ff24ca99193190615252aa3d8ec2a56f9aaa3def (diff) | |
download | Nim-1b614ffc8044d9efcf5ae5c9ad59f2416e8ccfa2.tar.gz |
ensure file descriptor is closed
-rw-r--r-- | lib/pure/net.nim | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/lib/pure/net.nim b/lib/pure/net.nim index 2b7b96c65..28b84eb39 100644 --- a/lib/pure/net.nim +++ b/lib/pure/net.nim @@ -432,19 +432,21 @@ proc accept*(server: Socket, client: var Socket, proc close*(socket: Socket) = ## Closes a socket. - when defined(ssl): - if socket.isSSL: - ErrClearError() - # As we are closing the underlying socket immediately afterwards, - # it is valid, under the TLS standard, to perform a unidirectional - # shutdown i.e not wait for the peers "close notify" alert with a second - # call to SSLShutdown - let res = SSLShutdown(socket.sslHandle) - if res == 0: - discard - elif res != 1: - socketError(socket, res) - socket.fd.close() + try: + when defined(ssl): + if socket.isSSL: + ErrClearError() + # As we are closing the underlying socket immediately afterwards, + # it is valid, under the TLS standard, to perform a unidirectional + # shutdown i.e not wait for the peers "close notify" alert with a second + # call to SSLShutdown + let res = SSLShutdown(socket.sslHandle) + if res == 0: + discard + elif res != 1: + socketError(socket, res) + finally: + socket.fd.close() proc toCInt*(opt: SOBool): cint = ## Converts a ``SOBool`` into its Socket Option cint representation. |