Persist side-effects in the main loop

The main loop now does
1. (re-)write any previous response (in an idempotent way)
2. block reading a new request
3. generate a reply
4. goto 1