Attempt to make socket operations more robust.

Especially in TLS contexts, even if the underlying I/O subsystem says
there is data available for reading/writing, there can be actually not
enough available due packet encapsulation. Handle this by bailing out.