http service break into outer loop states
authorAndy Green <andy.green@linaro.org>
Tue, 15 Jan 2013 05:40:23 +0000 (13:40 +0800)
committerAndy Green <andy.green@linaro.org>
Tue, 15 Jan 2013 08:00:36 +0000 (16:00 +0800)
commitd280b6ecb318ba008cb618b510a3e8ae887800c1
tree6a2c4dd0e19115b5968d4832dde578ee07b758b4
parenta50dd1af40c4cb6add355a1ff7db2637361e650b
http service break into outer loop states

Previously we sat and looped to dump a file over http protocol.

Actually that's a source of blocking to the other sockets being serviced.

This patch breaks up the file service into a roundtrip around the poll()
loop for each 512-byte packet.  It doesn't make much difference if the
server is idle, but if it's busy it makes sure everyone else is getting
service while the file is sent.

It doesn't try to optimize multiple users of the file or to keep the
descriptor open, the point of this patch is to establish the breaking up
of the file send action into the poll loop.

On the user side, there are two differences:

 - context is now needed in the first argument to libwebsockets_serve_http_file()
that's not too bad since we provide context in the callback.

 - file send is now asynchronous to the user code, you get a new callback coming
in protocol 0 when it's done, LWS_CALLBACK_HTTP_FILE_COMPLETION

libwebsockets-test-server is updated accordingly.

Signed-off-by: Andy Green <andy.green@linaro.org>
lib/handshake.c
lib/libwebsockets.c
lib/libwebsockets.h
lib/parsers.c
lib/private-libwebsockets.h
libwebsockets-api-doc.html
test-server/test-server.c