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

done. (how did you even notice this?)