From 22d0afca50ac4e43f21e34b93076b592a99eddcf Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Tue, 11 Apr 2017 15:54:44 -0400 Subject: add a delay to input, simulating a laggy network --- debug-me.hs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'debug-me.hs') diff --git a/debug-me.hs b/debug-me.hs index 6103545..69870f1 100644 --- a/debug-me.hs +++ b/debug-me.hs @@ -4,7 +4,9 @@ import Types import Hash import Pty +import Control.Concurrent import Control.Concurrent.Async +import Control.Concurrent.STM import System.IO import System.Process import System.Exit @@ -23,21 +25,22 @@ main = do let Master h = ptyMaster p hSetBuffering stdin NoBuffering hSetBuffering h NoBuffering - ithread <- async (forward stdin h ph) - othread <- async (forward h stdout ph) + ithread <- async (forward stdin h ph 200000) + othread <- async (forward h stdout ph 0) exitstatus <- waitForProcess ph cancel ithread cancel othread return exitstatus -forward :: Handle -> Handle -> ProcessHandle -> IO () -forward from to ph = do +forward :: Handle -> Handle -> ProcessHandle -> Int -> IO () +forward from to ph delay = do b <- B.hGetSome from 1024 if b == B.empty then do terminateProcess ph return () else do + threadDelay delay B.hPut to b hFlush to - forward from to ph + forward from to ph delay -- cgit v1.2.3