Skip to content

Commit 83bd54d

Browse files
committed
fixing labelSocket
1 parent 09c8784 commit 83bd54d

3 files changed

Lines changed: 8 additions & 5 deletions

File tree

Network/Socket.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,8 @@ module Network.Socket (
287287
isSupportedFamily,
288288
packFamily,
289289
unpackFamily,
290+
labelSocket,
291+
socketLabel,
290292

291293
-- ** Protocol number
292294
ProtocolNumber,

Network/Socket/SockAddr.hs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ bind' s sa = case sa of
7777
G.bind s sa
7878
_ -> do
7979
G.bind s sa
80-
labelSocket s (\label -> label ++ "" ++ show sa)
80+
labelSocket s (\label -> label ++ " " ++ show sa)
8181

8282
-- | Accept a connection. The socket must be bound to an address and
8383
-- listening for connections. The return value is a pair @(conn,
@@ -90,7 +90,8 @@ accept s = accept' `annotateWithSocket` (s, Nothing)
9090
where
9191
accept' = do
9292
r@(news, sa) <- G.accept s
93-
labelSocket news (\label -> label ++ " " ++ show sa)
93+
label <- socketLabel s
94+
labelSocket news (\_ -> label ++ " " ++ show sa)
9495
return r
9596

9697
-- | Send data to the socket. The recipient can be specified
@@ -156,6 +157,6 @@ annotateWithSocket :: IO a -> (Socket, Maybe SockAddr) -> IO a
156157
annotateWithSocket io (s, mpeersa) = do
157158
label <- socketLabel s
158159
let label' = case mpeersa of
159-
Nothing -> label
160-
Just peersa -> label ++ " " ++ show peersa
160+
Nothing -> "<" ++ label ++ ">"
161+
Just peersa -> "<" ++ label ++ "> " ++ show peersa
161162
annotateIOException io label'

Network/Socket/Types.hsc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ foreign import ccall unsafe "dup"
222222
mkSocket :: CInt -> IO Socket
223223
mkSocket fd = do
224224
ref <- newIORef fd
225-
anno <- newIORef ""
225+
anno <- newIORef $ "sock " ++ show fd
226226
let s = Socket ref fd anno
227227
void $ mkWeakIORef ref $ close s
228228
return s

0 commit comments

Comments
 (0)