fix around closed socket. noreply could not read with NULL
refactor. use switch