refactorised net recv code