davidmoreno / onion

C library to create simple HTTP servers and Web Applications.
http://www.coralbits.com/libonion/
Other
2.02k stars 250 forks source link

Question on Event loop and async support? #237

Open nginxsantos opened 6 years ago

nginxsantos commented 6 years ago

Hi, Can this run inside my application's event loop or it has to have its own event loop? Also, does it support asynchronous handling Thanks, santos

davidmoreno commented 6 years ago

Hi,

it should be possible to use through another event loop. Check poller_libev.c and poller_libevent.c.

Once a request handler is called it has to finish the processing of that request, so it may block your program if you dont use threads.

Do you refer to that as asynchronous handling or are you referring to something else?

Regards-

alanswx commented 5 years ago

I am working on putting this into MiSTer's game loop, and I need it to be called periodically from the main loop.

I separated onion_listen into three functions, a setup, poll, and cleanup. I had to make two versions of onion_poller_poll, one called: onion_poller_poll_once that get's rid of the while, and passes 0 in for epoll. I need to clean this up, and figure out how to test it. Do you think something like this would be a patch you would consider accepting? I think it is fairly clean. I am just a little confused about this path:

if (o->flags & O_ONE) {

davidmoreno commented 5 years ago

Hi,

of course I will consider merging!

About that if, there is one mode that only serves one request and returns from onion_listen, that's the branch for that mode. But actually it is not very tested. It was useful at the beginning but later was superseded by the poll mode.

alanswx commented 5 years ago

Sounds great. I will clean up my code and try to submit a pr. Thanks for the explanation of the if, that makes more sense now. I think I can pass some arguments to the polling function and not duplicate the code.