Currently, the readPacketOrTimeout() discards the partially read packet when it aborts due to a timeout. This leaves the communication channel in an essentially broken state, since a packet has essentially been discarded and there is no easy/reliable way to tell where the next packet begins.
Proposed solution
Instead of discarding the partially read packet, buffer it in an instance variable so that the read can be resumed in a subsequent call.
Currently, the
readPacketOrTimeout()
discards the partially read packet when it aborts due to a timeout. This leaves the communication channel in an essentially broken state, since a packet has essentially been discarded and there is no easy/reliable way to tell where the next packet begins.Proposed solution
Instead of discarding the partially read packet, buffer it in an instance variable so that the read can be resumed in a subsequent call.