about summary refs log tree commit diff
diff options
context:
space:
mode:
authorsternenseemann <0rpkxez4ksa01gb3typccl0i@systemli.org>2021-03-16 21:01:15 +0100
committersternenseemann <0rpkxez4ksa01gb3typccl0i@systemli.org>2021-03-16 21:02:28 +0100
commitcf648932c00a17d91f69c29151eea11a7c499c2b (patch)
treebe97b88a24ce7f63d229bd4aee3798db926d6839
parent8aa1911f993fd84dc6004787e803171906cfffd0 (diff)
fix(Util.Socket): actually close the socket in gracefulClose
The close call was missing due to a previous oversight. While the socket
should have been closed by its finalizer, doing it explicitly is cleaner
and probably also means more predictable performance.
-rw-r--r--src/Network/Gopher/Util/Socket.hs6
1 files changed, 3 insertions, 3 deletions
diff --git a/src/Network/Gopher/Util/Socket.hs b/src/Network/Gopher/Util/Socket.hs
index 023aa1d..1a1eb9d 100644
--- a/src/Network/Gopher/Util/Socket.hs
+++ b/src/Network/Gopher/Util/Socket.hs
@@ -13,7 +13,7 @@ import Control.Monad (void, when)
 import Data.Functor ((<&>))
 import Foreign.C.Error (Errno (..), getErrno)
 import Foreign.C.Types (CInt (..))
-import System.Socket (receive, msgNoSignal, SocketException (..))
+import System.Socket (receive, msgNoSignal, SocketException (..), close, Family ())
 import System.Socket.Type.Stream (Stream ())
 import System.Socket.Protocol.TCP (TCP ())
 import System.Socket.Unsafe (Socket (..))
@@ -48,7 +48,7 @@ shutdown (Socket mvar) how = withMVar mvar $ \fd -> do
 --   of time to clean up on its end before closing
 --   the connection to avoid a broken pipe on the
 --   other side.
-gracefulClose :: Socket a Stream TCP -> IO ()
+gracefulClose :: Family f => Socket f Stream TCP -> IO ()
 gracefulClose sock = do
   -- send TCP FIN
   shutdown sock ShutdownWrite
@@ -57,4 +57,4 @@ gracefulClose sock = do
   -- something else which would mean protocol
   -- violation). Give up after 1s.
   _ <- race (void $ receive sock 16 msgNoSignal) (threadDelay 1000000)
-  pure ()
+  close sock