From 904854ee0aaa34ed106307e8531ae4000d986797 Mon Sep 17 00:00:00 2001 From: Andrew Martin Date: Fri, 18 Jan 2019 09:41:07 -0500 Subject: [PATCH] add uninterruptibleErrorlessClose --- src/Posix/Socket.hs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/Posix/Socket.hs b/src/Posix/Socket.hs index b1722e9..0700259 100644 --- a/src/Posix/Socket.hs +++ b/src/Posix/Socket.hs @@ -45,6 +45,7 @@ module Posix.Socket -- ** Close , close , uninterruptibleClose + , uninterruptibleErrorlessClose -- ** Shutdown , uninterruptibleShutdown -- ** Send @@ -731,6 +732,19 @@ uninterruptibleClose :: -> IO (Either Errno ()) uninterruptibleClose fd = c_unsafe_close fd >>= errorsFromInt +-- | Close a socket with the unsafe FFI. Do not check for errors. It is only +-- appropriate to use this when a socket is being closed to handle an +-- exceptional case. Since the user will want the propogate the original +-- exception, the exception provided by 'uninterruptibleClose' would just +-- be discarded. This function allows us to potentially avoid an additional +-- FFI call to 'getErrno'. +uninterruptibleErrorlessClose :: + Fd -- ^ Socket + -> IO () +uninterruptibleErrorlessClose fd = do + _ <- c_unsafe_close fd + pure () + -- | Shutdown a socket. This uses the unsafe FFI. uninterruptibleShutdown :: Fd