Various fixes

This makes miner_gate build cleanly (without warnings), and tolerate partial reads/writes so its client can be run on another machine.