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

Roman Nikiforov roman at nikiforoff.de
Mon Nov 2 17:43:59 CET 2020

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 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?

- Roman
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://libwebsockets.org/pipermail/libwebsockets/attachments/20201102/f2994f90/attachment.htm>

More information about the Libwebsockets mailing list