Refactoring long polling transport to be able to fix bug #3227

This was one of those PRs where I felt the need to take a look at the branch in VS. There I have whitespace configured to be visible.