ensure file descriptor is closed
This commit is contained in:
parent
ff24ca9919
commit
1b614ffc80
1 changed files with 15 additions and 13 deletions
|
|
@ -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.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue