Skip to content

Commit c74cf74

Browse files
committed
Detect disconnection for GnuTLS as well
1 parent efe2940 commit c74cf74

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

src/tls_gnutls.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
* TLS implementation with GNUTLS
1515
*/
1616

17+
#include <errno.h>
1718
#include <string.h>
19+
#include <sys/socket.h>
1820
#include <gnutls/gnutls.h>
1921
#include <gnutls/x509.h>
2022
#include <gnutls/x509-ext.h>
@@ -665,6 +667,15 @@ int tls_read(struct conn_interface *intf, void *buff, size_t len)
665667
ret = gnutls_record_recv(tls->session, buff, len);
666668
tls->lasterror = ret < 0 ? ret : 0;
667669

670+
if (ret == GNUTLS_E_AGAIN || ret == GNUTLS_E_INTERRUPTED) {
671+
char c;
672+
ssize_t n = recv(intf->conn->sock, &c, 1, MSG_PEEK);
673+
if (n < 0 && errno == ENOTCONN) {
674+
strophe_debug(tls->ctx, "tls", "EAGAIN but connection is closed");
675+
tls->lasterror = GNUTLS_E_PULL_ERROR;
676+
}
677+
}
678+
668679
return ret;
669680
}
670681

0 commit comments

Comments
 (0)