[Libwebsockets] server: no disconnection if return -1 in callback

Andy Green andy at warmcat.com
Mon Nov 2 17:56:52 CET 2020



On 11/2/20 4:43 PM, Roman Nikiforov wrote:
> Hi Andy,
> according to documentation the proper way to force disconnection is to 
> return -1 in callback. But I have the following case where it doesn't work:
> in LWS_CALLBACK_RECEIVE I call lws_callback_on_writable(wsi) and then on 
> the next callback I return -1. I tried it LWS_CALLBACK_SERVER_WRITEABLE 

You can't really take that "next callback" approach since the event loop 
may be idle for a very long time before you get any "next callback". 
And the kind of callback that might happen to be next, may not be 
related to a specific wsi.

> and even independent of callback type:
> int Server::callbackPush(lws *wsi, lws_callback_reasons reason, void 
> *user, void *in, size_t len)
> {
>      PushSessionData *session = static_cast<PushSessionData*>(user);
>      if (session && session->hasFailed == 1) {
>          // this doesn't work
>          //dbg("return -1 to disconnect\n");
>          //return -1;// error message was printed in processPullRequest 
> (may be in another thread)
>          lws_set_timeout(wsi, NO_PENDING_TIMEOUT, LWS_TO_KILL_ASYNC);
>      }
> Calling set_timeout does the job, but shouldn't return -1 be the proper way?

Most code calling the callback will check and hang up if it returned 
nonzero, but not all; all the common ones where you, eg, receive 
something and so might realize you are done with the connection, or send 
something and realize you are done will listen for it.

-Andy

> - Roman
> 
> _______________________________________________
> Libwebsockets mailing list
> Libwebsockets at ml.libwebsockets.org
> https://libwebsockets.org/mailman/listinfo/libwebsockets
> 


More information about the Libwebsockets mailing list