Implement the last part interrupt-driven: reception of packets.

Also fix one memory bug and one race in the existing code.