factor out TaskDispatcher#dispatch_to_{tcp,udp}