[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...

https://libwebsockets.org/git/libwebsockets/tree/lib/roles/cgi/cgi-server.c#n277-295

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

Okay...

>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
>LWS_CALLBACK_WSI_DESTROY and LWS_CALLBACK_DEL_POLL_FD.
>
>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...

https://libwebsockets.org/git/libwebsockets/tree/include/libwebsockets/lws-timeout-timer.h#n79-105

-Andy

>Best regards,
>Catherine
>
>-----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_VISIBLE LWS_EXTERN const char *
>lws_get_urlarg_by_name(struct lws *wsi, const char *name, char *buf,
>int
>len)
>{
>         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;
>}
>
>https://secure-web.cisco.com/1mswPXN1cJ-CTUPjOeut2csQnynvsV_6Xw9GFKPUiLtyUo2vcsqBojsHA3VtbbyBss5zP1FtfJ1LoaxrosqWO2xFY0k7xN9Em2idcv59hENyaim73HCVHyBUKKDvRJYW5HcLqehmBNvVc3SiUKoswfv0Cc1TyzPQT_4aT4RR1_H1o6gk4pyqkahf9bkxPff9BemK-5FMrOj9VbP-MzNDvyMu23TvrRTkG-N96jkXwr6P9qKHlu9mA1XpQw8yplU4pOmDCHLBsHLepGbeGc56Rs2vLqNxvYA8wgCN2t02Nj67W7E3yPQjFGMwA6OyMJtAK/https%3A%2F%2Flibwebsockets.org%2Fgit%2Flibwebsockets%2Ftree%2Flib%2Fcore-net%2Fwsi.c#n504-519
>
>-Andy


More information about the Libwebsockets mailing list