@@ -160,6 +160,7 @@ module Network.Socket
160
160
-- in case you ever want to get at the underlying file descriptor..
161
161
, fdSocket
162
162
, mkSocket
163
+ , setNonBlockIfNeeded
163
164
164
165
-- * Deprecated aliases
165
166
-- $deprecated-aliases
@@ -262,6 +263,10 @@ socket2FD (MkSocket fd _ _ _ _) =
262
263
FD {fdFD = fd,fdIsSocket_ = 1 }
263
264
#endif
264
265
266
+ -- | Smart constructor for constructing a 'Socket'. It should only be
267
+ -- called once for every new file descriptor. The caller must make
268
+ -- sure that the socket is in non-blocking mode. See
269
+ -- 'setNonBlockIfNeeded'.
265
270
mkSocket :: CInt
266
271
-> Family
267
272
-> SocketType
@@ -390,6 +395,9 @@ foreign import ccall unsafe "socketpair"
390
395
#endif
391
396
392
397
-- | Set the socket to nonblocking, if applicable to this platform.
398
+ --
399
+ -- Depending on the platform this is required when using sockets from file
400
+ -- descriptors that are passed in through 'recvFd' or other means.
393
401
setNonBlockIfNeeded :: CInt -> IO ()
394
402
setNonBlockIfNeeded fd =
395
403
System.Posix.Internals. setNonBlockingFD fd True
@@ -1023,6 +1031,9 @@ sendFd sock outfd = do
1023
1031
-- incorrect (since socket FDs need to be closed via closesocket().)
1024
1032
closeFd outfd
1025
1033
1034
+ -- | Receive a file descriptor over a domain socket. Note that the resulting
1035
+ -- file descriptor may have to be put into non-blocking mode in order to be
1036
+ -- used safely. See 'setNonBlockIfNeeded'.
1026
1037
recvFd :: Socket -> IO CInt
1027
1038
recvFd sock = do
1028
1039
theFd <- throwSocketErrorWaitRead sock " Network.Socket.recvFd" $
0 commit comments