Improve error handling in ssl_socket_read() function.

Inspired by code from freebsd libfetch common.c:fetch_ssl_read() function.

Signed-off-by: Thiago Farina <tfarina@chromium.org>