refine buffer read socket logic.