[ANN] x0 HTTP server and framework (initial release)
Graham Leggett
minfrin at sharp.fm
Thu Apr 1 10:53:39 CEST 2010
On 31 Mar 2010, at 4:57 PM, Christian Parpart wrote:
> x0 also includes support for SSL (via gnutls), which is currently
> integrated directly into the core, because it was easier to
> implement it
> this way for me, as the asynchronous SSL-handshake made my headache-
> less
> nights rare and I still search for an ideal connection-level API to be
> able to encapsulate SSL into its dedicated plugin.
A while back I implemented async non blocking SSL using openssl +
libev, and was able to keep the SSL part modular (also for a server,
but not HTTP). This is tricky, because SSL_read might want to write to
a socket as well as read from it, and you need to be sure before you
attempt to write that you have received an event to say the socket is
writable.
You might be tempted to keep two socket watchers going for listening
to socket read events, and socket write events, but to support SSL
asynchronously you need two sets of two socket watcher events (making
four), socket read/read (listening for read events), socket read/write
(listening for write events) pointing at your read handler, followed
by socket write/write (listening for write events), and socket write/
read (listening for read events) pointing at your write handler.
Under normal reading conditions, you switch on the read/read event,
and wait for read events to come in. When SSL_read returns
SSL_ERROR_WANT_WRITE, you switch off the read/read event, and switch
on the read/write event, waiting for a write to come in, and SSL_read
is signalled correctly that it is safe to write. When the write is
done with SSL_read writing, you switch off read/write, switch on read/
read, and you're back on track as before.
Supporting SSL_write works the same way.
> server protocol features:
> * should basically implement HTTP/1.1 (not (yet) everything)
> * HTTP keep-alive
> * supports HTTP pipelining
> * partial responses (via Range request-header) on static files
> * automatic chunked encoding
> if not response content-length is set, chunked encoding
> is enabled automatically by appending a chunked_encoding filter
> at the end of the filter-list.
Not sure how far you are, but the APR-util library underneath httpd
gives you some very powerful and helpful APIs, most specifically the
bucket brigades API, to give you a "virtual" view (buckets) of
"physical" memory areas (area in RAM, static area in RAM, area in file
on disk, data in socket, etc), which in turn makes it easy to support
SENDFILE, as well as the pools API, which allows you the freedom to
fail your request or connection at any time and be guaranteed you've
freed all your RAM with no leaks. Works side by side with libev
without a problem.
Good luck!
Regards,
Graham
--
More information about the libev
mailing list