> Interesting. I am not sure exactly how that would work. Do you have any
> simple examples?
Something like this (off top of my head):
shttp_copy(arg, ...)
{
setjmp(arg->priv->jump_buffer); // longjmp() will jump here
if (all_data_fit_output_buffer) {
arg->flags &= ~COPYOUT_STALLED;
}else {
arg->flags |= COPYOUT_STALLED;
}
copy_user_data_to_output_buffer();
}
shttpd_printf(..) { ..... shttpd_copy() .... }
... in io_emb.c ...
if (flags & COPYOUT_STALLED) // Do not call_user(), jump directly
longjmp(arg->jump_buffer);
So this way, shttpd_copy() will be entered as many times as needed until all
data is copied,
without entering the callback. And the callback may be written as
"synchronous" manner,
with the restriction of being careful with the global data.
Obviously the jump_buffer must be stored in the connection structure, not
sure about the
shttpd_arg itself.
>
> > We must make sure that data like shttpd_arg is dynamically allocated
> > and available
> > after the jump. Currently, it is a stack variable.
>
> What about everything else that is stored on the stack though, like local
> variables for loop indices? I can imagine how setjmp/longjmp could switch
> between two stacks but how would you set them up in the first place?
I beleive setjump merely stores the register context, it does not provide
the stack management.
If the stack is busted by subsequent function calls, and longjump is
executed, bad things may
happen. I would say, it is safe to longjump to a function that is up in call
chain hierarchy.
If the function is down the chain and being return()-ed (which is the case
for shttpd_copy() ),
the stack is defunitely busted, and special care must be taken
in this case. I cannot say what care is it, since the only way I implemented
setjmp/longjmp
is by calling "upper" function. That was for "exception handling" in my toy
language.
-------------------------------------------------------------------------
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