[Libwebsockets] How to run run libwebsocket_Service() in a Mainloop?

Prathamesh P Ghanekar prathamesh.ghanekar at igate.com
Wed Apr 9 06:15:52 CEST 2014


Hi Andy,Michael



Thanks for pointing me to the repository. I am going through it. But meanwhile, I have another confusion. It goes as follows:



1) I am quoting some lines from the README.coding file of the libwebsockets git repository.



Libwebsockets is singlethreaded

-------------------------------

Directly performing websocket actions from other threads is not allowed.

Aside from the internal data being inconsistent in forked() processes,

the scope of a wsi (struct websocket) can end at any time during service

with the socket closing and the wsi freed.

If you need to service other socket or file descriptors as well as the

websocket ones, you can combine them together with the websocket ones

in one poll loop, see "External Polling Loop support" below, and

still do it all in one thread / process context.



What I understand from these lines is that, performing libwebsockets actions from other threads is not allowed/encouraged. That is, to create a thread for libwebsocket_service() API, and Mainloop should be used to integrate websockets with any legacy code.



2) Whereas, I was going through libwebsockets.c file, where APIs are briefly documented.

For libwebsocket_create_context() API, some lines go as follows:



After initialization, it returns a struct libwebsocket_context * that represents this server. After calling, user code needs to take care of calling libwebsokcet service() with the context pointer to get the server’s sockets serviced. This can be done in the same process context or as a forked process, or another thread.



This leaves me in confusion whether to create a thread for calling libwebsocket_service() or it’s not allowed/encouraged.

Am I misinterpreting anything from the documentation?



Thanks in advance ☺

Regards,

Prathamesh



-----Original Message-----
From: Andy Green [mailto:andy.green at linaro.org]
Sent: 08 April 2014 17:59
To: Prathamesh P Ghanekar; Michael Haberler
Subject: Fwd: [Libwebsockets] How to run run libwebsocket_Service() in a Mainloop?



Not sure what happened with the To: emails in this one, so forwarding it...



-Andy



---------- Forwarded message ----------

From: Michael Haberler <mail17 at mah.priv.at<mailto:mail17 at mah.priv.at>>

Date: 8 April 2014 12:26

Subject: Re: [Libwebsockets] How to run run libwebsocket_Service() in a Mainloop?

To: Prathamesh P Ghanekar <andy.green at linaro.org<mailto:andy.green at linaro.org>>









Prathamesh,



Am 08.04.2014 um 11:29 schrieb Prathamesh P Ghanekar <andy.green at linaro.org<mailto:andy.green at linaro.org>>:



> Hi,

>

> I would like to know how should one go about running the libwebsocket_service() call in a glib main loop?

> I am starting a server in the main() using libwebsocket_create_context() and wish to avoid while(1) loop for polling for client connections. An example code snippet would be of great help.



not exactly what you asked - but maybe a starting point: libwebsockets integrated with the zeromq event loop:



https://github.com/mhaberler/libwebsockets/commits/zeromq-proxy-example



- Michael



>

> Regards,

> Prathamesh



_______________________________________________

> Libwebsockets mailing list

> Libwebsockets at ml.libwebsockets.org<mailto:Libwebsockets at ml.libwebsockets.org>

> http://ml.libwebsockets.org/mailman/listinfo/libwebsockets

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Disclaimer~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Information contained and transmitted by this e-mail is confidential and proprietary to iGATE and its affiliates and is intended for use only by the recipient. If you are not the intended recipient, you are hereby notified that any dissemination, distribution, copying or use of this e-mail is strictly prohibited and you are requested to delete this e-mail immediately and notify the originator or mailadmin at igate.com <mailto:mailadmin at igate.com>. iGATE does not enter into any agreement with any party by e-mail. Any views expressed by an individual do not necessarily reflect the view of iGATE. iGATE is not responsible for the consequences of any actions taken on the basis of information provided, through this email. The contents of an attachment to this e-mail may contain software viruses, which could damage your own computer system. While iGATE has taken every reasonable precaution to minimise this risk, we cannot accept liability for any damage which you sustain as a result of software viruses. You should carry out your own virus checks before opening an attachment. To know more about iGATE please visit www.igate.com <http://www.igate.com>.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://libwebsockets.org/pipermail/libwebsockets/attachments/20140409/c430392b/attachment-0001.html>


More information about the Libwebsockets mailing list