[Libwebsockets] how to close Websocket connection string other than call back

Subi S S subi.s at cambiumnetworks.com
Tue Jan 12 12:01:04 CET 2016


Hi ,

I am using lws_context_destroy(context) to close the connection from client code ( for me it is not possible to return -1 from call back),
is there a way to send reason string in this case ? or any other API is there to close the connection ?

But lws_context_destroy invokes close with  LWS_CLOSE_STATUS_NOSTATUS_CONTEXT_DESTROY

for (n = 0; n < context->fds_count; n++) {
              struct lws *wsi = wsi_from_fd(context, context->fds[n].fd);
              if (!wsi)
                     continue;
              lws_close_free_wsi(wsi, LWS_CLOSE_STATUS_NOSTATUS_CONTEXT_DESTROY
                           /* no protocol close */);
              n--;
       }

................................. but in lws_close_free_wsi reason is ignored for "LWS_CLOSE_STATUS_NOSTATUS_CONTEXT_DESTROY"

if (old_state == LWSS_ESTABLISHED &&
           (wsi->u.ws.close_in_ping_buffer_len || /* already a reason */
            (reason != LWS_CLOSE_STATUS_NOSTATUS &&
            (reason != LWS_CLOSE_STATUS_NOSTATUS_CONTEXT_DESTROY)))) {
              lwsl_debug("sending close indication...\n");

              /* if no prepared close reason, use 1000 and no aux data */
              if (!wsi->u.ws.close_in_ping_buffer_len) {
                     wsi->u.ws.close_in_ping_buffer_len = 2;
                     wsi->u.ws.ping_payload_buf[LWS_SEND_BUFFER_PRE_PADDING] =
                           (reason >> 16) & 0xff;
                     wsi->u.ws.ping_payload_buf[LWS_SEND_BUFFER_PRE_PADDING + 1] =
                           reason & 0xff;
              }



Thanks,
Subi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://libwebsockets.org/pipermail/libwebsockets/attachments/20160112/db2a2904/attachment.html>


More information about the Libwebsockets mailing list