[Libwebsockets] How to disconnect a client connection?

Andy Green andy at warmcat.com
Wed Apr 1 20:59:37 CEST 2015



On 1 April 2015 22:49:23 GMT+08:00, Danomi Czaski <djczaski at gmail.com> wrote:
>>On 1 April 2015 21:29:12 GMT+08:00, Danomi Czaski <djczaski at
>gmail.com> wrote:
>>>>On 1 April 2015 03:59:03 GMT+08:00, Danomi Czaski <djczaski at
>>>gmail.com> wrote:
>>>>>What is the proper way to disconnect and clean up a client
>>>connection?
>>>>>There is a call for `libwebsocket_client_connect` but I don't see a
>>>>>corresponding `libwebsocket_client_disconnect`.
>>>>>
>>>>>My application needs to switch between different servers based upon
>a
>>>>>user command.
>>>>
>>>>Just return nonzero from most callbacks will kill that connection.
>>>>
>>>>The test client tests this actually, he keeps making connections
>with
>>>a
>>>>limited lifetime that close and make a fresh connection,
>>>
>>>But then I need to wait for a callback event, like
>>>LWS_CALLBACK_CLIENT_RECEIVE,
>>>in order to return nonzero and terminate the connection. Can't I
>force
>>>the close
>>>myself?
>>
>>The design of lws is the the 'yourself' who knows the wsi for the
>connection,
>>is in a callback for that wsi and perfectly well able to return
>nonzero from it with no effort.
>
>Just asking a question.
>
>Yep, easy to do in the callback "myself" I agree:
>
>    int g_close_connection = 0;
>
>    void close_lws_connection(void)
>    {
>        g_close_connection = 1;
>    }
>
>    int callback_lws(
>        struct libwebsocket_context *context, struct libwebsocket *wsi,
>        enum libwebsocket_callback_reasons reason,
>        void *user, void *in, size_t len)
>    {
>        if (g_close_connection)
>            return -1;
>
>        ...
>    }
>
>But, I don't see how I can control when the callback for a particular
>wsi executes without waiting for some event like
>LWS_CALLBACK_CLIENT_RECEIVE which may or may not come.

Just ask for a writeable callback.

-Andy

>_______________________________________________
>Libwebsockets mailing list
>Libwebsockets at ml.libwebsockets.org
>http://ml.libwebsockets.org/mailman/listinfo/libwebsockets




More information about the Libwebsockets mailing list