Skip to content

Commit fe3a66c

Browse files
complyuekazu-yamamoto
authored andcommitted
docup why bracketOnError in accept loop
1 parent 9da532e commit fe3a66c

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

Network/Socket.hs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@
6262
-- > return sock
6363
-- > loop sock = forever $ E.bracketOnError (accept sock) (close . fst)
6464
-- > $ \(conn, _peer) -> void $
65+
-- > -- 'forkFinally' alone is unlikely to fail thus leaking @conn@,
66+
-- > -- but 'E.bracketOnError' above will be necessary if some
67+
-- > -- non-atomic setups (e.g. spawning a subprocess to handle
68+
-- > -- @conn@) before proper cleanup of @conn@ is your case
6569
-- > forkFinally (server conn) (const $ gracefulClose conn 5000)
6670
--
6771
-- > {-# LANGUAGE OverloadedStrings #-}

examples/EchoServer.hs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,8 @@ runTCPServer mhost port server = withSocketsDo $ do
3939
return sock
4040
loop sock = forever $ E.bracketOnError (accept sock) (close . fst)
4141
$ \(conn, _peer) -> void $
42+
-- 'forkFinally' alone is unlikely to fail thus leaking @conn@,
43+
-- but 'E.bracketOnError' above will be necessary if some
44+
-- non-atomic setups (e.g. spawning a subprocess to handle
45+
-- @conn@) before proper cleanup of @conn@ is your case
4246
forkFinally (server conn) (const $ gracefulClose conn 5000)

0 commit comments

Comments
 (0)