Martin Mares [Tue, 22 Nov 2011 16:13:32 +0000 (17:13 +0100)]
UCW::CGI: Report all errors by proper HTTP status codes
All calls to die have been replaced by returning a proper HTTP status
code. (A sole exception is if we fail, because we were not run as a CGI
script at all.)
Also, the set of supported HTTP methods now includes HEAD.
Martin Mares [Fri, 19 Aug 2011 10:29:34 +0000 (12:29 +0200)]
Main: Clean up handling of poll flags
- We no longer include POLLERR and POLLHUP in the set of requested
events. The standard (SUSv2) says they will be delivered regardless
of the event mask chosen.
- POLLERR is an output event, so we call only the write handler.
- POLLHUP is documented as an output event, but it sometimes signals
events which we would like to process by the input handler. The
situations when POLLHUP is generated include:
* on reading end of a pipe when the writing end has been closed
-> we would like to call read handler and get EOF (write handler
does not exist)
* on writing end of a pipe when the reading end has been closed
-> we would like to call write handler (read handler does not
exist)
* on a R/W socket when the other end has been closed -> better
call read handler to get an EOF
* on a tty which has been hanged up -> probably the same as a R/W
socket
We have therefore decided to call the read handler, but fall back to
the write handler if the read handler does not exist.
- When a handler decided to remove itself (but keep the main_file),
we could have entered an infinite loop. This no longer happens.
Martin Mares [Thu, 9 Jun 2011 16:04:26 +0000 (18:04 +0200)]
Main recio: Allow rec_io_(start|stop)_read from the read_handler
This involves rescanning the read buffer on rec_io_start_read()
as there might be leftover data from previous invokations of the
read_handler.
However, we have to be careful to avoid arbitrarily deep recursion
of various handlers. We do that by deferring the actual start of
reading to a main_hook.
Martin Mares [Sat, 26 Feb 2011 11:11:16 +0000 (12:11 +0100)]
Main: Added main_teardown() and main_destroy()
There are now two possibilities how to get rid of a main loop
context. Either you call main_delete(), which is gentle and fails
whenever there are any active files/hooks/etc. Or you call main_destroy(),
which forcibly removes all such objects; it also closes all files.
main_teardown() just calls main_destroy() on the current context,
just as main_cleanup() calls main_delete().
Also, file_close_all() is no longer available -- the only known use
cases are after fork(), but closing files is no longer sufficient
there. All calls to file_close_all() should be therefore replaced
by main_teardown().
Martin Mares [Thu, 7 Oct 2010 14:58:43 +0000 (16:58 +0200)]
UCW::Configure::C: de-reference CPU_ARCH in COPT
Originally, when CONFIG_EXACT_CPU was enabled, COPT contained `-march=$(CPU_ARCH)',
which worked when it was used in a Makefile, but not when doing a test
compile in the configure script.
I changed it to dereference the variable immediately.
Martin Mares [Fri, 1 Oct 2010 18:57:25 +0000 (20:57 +0200)]
Added a clean way for building of static PIC libraries
Defining CONFIG_STATIC_PIC adds a dependency on *-pic.a
to every pkg-config file. In addition to that, the .pc
files now contain a "picsuffix" variable which can be
overridden by the user to enable the PIC mode.
Martin Mares [Fri, 30 Jul 2010 18:42:57 +0000 (20:42 +0200)]
Main: Optimize calls to epoll_ctl()
It often happens that a file callback is removed and then reinstated
again before the next main loop iteration (e.g., on a boundary between
two blocks if block_io is used). This caused lots of unnecessary
calls to epoll_ctl().
We now put all files on which file_chg() was called to a separate list
and just before we call epoll_wait(), we process this list and check
which files have changed their event mask since the last iteration.
Martin Mares [Fri, 30 Jul 2010 18:24:56 +0000 (20:24 +0200)]
Main: Unified support for poll and epoll
When the epoll mechanism is available in the system library, use it.
Rewritten processing of file events: when (e)poll completes, all pending
events are scanned and the corresponding files are relinked to another
list. Then this list is processed entry by entry and callbacks are
performed. When file_add() or file_del() is requested from the callback
function, the file is just relinked to the main file_list and the worst
thing which can happen is that an event will be postponed to the next
iteration of the main loop.
To achieve this, I had to decouple the order of entries in the poll_table
from the order of files in the file_list by introducing an auxiliary
array of pointers mapping poll_table entries to file structs.
All tricks with stopping the event scanning loop when poll_table_obsolete
becomes set are gone.
Martin Mares [Wed, 28 Jul 2010 22:30:10 +0000 (00:30 +0200)]
Main: Split off block I/O
Block-based I/O is no longer hard-wired in the mainloop itself,
it became a separate module built on the top of main_file. While the
timer embedded in main_block_io is somewhat illogical, I have decided
to keep it to make porting of old code easier.
I plan to add another I/O layer in the future, which will handle
more complex buffering capable of reading lines and other variable-size
data structures.
Martin Mares [Wed, 28 Jul 2010 21:56:29 +0000 (23:56 +0200)]
Main: Implemented safe delivery of signals
The current implementation passes the signals through a pipe,
I plan to add signalfd() later.
SIGCHLD handling became the first user of the new signal mechanism.
However, situations in which multiple threads spawn processes using
separate main loops are not supported (we must have a single SIGCHLD
handler for the whole process).
Martin Mares [Mon, 19 Jul 2010 15:27:12 +0000 (17:27 +0200)]
UCW::CGI: Support multiple argument tables
(1) parse_args() can be called multiple times with different
argument tables, so that different parts of a single script
can fetch their own arguments without cluttering the main
argument table. The only catch is that uploaded files must
be defined in the main argument table (i.e., the first one used).
(2) self_ref() and self_form() accepts optional argument tables
which are merged to the main one.