Skip to content

Commit cd3f965

Browse files
committed
Use pseudo errno value instead of SSL_write() result
SSL_write(3) does not set errno, but sets an internal error code. Also check for EAGAIN cases.
1 parent ea71812 commit cd3f965

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

src/netlog/netlog-dtls.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,13 @@ static int dtls_write(DTLSManager *m, const char *buf, size_t count) {
2727

2828
ERR_clear_error();
2929
r = SSL_write(m->ssl, buf, count);
30-
if (r <= 0)
31-
return log_error_errno(r, "DTLS: Failed to invoke SSL_write: %s", TLS_ERROR_STRING(SSL_get_error(m->ssl, r)));
30+
if (r <= 0) {
31+
int error = SSL_get_error(m->ssl, r);
32+
if (IN_SET(error, SSL_ERROR_WANT_READ, SSL_ERROR_WANT_WRITE))
33+
return log_info_errno(SYNTHETIC_ERRNO(EAGAIN), "DTLS: Failed to invoke SSL_write: %s", TLS_ERROR_STRING(error));
34+
else
35+
return log_error_errno(SYNTHETIC_ERRNO(EPIPE), "DTLS: Failed to invoke SSL_write: %s", TLS_ERROR_STRING(error));
36+
}
3237

3338
return log_debug("DTLS: Successful SSL_write: %d bytes", r);
3439
}

src/netlog/netlog-tls.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,13 @@ static int tls_write(TLSManager *m, const char *buf, size_t count) {
3737

3838
ERR_clear_error();
3939
r = SSL_write(m->ssl, buf, count);
40-
if (r <= 0)
41-
return log_error_errno(r, "TLS: Failed to invoke SSL_write: %s", TLS_ERROR_STRING(SSL_get_error(m->ssl, r)));
40+
if (r <= 0) {
41+
int error = SSL_get_error(m->ssl, r);
42+
if (IN_SET(error, SSL_ERROR_WANT_READ, SSL_ERROR_WANT_WRITE))
43+
return log_info_errno(SYNTHETIC_ERRNO(EAGAIN), "TLS: Failed to invoke SSL_write: %s", TLS_ERROR_STRING(error));
44+
else
45+
return log_error_errno(SYNTHETIC_ERRNO(EPIPE), "TLS: Failed to invoke SSL_write: %s", TLS_ERROR_STRING(error));
46+
}
4247

4348
return log_debug("TLS: Successful TLS SSL_write: %d bytes", r);
4449
}

0 commit comments

Comments
 (0)