cleanup socket code:

benefit of 34104bfb7ff3cabf9bbb0ce3788e28d3dc1457a5