Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Multi Response (Read/Write) Packets
Description, Motivation, and Context
While running again a PLC with > 250 reads, we noticed that writes were being sent in parallel with the reads. This caused the buffer returned to _handleDataEvent to contain the response for both the read and write, however the parsing only ever parsed the first response in the header and threw away the other one. This change allows the remainder of the buffer to also be processed.
Aditionally, listeners are removed after failed calls and listeners are guranteed to be attached before the new write command is sent. This avoids possible race conditions in where a message could be recieved on the socket before the listener is set up.
An alternative solution to this would be to group read/write/groups in the same queue instead of individual queues so there is only ever 1 outstanding request.
How Has This Been Tested?
Tested against a PLC with > 250 reads and around 2 writes. When ever the writes would be would be executed, the subsequent read would always fail. I believe you can issue a write and read at the same time to reliably reproduce the error.
Screenshots (if appropriate):
Types of changes
Checklist:
[WIP] Some awesome PR title
)Related Issue