-
Notifications
You must be signed in to change notification settings - Fork 877
Enforcing the frame size for read #3782
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
Conversation
roji
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for doing this @vonzshik.
When I thought about how to do it, I imagined a more explicit/high-level API where we would call "StartNewFrame" on the buffer, providing the message code and length, rather than inferring that a new frame is starting from the setting of ReadPosition (when _inFrame is false). It seems like this might considerably simplify things (I'm still not clear on the exact logic of _bufferReset, ResetFrame, etc.).
What do you think?
| await Authenticate(username, timeout, async, cancellationToken); | ||
|
|
||
| #if DEBUG | ||
| ReadBuffer.EnableFrameTracking = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any particular reason this shouldn't always be on (in DEBUG)? We could also use it to catch bugs in the Startup message and in authentication...
| { | ||
| await Authenticate(username, timeout, async, cancellationToken); | ||
|
|
||
| #if DEBUG |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than wrapping each call with #if DEBUG, the methods themselves can have [Conditional("DEBUG")]. This automatically does what we want, and makes the call sites much nicer.
| } | ||
| else | ||
| { | ||
| _currentFrame.LengthLeft -= positionDelta; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: maybe better to have Position (in the frame) - just like the the buffer's ReadPosition - which gets incremented, rather than LengthLeft which gets decremented.
| { | ||
| Debug.Assert(positionDelta == 1, "Protocol failure"); | ||
| Debug.Assert(ReadBytesLeft >= 5); | ||
| var frameCode = Buffer[_readPosition]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Convert to BackendMessageCode?
Related to #3775
Testing whether it breaks something...