Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/tls_gnutls.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
* TLS implementation with GNUTLS
*/

#include <errno.h>
#include <string.h>
#include <sys/socket.h>
#include <gnutls/gnutls.h>
#include <gnutls/x509.h>
#include <gnutls/x509-ext.h>
Expand Down Expand Up @@ -665,6 +667,15 @@ int tls_read(struct conn_interface *intf, void *buff, size_t len)
ret = gnutls_record_recv(tls->session, buff, len);
tls->lasterror = ret < 0 ? ret : 0;

if (ret == GNUTLS_E_AGAIN || ret == GNUTLS_E_INTERRUPTED) {
char c;
ssize_t n = recv(intf->conn->sock, &c, 1, MSG_PEEK);
if (n < 0 && errno == ENOTCONN) {
strophe_debug(tls->ctx, "tls", "EAGAIN but connection is closed");
tls->lasterror = GNUTLS_E_PULL_ERROR;
}
}

return ret;
}

Expand Down
14 changes: 14 additions & 0 deletions src/tls_openssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#ifndef _WIN32
#include <sys/select.h>
#include <sys/socket.h>
#else
#include <winsock2.h>
#endif
Expand Down Expand Up @@ -963,6 +964,19 @@ int tls_read(struct conn_interface *intf, void *buff, size_t len)
ret = SSL_read(tls->ssl, buff, len);
_tls_set_error(tls, ret <= 0 ? SSL_get_error(tls->ssl, ret) : 0);

#ifndef _WIN32
if (tls->lasterror == SSL_ERROR_WANT_READ) {
char c;
ssize_t n = recv(intf->conn->sock, &c, 1, MSG_PEEK);
if (n < 0 && errno == ENOTCONN) {
strophe_debug(tls->ctx, "tls",
"WANT_READ but connection is closed");
_tls_set_error(tls,
SSL_ERROR_SYSCALL); // Set a more appropriate error
}
}
#endif

return ret;
}

Expand Down
Loading