Tommi Mäkitalo <tommi@...> writes:
> I would really like to understand, how you do this asynchrounous thing.

Here is another example for you:
http://stackoverflow.com/a/17598710/257568

It is my stackoverflow answer showing how to use coroutines
to make the asynchronous control flow look like synchronous;

Cherokee (http://cherokee-project.com/) allows the programmer to pause the
request by returning ret_eagain from the handler.
There's also cherokee_thread_deactive_to_polling which allows one
to use a file descriptor to tell Cherokee precisely when to wake up the
request. Here is how I use it in my tests:

  if (handler->sent == 0) {
    int eventFd = eventfd (0, EFD_CLOEXEC | EFD_NONBLOCK); if (eventFd ==
-1) {CERR ("eventfd: " << strerror (errno)); return ret_error;}
    handler->eventFd = eventFd;
    ret_t rc = cherokee_thread_deactive_to_polling (HANDLER_THREAD(handler),
HANDLER_CONN(handler), eventFd, FDPOLL_MODE_READ, false);
    (new Coro (handler, buffer))->start(); // Starts the coroutine.
    return ret_eagain;
  }
  if (handler->sent != 3) return ret_eagain;
  return ret_eof;



------------------------------------------------------------------------------
See everything from the browser to the database with AppDynamics
Get end-to-end visibility with application monitoring from AppDynamics
Isolate bottlenecks and diagnose root cause in seconds.
Start your free trial of AppDynamics Pro today!
http://pubads.g.doubleclick.net/gampad/clk?id=48808831&iu=/4140/ostg.clktrk
_______________________________________________
Tntnet-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tntnet-general

Reply via email to