Improve EOF handling for half-close. Patch from Catalin Patulea

Fixes the situation
$ ./dbclient root@1.2.3.4 'cat; echo foo'
^D
<no output>