clean P2P protocol shutdown on EOF

Avoids "git-annex-shell: <stdin>: hGetChar: end of file"
being displayed by the test suite, due to the way it
runs git-annex-shell without using ssh.

git-annex-shell over ssh was not affected because git-annex hangs up the
ssh connection and so never sees the error message that git-annnex-shell
probably did emit.

This commit was sponsored by Ryan Newton on Patreon.
This commit is contained in:
Joey Hess 2018-09-13 10:46:37 -04:00
parent e4d1914e3a
commit b18fb1e343
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
3 changed files with 11 additions and 2 deletions

View file

@ -83,6 +83,7 @@ data Message
| DATA Len -- followed by bytes of data
| VALIDITY Validity
| ERROR String
| ProtocolEOF
deriving (Show)
instance Proto.Sendable Message where
@ -108,6 +109,7 @@ instance Proto.Sendable Message where
formatMessage (VALIDITY Invalid) = ["INVALID"]
formatMessage (DATA len) = ["DATA", Proto.serialize len]
formatMessage (ERROR err) = ["ERROR", Proto.serialize err]
formatMessage (ProtocolEOF) = []
instance Proto.Receivable Message where
parseCommand "AUTH" = Proto.parse2 AUTH
@ -367,6 +369,8 @@ serverLoop :: (Message -> Proto (ServerHandler a)) -> Proto (Maybe a)
serverLoop a = do
mcmd <- net receiveMessage
case mcmd of
-- Stop loop at EOF
Just ProtocolEOF -> return Nothing
-- When the client sends ERROR to the server, the server
-- gives up, since it's not clear what state the client
-- is in, and so not possible to recover.