@@ -97,16 +97,17 @@ instance Eq Socket where
97
97
Socket ref1 _ == Socket ref2 _ = ref1 == ref2
98
98
99
99
{-# DEPRECATED fdSocket "Use withFdSocket or unsafeFdSocket instead" #-}
100
+ -- | Currently, this is an alias of `unsafeFdSocket`.
100
101
fdSocket :: Socket -> IO CInt
101
102
fdSocket = unsafeFdSocket
102
103
103
104
-- | Getting a file descriptor from a socket.
104
105
--
105
106
-- 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.
107
108
-- Consider the following scenario:
108
109
--
109
- -- 1) Thread A acquires a 'Fd' from 'Socket' by 'fdSocket '.
110
+ -- 1) Thread A acquires a 'Fd' from 'Socket' by 'unsafeFdSocket '.
110
111
--
111
112
-- 2) Thread B close the 'Socket'.
112
113
--
@@ -115,7 +116,7 @@ fdSocket = unsafeFdSocket
115
116
--
116
117
-- In this case, it is safer for Thread A to clone 'Fd' by
117
118
-- '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'.
119
120
--
120
121
-- If you use this function, you need to guarantee that the 'Socket' does not
121
122
-- get garbage-collected until after you finish using the file descriptor.
@@ -190,9 +191,9 @@ invalidateSocket (Socket ref _) errorAction normalAction = do
190
191
-- | Close the socket. This function does not throw exceptions even if
191
192
-- the underlying system call returns errors.
192
193
--
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
194
195
-- 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 '.
196
197
close :: Socket -> IO ()
197
198
close s = invalidateSocket s (\ _ -> return () ) $ \ oldfd -> do
198
199
-- closeFdWith avoids the deadlock of IO manager.
0 commit comments