Ikruglov/optimize try read sock

Fix issues noticed by Pavel Shaydo in the maillist. Attempt 2.