redding/sanford-protocol — pull request #18 by jcredding (2013-03-04 17:09:33+00:00)
Title: Keep reading till the number of requested bytes is received

This modifies the `Socket#read` to loop when it calls `recv`. The
goal is to make sure the requested number of bytes is read from
the socket, even if it takes multiple calls to `recv`. This will
loop calling `recv` until the expected number of bytes are read,
ensuring the full message is read. If an empty string is read,
then the loop will also exit, as this is indicative the client
closed the connection.

This is came about from an issue that occurred in a production
setting, but never occurred in local development. It seems that
the full response is not always available when `recv` is called.
This caused an incomplete BSON string to be decoded, which failed.