From a77d29ab37ef33275660f5928e27d58b4b4f323b Mon Sep 17 00:00:00 2001 From: Robin Goos Date: Thu, 26 Jan 2023 17:55:44 -0800 Subject: [PATCH] Avoid closing sockets twice --- Sources/TCPSocket.swift | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Sources/TCPSocket.swift b/Sources/TCPSocket.swift index 35a10dc..7a02492 100644 --- a/Sources/TCPSocket.swift +++ b/Sources/TCPSocket.swift @@ -201,8 +201,12 @@ public final class TCPSocket { /// Close the socket func close() { + guard fileDescriptor != -1 else { + return + } _ = SystemLibrary.shutdown(fileDescriptor, Int32(SHUT_WR)) _ = SystemLibrary.close(fileDescriptor) + fileDescriptor = -1 } func getPeerName() throws -> (String, Int) {