Make accept loop use a condition

The accept-loop is written as a while-true loop which returns in the
middle. This is a bit hard to read. Change it to run while the listener
exists and only create a new state object if the handler exists.

Signed-off-by: Marcus Karlsson <mk@acc.umu.se>