Refactor packet send/receive.
These are changes to make the class more generally useful:
* Change the recv() function to simply receive a single message.
* Add recv_all() which duplicates the previous functionality, where
  we loop and collect all pending packets.
* Add the send_query() function to send a query rather than send
  a query and receive answers.
* Change query() to use our new send_query() and recv_all()
  functions.
* Update the rest of the code to use these new functions properly.