[Libwebsockets] Returning wrong protocol number when initialising the context

Gilles Printemps gprintemps at gmail.com
Mon Nov 18 14:06:28 CET 2019


Hi Silas,
Thanks for your answer.
The point you highlighted seems the origin of my problem.
I was aware about that and don't know why I didn't add this terminator.
Thanks again

On Mon, Nov 18, 2019 at 12:07 PM Silas Parker <
skyhisi+libwebsockets at gmail.com> wrote:

> It looks like you're missing the terminating protocol.
> The docs say "The list is ended with an entry that has a NULL callback
> pointer"
> So you need to add an additional entry to your list so it doesn't run
> off into memory.
> _protocols.push_back({nullptr,nullptr,0,0,0,nullptr});
>
> Thanks,
> Silas
>
> On Mon, 18 Nov 2019 at 11:02, Gilles Printemps <gprintemps at gmail.com>
> wrote:
> >
> > Hi,
> > When I'm executing the following example (using libwebsockets 3.2.0), I
> got the following output through the logs
> >   "Creating Vhost 'default' port 9000, 5 protocols, IPv6 off"
> > Can someone explain why "5 protocols" are returned?
> > BR
> >
> >
> > #include <vector>
> > #include <libwebsockets.h>
> >
> > static int WSCallback(struct lws *wsi,enum lws_callback_reasons
> reason,void *session,void *data,size_t len) {}
> >
> > int main(int argc, char* argv[]) {
> >   lws_set_log_level(12,NULL);
> >   std::vector<lws_protocols> _protocols;
> >   _protocols.push_back({"ZWave",WSCallback,128,128,0,nullptr});
> >
> >   struct lws_context *context=NULL;
> >   struct lws_context_creation_info info;
> >   memset(&info, 0, sizeof info);
> >   info.port = 9000;
> >   info.protocols = _protocols.data();
> >   info.gid = -1;
> >   info.uid = -1;
> >   info.options = 0;
> >   context=lws_create_context(&info);
> >
> >   if (context==NULL) {
> >     printf("libwebsocket init failed\n");
> >     return -1;
> >   }
> >
> >   lws_context_destroy(context);
> > }
> > _______________________________________________
> > Libwebsockets mailing list
> > Libwebsockets at ml.libwebsockets.org
> > https://libwebsockets.org/mailman/listinfo/libwebsockets
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://libwebsockets.org/pipermail/libwebsockets/attachments/20191118/cbe64cda/attachment-0001.htm>


More information about the Libwebsockets mailing list