onion icon indicating copy to clipboard operation
onion copied to clipboard

Question on Event loop and async support?

Open nginxsantos opened this issue 6 years ago • 4 comments

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

nginxsantos avatar Aug 23 '18 18:08 nginxsantos

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-

davidmoreno avatar Aug 26 '18 17:08 davidmoreno

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) {

alanswx avatar May 13 '19 22:05 alanswx

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.

davidmoreno avatar May 14 '19 07:05 davidmoreno

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.

alanswx avatar May 14 '19 13:05 alanswx