it looks like it is fairly possible to emulate coroutines
using the trick described on Simon Thatham's page.

There gonna be one big restriction though:
the callback must NOT use local variables.

Why so? The real coroutine preserves the stack, which we cannot do,
this is un-portable. We must call the function and jump to the
preserved location
instead. So all local variables must be collected in a structure, and
preallocated inside the connection variable. The callback then is passed the
pointer to preallocated space.

To do that, additional parameter, "size_t params_size" must be passed
to register_callback(). And the resiult will look like this:

struct my_callback_params {
     int a, b, c;
     FILE *fp;
    ......
};

 ...
 register_callback(ctx, "/foo", &my_callback, sizeof(struct
my_callback_params));

 ...
 void my_callback(struct shttpd_arg *arg) {
     struct my_callback_params *pp = arg->user_data;

    SHTTPD_STATEFUL_BEGIN(arg);

     pp->fp = fopen(...);
     while (shttpd_read(priv, pp->buf, ...))
        fwrite(pp->fp, ...);

    SHTTPD_STATEFUL_END();
 }

callback interface is greatly simplified then - no in/out buffers,
states, flags, etc.
The price is those ugly BEGIN/END macros and "no local vars" restriction.

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
shttpd-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/shttpd-general

Reply via email to