[Libwebsockets] Sending WS Connection Close packet immediately from the lws client
andy at warmcat.com
Tue May 21 15:20:03 CEST 2019
On 5/21/19 2:17 PM, Mateusz Stępień wrote:
> On 5/21/19 2:51 PM, Andy Green wrote:
> > There's also this api
> That function would probably help, when I could get to the point that
> Close message is already sent and I'm waiting for ACK from the server.
>> You can never guarantee you can either send the close frame at all or
>> when you can send it.
> That can be said about every packet going out from the client. However
> the issue is not about flaky connection or sth like that. It is that
> that I cannot send Close message like I can send any other one. Right
ws close frame is handled by lws internally, yes.
> now if I want to close the connection with a close message and a chosen
> reason, I need to wait for the CLIENT_RECEIVE callback and because I
No... you just need to let know lws you want to close that wsi... the
api I linked to will allow you to do that from any callback.
> cannot force it, I am at the mercy of server, which can send another
> message in 5 seconds, or in 20 minutes, or never. Please note, that I'm
> talking about time between setting "completed" flag and receiving
> CLIENT_RECEIVE callback.
>> If it can be sent within a timeout period of a few seconds, it will be
>> sent. But anything can crash or run out of battery or lose connection
>> at any time without ceremony. So you shouldn't assume this can be
>> made a certainty... CLOSE callback to learn the socket closed is much
>> more certain.
> I'm sorry, but I don't see the relevance to my issue. At the CLOSE
> callback there's nothing I can do to send the Close message.
You seem to be setting flags and stuff like you're going to rely on it.
It spells it out in RFC6455, you can't rely on the CLOSE frames coming.
More information about the Libwebsockets