add killTransferrer

There is redundant code in the assistant that does the same thing,
but that code uses a PID, not a ProcessHandle, and gets the PID from,
apparently, the TransferInfo transferPid (although I can't seem to find
where that gets set on non-windows).
This commit is contained in:
Joey Hess 2020-12-08 11:43:06 -04:00
parent 822a8eadf8
commit b9cfd15e90
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38

View file

@ -129,14 +129,6 @@ mkTransferrer program batchmaker = do
, transferrerHandle = pid , transferrerHandle = pid
} }
{- Closing the fds will shut down the transferrer, but only when it's
- in between transfers. -}
shutdownTransferrer :: Transferrer -> IO ()
shutdownTransferrer t = do
hClose $ transferrerRead t
hClose $ transferrerWrite t
void $ waitForProcess $ transferrerHandle t
-- | Send a request to perform a transfer. -- | Send a request to perform a transfer.
sendRequest :: TransferRequestLevel -> Transfer -> Maybe Remote -> AssociatedFile -> Handle -> IO () sendRequest :: TransferRequestLevel -> Transfer -> Maybe Remote -> AssociatedFile -> Handle -> IO ()
sendRequest level t mremote afile h = do sendRequest level t mremote afile h = do
@ -167,3 +159,20 @@ readResponse h = do
transferKeysProtocolError :: String -> a transferKeysProtocolError :: String -> a
transferKeysProtocolError l = error $ "transferkeys protocol error: " ++ show l transferKeysProtocolError l = error $ "transferkeys protocol error: " ++ show l
{- Closing the fds will shut down the transferrer, but only when it's
- in between transfers. -}
shutdownTransferrer :: Transferrer -> IO ()
shutdownTransferrer t = do
hClose $ transferrerRead t
hClose $ transferrerWrite t
void $ waitForProcess $ transferrerHandle t
{- Kill the transferrer, and all its child processes. -}
killTransferrer :: Transferrer -> IO ()
killTransferrer t = do
hClose $ transferrerRead t
hClose $ transferrerWrite t
interruptProcessGroupOf $ transferrerHandle t
threadDelay 50000 -- 0.05 second grace period
terminateProcess $ transferrerHandle t