@@ -19,6 +19,7 @@ import System.IO.Error (isAlreadyInUseError, isDoesNotExistError)
1919import qualified Network.Socket.Buffer as G
2020import Network.Socket.Flag
2121import Network.Socket.Imports
22+ import Network.Socket.Internal
2223import qualified Network.Socket.Name as G
2324import qualified Network.Socket.Syscall as G
2425#if !defined(mingw32_HOST_OS)
@@ -30,23 +31,26 @@ import Network.Socket.Types
3031
3132-- | Getting peer's 'SockAddr'.
3233getPeerName :: Socket -> IO SockAddr
33- getPeerName = G. getPeerName
34+ getPeerName s = G. getPeerName s `annotateIOException` show s
3435
3536-- | Getting my 'SockAddr'.
3637getSocketName :: Socket -> IO SockAddr
37- getSocketName = G. getSocketName
38+ getSocketName s = G. getSocketName s `annotateIOException` show s
3839
3940-- | Connect to a remote socket at address.
4041connect :: Socket -> SockAddr -> IO ()
41- connect = G. connect
42+ connect s sa = G. connect s sa `annotateIOException` ( show s ++ " " ++ show sa)
4243
4344-- | Bind the socket to an address. The socket must not already be
4445-- bound. The 'Family' passed to @bind@ must be the
4546-- same as that passed to 'socket'. If the special port number
4647-- 'defaultPort' is passed then the system assigns the next available
4748-- use port.
4849bind :: Socket -> SockAddr -> IO ()
49- bind s sa = case sa of
50+ bind s sa = bind' s sa `annotateIOException` (show s ++ " " ++ show sa)
51+
52+ bind' :: Socket -> SockAddr -> IO ()
53+ bind' s sa = case sa of
5054 SockAddrUnix p -> do
5155 -- gracefully handle the fact that UNIX systems don't clean up closed UNIX
5256 -- domain sockets, inspired by https://stackoverflow.com/a/13719866
@@ -73,14 +77,14 @@ bind s sa = case sa of
7377-- to the socket on the other end of the connection.
7478-- On Unix, FD_CLOEXEC is set to the new 'Socket'.
7579accept :: Socket -> IO (Socket , SockAddr )
76- accept = G. accept
80+ accept s = G. accept s `annotateIOException` show s
7781
7882-- | Send data to the socket. The recipient can be specified
7983-- explicitly, so the socket need not be in a connected state.
8084-- Returns the number of bytes sent. Applications are responsible for
8185-- ensuring that all data has been sent.
8286sendBufTo :: Socket -> Ptr a -> Int -> SockAddr -> IO Int
83- sendBufTo = G. sendBufTo
87+ sendBufTo s ptr len sa = G. sendBufTo s ptr len sa `annotateIOException` ( show s ++ " " ++ show sa)
8488
8589-- | Receive data from the socket, writing it into buffer instead of
8690-- creating a new string. The socket need not be in a connected
@@ -95,7 +99,7 @@ sendBufTo = G.sendBufTo
9599-- NOTE: blocking on Windows unless you compile with -threaded (see
96100-- GHC ticket #1129)
97101recvBufFrom :: Socket -> Ptr a -> Int -> IO (Int , SockAddr )
98- recvBufFrom = G. recvBufFrom
102+ recvBufFrom s ptr len = G. recvBufFrom s ptr len `annotateIOException` show s
99103
100104-- | Send data to the socket using sendmsg(2).
101105sendBufMsg
@@ -111,7 +115,9 @@ sendBufMsg
111115 -- ^ Message flags
112116 -> IO Int
113117 -- ^ The length actually sent
114- sendBufMsg = G. sendBufMsg
118+ sendBufMsg s sa dats cmgs flag =
119+ G. sendBufMsg s sa dats cmgs flag
120+ `annotateIOException` (show s ++ " " ++ show sa)
115121
116122-- | Receive data from the socket using recvmsg(2).
117123recvBufMsg
@@ -129,4 +135,4 @@ recvBufMsg
129135 -- ^ Message flags
130136 -> IO (SockAddr , Int , [Cmsg ], MsgFlag )
131137 -- ^ Source address, received data, control messages and message flags
132- recvBufMsg = G. recvBufMsg
138+ recvBufMsg s bufs len flag = G. recvBufMsg s bufs len flag `annotateIOException` show s
0 commit comments