@@ -57,6 +57,7 @@ import Network.Socket.Internal
5757import System.Posix.Types (Fd (.. ))
5858
5959import Network.Socket.Flag
60+ import Network.Socket.SockAddr (annotateWithSocket )
6061
6162#if !defined(mingw32_HOST_OS)
6263import Network.Socket.Posix.Cmsg
@@ -78,8 +79,10 @@ import Network.Socket.Win32.MsgHdr (MsgHdr(..))
7879send :: Socket -- ^ Connected socket
7980 -> ByteString -- ^ Data to send
8081 -> IO Int -- ^ Number of bytes sent
81- send s xs = unsafeUseAsCStringLen xs $ \ (str, len) ->
82- sendBuf s (castPtr str) len
82+ send s xs = send' `annotateWithSocket` (s, Nothing )
83+ where
84+ send' = unsafeUseAsCStringLen xs $ \ (str, len) ->
85+ sendBuf s (castPtr str) len
8386
8487waitWhen0 :: Int -> Socket -> IO ()
8588waitWhen0 0 s = when rtsSupportsBoundThreads $
@@ -145,11 +148,12 @@ sendMany :: Socket -- ^ Connected socket
145148 -> [ByteString ] -- ^ Data to send
146149 -> IO ()
147150sendMany _ [] = return ()
148- sendMany s cs = do
149- sent <- sendManyInner
150- waitWhen0 sent s
151- when (sent >= 0 ) $ sendMany s $ remainingChunks sent cs
151+ sendMany s cs = sendMany' `annotateWithSocket` (s, Nothing )
152152 where
153+ sendMany' = do
154+ sent <- sendManyInner
155+ waitWhen0 sent s
156+ when (sent >= 0 ) $ sendMany s $ remainingChunks sent cs
153157 sendManyInner =
154158#if !defined(mingw32_HOST_OS)
155159 fmap fromIntegral . withIOVecfromBS cs $ \ (iovsPtr, iovsLen) ->
@@ -178,11 +182,12 @@ sendManyTo :: Socket -- ^ Socket
178182 -> SockAddr -- ^ Recipient address
179183 -> IO ()
180184sendManyTo _ [] _ = return ()
181- sendManyTo s cs addr = do
182- sent <- fromIntegral <$> sendManyToInner
183- waitWhen0 sent s
184- when (sent >= 0 ) $ sendManyTo s (remainingChunks sent cs) addr
185+ sendManyTo s cs addr = sendManyTo' `annotateWithSocket` (s, Nothing )
185186 where
187+ sendManyTo' = do
188+ sent <- fromIntegral <$> sendManyToInner
189+ waitWhen0 sent s
190+ when (sent >= 0 ) $ sendManyTo s (remainingChunks sent cs) addr
186191 sendManyToInner =
187192 withSockAddr addr $ \ addrPtr addrSize ->
188193#if !defined(mingw32_HOST_OS)
@@ -225,11 +230,11 @@ sendManyWithFds :: Socket -- ^ Socket
225230 -> [ByteString ] -- ^ Data to send
226231 -> [Fd ] -- ^ File descriptors
227232 -> IO ()
228- sendManyWithFds s bss fds =
229- void $
233+ sendManyWithFds s bss fds = sendManyWithFds' `annotateWithSocket` (s, Nothing )
234+ where
235+ sendManyWithFds' = void $
230236 withBufSizs bss $ \ bufsizs ->
231237 sendBufMsg s addr bufsizs cmsgs flags
232- where
233238 addr = NullSockAddr
234239 cmsgs = encodeCmsg . (: [] ) <$> fds
235240 flags = mempty
@@ -257,8 +262,8 @@ recv :: Socket -- ^ Connected socket
257262 -> Int -- ^ Maximum number of bytes to receive
258263 -> IO ByteString -- ^ Data received
259264recv s nbytes
260- | nbytes < 0 = ioError (mkInvalidRecvArgError " Network.Socket.ByteString.recv" )
261- | otherwise = createAndTrim nbytes $ \ ptr -> recvBuf s ptr nbytes
265+ | nbytes < 0 = ioError (mkInvalidRecvArgError " Network.Socket.ByteString.recv" ) `annotateWithSocket` (s, Nothing )
266+ | otherwise = createAndTrim nbytes $ \ ptr -> recvBuf s ptr nbytes `annotateWithSocket` (s, Nothing )
262267
263268-- | Receive data from the socket. The socket need not be in a
264269-- connected state. Returns @(bytes, address)@ where @bytes@ is a
@@ -323,8 +328,10 @@ sendMsg :: Socket -- ^ Socket
323328 -> MsgFlag -- ^ Message flags
324329 -> IO Int -- ^ The length actually sent
325330sendMsg _ _ [] _ _ = return 0
326- sendMsg s addr bss cmsgs flags = withBufSizs bss $ \ bufsizs ->
327- sendBufMsg s addr bufsizs cmsgs flags
331+ sendMsg s addr bss cmsgs flags = sendMsg' `annotateWithSocket` (s, Just addr)
332+ where
333+ sendMsg' = withBufSizs bss $ \ bufsizs ->
334+ sendBufMsg s addr bufsizs cmsgs flags
328335
329336-- | Receive data from the socket using recvmsg(2).
330337recvMsg :: Socket -- ^ Socket
@@ -336,10 +343,12 @@ recvMsg :: Socket -- ^ Socket
336343 -- 'MSG_CTRUNC' is returned
337344 -> MsgFlag -- ^ Message flags
338345 -> IO (SockAddr , ByteString , [Cmsg ], MsgFlag ) -- ^ Source address, received data, control messages and message flags
339- recvMsg s siz clen flags = do
340- bs@ (PS fptr _ _) <- create siz $ \ ptr -> zeroMemory ptr (fromIntegral siz)
341- withForeignPtr fptr $ \ ptr -> do
342- (addr,len,cmsgs,flags') <- recvBufMsg s [(ptr,siz)] clen flags
343- let bs' | len < siz = PS fptr 0 len
344- | otherwise = bs
345- return (addr, bs', cmsgs, flags')
346+ recvMsg s siz clen flags = recvMsg' `annotateWithSocket` (s, Nothing )
347+ where
348+ recvMsg' = do
349+ bs@ (PS fptr _ _) <- create siz $ \ ptr -> zeroMemory ptr (fromIntegral siz)
350+ withForeignPtr fptr $ \ ptr -> do
351+ (addr,len,cmsgs,flags') <- recvBufMsg s [(ptr,siz)] clen flags
352+ let bs' | len < siz = PS fptr 0 len
353+ | otherwise = bs
354+ return (addr, bs', cmsgs, flags')
0 commit comments