technomancy/leiningen — pull request #937 by hyPiRion (2013-01-18 00:09:17+00:00)
Title: Gracefully stop reading input in sub-process. Fixes #934.

@xeqi, could you check that this works for you?

Commit message:
This commit handles three major bugs with the current way of redirecting input
from Leiningen to a sub-process:

- The redirection is never stopped. This means that typing on the keyboard after
a sub-process has finished will crash the thread redirecting data from *in* to
the sub-process' input stream, as it is closed.

- The redirection is buffered. This means that data intended to a subsequent
sub-process may be sent to this sub-process instead.

- The redirection blocks instead of busy waits. For the output streams, this is
perfectly fine and the recommended approach to avoid wasting cycles. However,
this has some issues when done to an input stream: If the sub-process finishes
while the thread block waiting for a character, we will be unable to stop the
thread before a character has been read. The consequence is that a character
originally intended to the subsequent sub-process will be given to the
previous process.

These issues are solved by reading one byte at a time, busy wait on data and
gracefully exit when the sub-process has ended (through a mutable
variable/atom).