On Thu, May 29, 2008 at 2:34 PM, Rui Jorge Coelho <[EMAIL PROTECTED]>
wrote:
> * My current implementation is a one-way producer-consumer using pipes
> in which the workers write an object pointer to the main-consumer
> thread.
>
> * "write to a pipe or FIFO .... IEEE Std 1003.1-2001 does not say
> whether write requests for more than {PIPE_BUF} bytes are atomic, but
> requires that writes of {PIPE_BUF} or fewer bytes shall be atomic" ...
> even if O_NONBLOCK is set
> See <http://www.opengroup.org/onlinepubs/000095399/functions/write.html>
> Do you think this also applies to AF_INET sockets?
Cool:
*A write request for {PIPE_BUF} or fewer bytes shall have the following
effect: if there is sufficient space available in the pipe, write() shall
transfer all the data and return the number of bytes requested. Otherwise,
write() shall transfer no data and return -1 with errno* set to [EAGAIN].
This means, if you set NONBLOCK on your pipe (and you should, since callback
must not block), you're guaranteed to send your messages atomically if
they're small enough.
It does not apply for sockets, though:
*If the O_NONBLOCK flag is set, write() shall not block the thread. If some
data can be written without blocking the thread, write() shall write what it
can and return the number of bytes written. Otherwise, it shall return -1
and set errno to [EAGAIN].
*
So you may use pipes to pass your data. And, only one pipe is sufficient -
you do not need fancy SHTTPD interface to manage threads.
> * "If the data is too long to pass atomically through the underlying
> protocol, the error WSAEMSGSIZE is returned"
> See
> <http://msdn.microsoft.com/en-us/library/ms740149(VS.85).aspx<http://msdn.microsoft.com/en-us/library/ms740149%28VS.85%29.aspx>
> >
> Do you think this can be interpreted that 1 write()/send() call in
> WINDOWS is atomic?
>
I think so.
>
> * Also shttpd_socketpair looks good, but should be used for WINDOWS only
> ... in UNIX why not use pipe() syscall?
>
shttpd_socketpair is crossplatform way of making socket pipe.
It is not good you, though.
The other way to pass data to the main thread is to use shared memory.
You've got many producers and one consumer.
You can allocate shared memory, as a ringbuffer, with tail and head.
Consumers may write data into ringbuffer:
o advance head lock-lessly
o write data into buffer (old head location, new head location)
Consumer just reads the data, advancing tail.
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
shttpd-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/shttpd-general