Skip to content

@thelff /netproxy6.hs
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
network-conduit hangs in clientSrc $$ serverSink?
{-# LANGUAGE ScopedTypeVariables #-}
{-# OPTIONS -Wall #-}
import Data.Conduit
import Data.Conduit.Network
import Control.Monad.IO.Class (liftIO)
import Control.Concurrent.Lifted (fork,threadDelay)
import Network (withSocketsDo)
import qualified Control.Exception.Lifted as EL
import Control.Monad.Trans.Resource
main::IO ()
main = do
withSocketsDo $ runTCPClient (ClientSettings 5000 "127.0.0.1") $ \clientSrc clientSink -> do
liftIO $ putStrLn $ "attaching runTcpClient"
liftIO $ withSocketsDo $ runTCPServer (ServerSettings 5002 (Just "127.0.0.1")) $ \serverSrc serverSink -> do
liftIO $ putStrLn $ "\nNEW runTcpServer session"
_ <- liftIO $ fork $ do
liftIO $ putStrLn "START clientSrc serverSink"
runResourceT $ do
_ <- register $ liftIO $ putStrLn ("finalizer clientSrc serverSink") -- Doesnt fire
EL.catch (clientSrc $$ serverSink) (\(e::EL.SomeException) -> liftIO (putStrLn ("Exception:clientSrc serverSink e[" ++ show e ++ "]"))) -- no errors until the process is killed
liftIO $ putStrLn "END clientSrc serverSink" -- never gets this far
liftIO $ putStrLn "START serverSrc clientSink"
EL.catch (serverSrc $$ clientSink) (\(e::EL.SomeException) -> liftIO (putStrLn ("Exception:serverSrc clientSink e[" ++ show e ++ "]")))
liftIO $ putStrLn "END serverSrc clientSink"
putStrLn $ "END runTcpClient"
-- on Ubuntu
{-
grant@grant-VirtualBox:~/haskell$ ./netproxy6
attaching runTcpClient
NEW runTcpServer session
START clientSrc serverSink
START serverSrc clientSink
END serverSrc clientSink
NEW runTcpServer session
START serverSrc clientSink
START clientSrc serverSink
END serverSrc clientSink
NEW runTcpServer session
START clientSrc serverSink
START serverSrc clientSink
END serverSrc clientSink
^CException:clientSrc serverSink e[recv: invalid argument (Bad file descriptor)]
END clientSrc serverSink
finalizer clientSrc serverSink
Exception:clientSrc serverSink e[recv: invalid argument (Bad file descriptor)]
END clientSrc serverSink
finalizer clientSrc serverSink
Exception:clientSrc serverSink e[recv: invalid argument (Bad file descriptor)]
END clientSrc serverSink
finalizer clientSrc serverSink
-}
-- on Windows 7
{-
C:\haskell>netproxy6
attaching runTcpClient
NEW runTcpServer session
START clientSrc serverSink
START serverSrc clientSink
END serverSrc clientSink
NEW runTcpServer session
START clientSrc serverSink
START serverSrc clientSink
END serverSrc clientSink
NEW runTcpServer session
START serverSrc clientSink
START clientSrc serverSink
END serverSrc clientSink
-}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.