Update timed_recv method with logic from 3.1 version.