Move request/response matching into a function
Ignore SIGPIPE and handle socket write errors properly

SIGPIPE is no ignored instead of letting the default handler exit
the process.

Clients are now disconnected on socket write errors.

Splitted client disconnect handling into two phases. This allows marking
clients as disconnected while iterating the client array. This is similar
to the event source remove handling.