0

i have such problem. I need to write multithread http server using libevent, but don't using <evhttp.h>. So i have problems with handle request. So i have

int main()
{
    ..............
    /*Some standard  stuff for binding to port*/
    ..............
    ev_accept = event_new(evbase_accept, listenfd, EV_READ|EV_PERSIST, on_accept, NULL);
    event_add(ev_accept, NULL);
    for(int i = 0;i < 4; i++) {
        std::thread (threadF).detach();
    }
    event_base_dispatch(evbase_accept);

So i try 2 possible variants:
1) i'll try in on_accept for each connection create client_fd with client_fd=accept(...) and then add it to my queue for handling, and then in threadF i pop element from queue and dispatch event for it, but i failed with too many fd open
2) in on_accept add fd to queue and then in threadF pop fd and client_fd=accept(...), but this fails too, but this fails too.
So what another possibilities you can advise me. Or what is the best strategy for multithreading handle request? Thank you.

Mike Minaev
  • 1,912
  • 4
  • 23
  • 33

0 Answers0