Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Partial message transfers and framing #13

Open
mfya opened this issue Apr 14, 2017 · 0 comments
Open

Partial message transfers and framing #13

mfya opened this issue Apr 14, 2017 · 0 comments

Comments

@mfya
Copy link

mfya commented Apr 14, 2017

The socket communication is missing proper handling of partial transfers and requires message framing.
The current code only works as long as one call to Boost.Asios async_receive() returns exactly one message, but this is not guaranteed. As a consequence messages are lost or the app crashes when it attempts to deserialize incompletely transferred Flatbuffer objects.

The amount of bytes read from a TCP socket by a single call to recv() (and so Boost.Asios async_receive()) is not guaranteed to match the amount of bytes, which have been sent from the other side with one send() call. Only part of the data from one call or data from multiple send() calls could be returned.
Additionally send() and recv() may transfer less than the requested number of bytes. The number of actually transferred bytes should always be checked and partial transfers resumed by another call to transfer the remaining data.

To ensure that only complete messages are deserialized, message framing should be added. For instance by prepending each message with its size in bytes and then using async_read() instead of async_receive() to read this exact number of bytes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant