Check for socket errors when connection is terminated by server

This means that when a connection fails or is closed due to a socket
error, the error is properly bubbled back up to the user.
This commit is contained in:
Kevin Easton
2015-06-13 23:29:00 +10:00
parent bc94fbe64a
commit 6077322ef8

View File

@@ -214,11 +214,21 @@ int BX_dgets (char *str, int des, int buffer, int buffersize, void *ssl_fd)
* use that as a cheap way to check for #1. If #1 is false, * use that as a cheap way to check for #1. If #1 is false,
* then #2 must have been true, and if nbytes is 0, then * then #2 must have been true, and if nbytes is 0, then
* that indicates an EOF condition. * that indicates an EOF condition.
*
* The "EOF" condition might actually be a socket error, so check
* for that and return it to the caller.
*/ */
else if (!nbytes && ioe->write_pos == 0) else if (!nbytes && ioe->write_pos == 0)
{ {
int so_error;
socklen_t len = sizeof so_error;
*str = 0; *str = 0;
dgets_errno = -1; if (getsockopt(des, SOL_SOCKET, SO_ERROR, &so_error, &len) == 0 &&
so_error != 0)
dgets_errno = so_error;
else
dgets_errno = -1;
return -1; return -1;
} }