Skip to content

Commit

Permalink
Removed --hidden-client-mode-option
Browse files Browse the repository at this point in the history
  • Loading branch information
ekarayel committed Nov 17, 2015
1 parent 56da4f6 commit e329607
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
28 changes: 17 additions & 11 deletions src/Sync/MerkleTree/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
module Sync.MerkleTree.Run where

import Control.Concurrent
import Control.Concurrent.MVar
import Control.Monad
import Data.List

import System.Console.GetOpt
import System.Exit
import System.IO
Expand Down Expand Up @@ -102,9 +102,6 @@ toSyncOptions = foldl (flip id) defaultSyncOptions
putError :: String -> IO ()
putError = hPutStrLn stderr

_HIDDENT_CLIENT_MODE_OPTION_ :: String
_HIDDENT_CLIENT_MODE_OPTION_ = "--hidden-client-mode-option"

printUsageInfo :: String -> IO ()
printUsageInfo version =
mapM_ putError ([usageInfo header optDescriptions] ++ [details])
Expand Down Expand Up @@ -135,7 +132,7 @@ main version args = flip catchIOError (putError . show) $
do let parsedOpts = getOpt (ReturnInOrder parseNonOption) optDescriptions args
exit err = hPutStrLn stderr err >> exitFailure
case () of
() | [_HIDDENT_CLIENT_MODE_OPTION_] == args -> runChild
() | [] == args -> runChild
| (options,[],[]) <- parsedOpts ->
do mMsg <- run version $ toSyncOptions options
case mMsg of
Expand Down Expand Up @@ -181,10 +178,19 @@ run version so
]
missingRemoteCmd = "The --remote-shell is required when the prefix 'remote:' is used."

_WAIT_FOR_INPUT_ :: Int
_WAIT_FOR_INPUT_ = 1000 * 1000 * 3

runChild :: IO ()
runChild =
do streams <- openStreams stdin stdout
child streams
do gotMessage <- newEmptyMVar
streams <- openStreams stdin stdout
_ <- forkIO $
do threadDelay _WAIT_FOR_INPUT_
r <- isEmptyMVar gotMessage
when r $ putError
"Running in server mode. (The command `sync-mht --help` prints usage info.)"
child gotMessage streams

runParent ::
ClientServerOptions
Expand All @@ -197,9 +203,8 @@ runParent clientServerOpts mRemoteCmd source destination dir =
do (exitAction, parentStreams) <-
case mRemoteCmd of
RemoteCmd remoteCmd ->
do let remoteCmd' = remoteCmd ++ " " ++ _HIDDENT_CLIENT_MODE_OPTION_
(Just hIn, Just hOut, Nothing, ph) <-
createProcess $ (shell remoteCmd')
do (Just hIn, Just hOut, Nothing, ph) <-
createProcess $ (shell remoteCmd)
{ std_in = CreatePipe
, std_out = CreatePipe
}
Expand All @@ -214,9 +219,10 @@ runParent clientServerOpts mRemoteCmd source destination dir =
do (parentInStream, childOutStream) <- mkChanStreams
(childInStream, parentOutStream) <- mkChanStreams
childTerminated <- newEmptyMVar
running <- newEmptyMVar
let childStrs = StreamPair { sp_in = childInStream, sp_out = childOutStream }
let parentStrs = StreamPair { sp_in = parentInStream, sp_out = parentOutStream }
_ <- forkFinally (child childStrs) (const $ putMVar childTerminated ())
_ <- forkFinally (child running childStrs) (const $ putMVar childTerminated ())
return (takeMVar childTerminated, parentStrs)
exitMsg <- parent parentStreams source destination dir clientServerOpts
exitAction
Expand Down
9 changes: 6 additions & 3 deletions src/Sync/MerkleTree/Sync.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ module Sync.MerkleTree.Sync
) where

import Control.Concurrent(newChan)
import Control.Concurrent.MVar
import Control.Monad
import Control.Monad.State
import Data.Monoid
Expand Down Expand Up @@ -78,9 +79,10 @@ data Direction
= FromRemote
| ToRemote

child :: StreamPair -> IO ()
child streams =
child :: MVar () -> StreamPair -> IO ()
child gotMessage streams =
do launchMessage <- getFromInputStream (sp_in streams)
putMVar gotMessage ()
_ <- serverOrClient (read launchMessage) streams
return ()

Expand Down Expand Up @@ -181,7 +183,8 @@ tests = H.TestList $
}
}
out <- ST.nullOutput
child $ StreamPair { sp_in = inst, sp_out = out }
r <- newEmptyMVar
child r $ StreamPair { sp_in = inst, sp_out = out }
return False
True H.@=? r
]

0 comments on commit e329607

Please sign in to comment.