diff options
author | Joey Hess <joeyh@joeyh.name> | 2017-04-11 15:54:44 -0400 |
---|---|---|
committer | Joey Hess <joeyh@joeyh.name> | 2017-04-11 15:54:44 -0400 |
commit | 22d0afca50ac4e43f21e34b93076b592a99eddcf (patch) | |
tree | d5010bd2ba75cb7b1850e6ae3f15bcdcbe700594 /debug-me.hs | |
parent | 58e71d656c3cfb6862647cdf215676b529a00c93 (diff) | |
download | debug-me-22d0afca50ac4e43f21e34b93076b592a99eddcf.tar.gz |
add a delay to input, simulating a laggy network
Diffstat (limited to 'debug-me.hs')
-rw-r--r-- | debug-me.hs | 13 |
1 files changed, 8 insertions, 5 deletions
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 |