Async server example and constructor with rx_remainder for async framer#19
Async server example and constructor with rx_remainder for async framer#19dbdbc wants to merge 1 commit intoninjasource:masterfrom
Conversation
| } | ||
| Err(e) => { | ||
| return Err(FramerError::WebSocket(e)); | ||
| match stream.next().await { |
There was a problem hiding this comment.
What happened to the loop? I believe that we need it if we only receive tiny chunks of data from the stream, perhaps not enough to read everything we need to complete the connect operation.
There was a problem hiding this comment.
The loop is never used, because we either return or panic inside it. However I now see that you probably wanted to handle the HttpHeaderIncomplete in the future instead of panicking, so if you want me to I can undo that change.
|
Hi, thanks for taking the time to bring this issue to my attention and propose a solution. I'm going to play around with your changes to see if I like them. Very good point about reuse of that buffer for reads and writes, I'll have to give it some thought. |
Added an async server example.
The newly added constructor was required because
read_headeralready reads from the stream before the websocket upgrade even happens.Also, I fixed some stuff clippy was not satisfied with.
When looking at the
client_asyncexample, I noticed that the same buffer is used for rx and tx. While this might be fine in this simple case, I think in more general scenarios it could violate the contract described inframer_async::Framer::readThis should in my opinion not be in an example in this way, but to have similar implementations for
client_asyncandserver_async, I also reused the same buffer for reading and writing.Are there ways to enforce the mentioned contract? E. g. by not only storing indices into the buffer (
frame_cursor,rx_remainder_len), but also a&mut [u8]in theFramerstruct? Or would this conflict with the design you have in mind?Anyway, that is not really part of this PR.
Thank you for creating this repo, and have a nice day!