MAX_RETRIES of 10 isn't a really good idea because if doing large restores over caldecott you could easily
get 10 timeouts in a row from the server before the server needs to send any data.
Fixing deadlocks with caldecott tunneling.

The caldecott server can send more than the BUFFER_SIZE due to the way it is written.
It only stops receiving data if more than 1mb (currently) is pulled. So it can be just over
1mb.

The current code passes the 1mb to the client application then goes to read from the tunnel again
with data still in the buffer. If the client application is waiting for this data before sending a response
and the server is waiting for the response we get into a dead lock.

Lets makes sure we have sent all data in the buffer before we try to read again.