Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/System/Socket.hsc
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ module System.Socket (
-- * Operations
-- ** socket
, socket
-- ** socketToFd
, socketToFd
-- ** connect
, connect
-- ** bind
Expand Down Expand Up @@ -144,6 +146,7 @@ import GHC.Conc ( closeFdWith )

import Foreign.Storable
import Foreign.Marshal.Alloc
import System.Posix.Types (Fd (..))

import System.Socket.Unsafe

Expand Down Expand Up @@ -455,3 +458,9 @@ getAddress = getAddress'
when (i /= 0) (SocketException <$> peek errPtr >>= throwIO)
addr <- peek addrPtr
return addr

-- | Invalidate the given 'Socket' and return the file descriptor
-- it held. All calls on the socket will fail after this call.
-- Additionally, the file descriptor needs to be closed manually.
socketToFd :: Socket f t p -> IO Fd
socketToFd (Socket mfd) = Fd . fromIntegral <$> swapMVar mfd (-1)