Skip to content

Commit e270b58

Browse files
committed
replacing fdSocket with unsafeFdSocket.
1 parent d0557cf commit e270b58

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

Network/Socket/Buffer.hsc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ sendBufTo s ptr nbytes sa =
5151
#if defined(mingw32_HOST_OS)
5252
socket2FD :: Socket -> IO FD
5353
socket2FD s = do
54-
fd <- fdSocket s
54+
fd <- unsafeFdSocket s
5555
-- HACK, 1 means True
5656
return $ FD{ fdFD = fd, fdIsSocket_ = 1 }
5757
#endif

Network/Socket/Types.hsc

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,16 +97,17 @@ instance Eq Socket where
9797
Socket ref1 _ == Socket ref2 _ = ref1 == ref2
9898

9999
{-# DEPRECATED fdSocket "Use withFdSocket or unsafeFdSocket instead" #-}
100+
-- | Currently, this is an alias of `unsafeFdSocket`.
100101
fdSocket :: Socket -> IO CInt
101102
fdSocket = unsafeFdSocket
102103

103104
-- | Getting a file descriptor from a socket.
104105
--
105106
-- If a 'Socket' is shared with multiple threads and
106-
-- one uses 'fdSocket', unexpected issues may happen.
107+
-- one uses 'unsafeFdSocket', unexpected issues may happen.
107108
-- Consider the following scenario:
108109
--
109-
-- 1) Thread A acquires a 'Fd' from 'Socket' by 'fdSocket'.
110+
-- 1) Thread A acquires a 'Fd' from 'Socket' by 'unsafeFdSocket'.
110111
--
111112
-- 2) Thread B close the 'Socket'.
112113
--
@@ -115,7 +116,7 @@ fdSocket = unsafeFdSocket
115116
--
116117
-- In this case, it is safer for Thread A to clone 'Fd' by
117118
-- 'System.Posix.IO.dup'. But this would still suffer from
118-
-- a race condition between 'fdSocket' and 'close'.
119+
-- a race condition between 'unsafeFdSocket' and 'close'.
119120
--
120121
-- If you use this function, you need to guarantee that the 'Socket' does not
121122
-- get garbage-collected until after you finish using the file descriptor.
@@ -190,9 +191,9 @@ invalidateSocket (Socket ref _) errorAction normalAction = do
190191
-- | Close the socket. This function does not throw exceptions even if
191192
-- the underlying system call returns errors.
192193
--
193-
-- If multiple threads use the same socket and one uses 'fdSocket' and
194+
-- If multiple threads use the same socket and one uses 'unsafeFdSocket' and
194195
-- the other use 'close', unexpected behavior may happen.
195-
-- For more information, please refer to the documentation of 'fdSocket'.
196+
-- For more information, please refer to the documentation of 'unsafeFdSocket'.
196197
close :: Socket -> IO ()
197198
close s = invalidateSocket s (\_ -> return ()) $ \oldfd -> do
198199
-- closeFdWith avoids the deadlock of IO manager.

0 commit comments

Comments
 (0)