[Libwebsockets] libwebsocket problem

Andy Green andy at warmcat.com
Fri May 17 05:27:35 CEST 2019

On May 16, 2019 7:48:58 PM PDT, "Wei, Catherine" <catherine.wei at commscope.com> wrote:

>Thanks, if I use the lws_hdr_copy_fragment, I need to know how many

Nope... just try fragment 0, 1 etc until you get a failure... then you discovered how many there were.  You don't need to know going in.  CGI already does this...


>fragments; if I use lws_get_urlarg_by_name, I need to know parameter
>name. However, all these are unknown to me. I think comment out the
>parse about "?" in the path seems the most simple and direct way to me.
>I will use this way for debug at present, but still thanks for your
>suggestion and letting me know such interfaces.


>Another problem that I met:
>When I want to disconnect the websocket connection (protocol: ws) using
>the "close(lws_get_socket_fd(&lwsConnection));" from the websocket

You're literally closing the socket without letting lws do the necessary steps.

>server side, I found there is no callback with reason
>(LWS_CALLBACK_DEL_POLL_FD) coming, and without this, the file
>descriptor will not be removed. If I manually exit the running
>websocket client, I can receive the callback with reason
>Do you know why this happened?

Yes... don't randomly close the socket using POSIX stuff.

Lws is flexible but it isn't quite so free-form.

You can usually close the wsi by returning nonzero from most callbacks.

If that doesn't fit the situation, use a related api...



>Best regards,
>-----Original Message-----
>From: Andy Green <andy at warmcat.com> 
>Sent: 2019年5月16日 18:19
>To: Wei, Catherine <catherine.wei at commscope.com>;
>libwebsockets at ml.libwebsockets.org
>Subject: Re: [Libwebsockets] libwebsocket problem
>Email Security Warning:
>The following message was sent from an external e-mail address.
>Exercise caution when opening attachments, clicking links, or
>exchanging information.
>On 5/16/19 9:12 AM, Wei, Catherine wrote:
>> Thanks for the API, since the number of the parameters are also
>unknow, so I didn't use the API. I added a patch to keep the parameters
>to the url, so I can easily get the request url with parameters with
>current interface. Still thanks. By the way, if there is any unproper
>place in my patch, please let me know.
>I appreciate the urge to send me code, but the existing apis can do
>everything you needed... look at the implementation of the by_name()
>api... it's based on the other api.  It just looks at each fragment
>until it finds it has asked for one that doesn't exist.
>lws_get_urlarg_by_name(struct lws *wsi, const char *name, char *buf,
>         int n = 0, sl = (int)strlen(name);
>         while (lws_hdr_copy_fragment(wsi, buf, len,
>                           WSI_TOKEN_HTTP_URI_ARGS, n) >= 0) {
>                 if (!strncmp(buf, name, sl))
>                         return buf + sl;
>                 n++;
>         }
>         return NULL;

More information about the Libwebsockets mailing list