HTTP::WebSocket to handle websocket connections, but using the underlying file descriptor in a
select(2) function to know when a new message arrived (because I manage multiple file descriptors). I also wrote a
read function in the
HTTP::WebSocket class to read a single message (as I discussed it in a previous forum message WebSocket and silent disconnections (solved) and I sent a PR https://github.com/crystal-lang/crystal/pull/8392 ). And I encounter a problem.
HTTP::WebSocket can read a message over the TCP connection, and this class manages boundaries correctly: messages do not overlap when multiple messages are sent by a single client at the same time, we get them separately. However, only the first message is handled in my
read function (which is basically the
#run method without the loop). Once the message has been handled, there is nothing to read on the file descriptor anymore (
select(2) does not return).
So, I think that HTTP::WebSocket buffers messages, and I would like to know if there is a message in the buffer I can read.
I tried to read
HTTP::WebSocket::Protocol but there are a bit obscure to me. As I understand, there is the
@io attribute in
HTTP::WebSocket::Protocol that is used to read messages in the underlying socket, but I don’t fully understand what’s going on.
Thanks for the help!