refactor socket code, ensure that each call to recv/recvmsg receives a single separate message