diff options
author | Emmanuel Vasilakis <mrzammler@mm.st> | 2023-02-22 19:14:43 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-22 19:14:43 +0200 |
commit | ff4eece8eeebfe9d084b51a3f3337e0cf39c0c3d (patch) | |
tree | 063f443f3d88bf13c33f16dbd30358b9ead87d0e /libnetdata | |
parent | 4622734378d671a245f472ce2ae266c605f3c11a (diff) |
Misc SSL improvements 2 (#14334)
* set to wait receive/send when ssl returns wait read/write
* compare the bytes
* set to normal to prevent going into stream mode with incomplete request
* disable wait send
Diffstat (limited to 'libnetdata')
-rw-r--r-- | libnetdata/socket/socket.c | 27 |
1 files changed, 5 insertions, 22 deletions
diff --git a/libnetdata/socket/socket.c b/libnetdata/socket/socket.c index 69124b9491..eb8e3a93da 100644 --- a/libnetdata/socket/socket.c +++ b/libnetdata/socket/socket.c @@ -923,53 +923,36 @@ int connect_to_one_of_urls(const char *destination, int default_port, struct tim ssize_t netdata_ssl_read(SSL *ssl, void *buf, size_t num) { error_limit_static_thread_var(erl, 1, 0); - int bytes, err, retries = 0; + int bytes, err; - //do { bytes = SSL_read(ssl, buf, (int)num); err = SSL_get_error(ssl, bytes); - retries++; - //} while (bytes <= 0 && err == SSL_ERROR_WANT_READ); if(unlikely(bytes <= 0)) { if (err == SSL_ERROR_WANT_WRITE || err == SSL_ERROR_WANT_READ) { bytes = 0; } else - error("SSL_write() returned %d bytes, SSL error %d", bytes, err); + error_limit(&erl, "SSL_write() returned %d bytes, SSL error %d", bytes, err); } - if(retries > 1) - error_limit(&erl, "SSL_read() retried %d times", retries); - return bytes; } ssize_t netdata_ssl_write(SSL *ssl, const void *buf, size_t num) { error_limit_static_thread_var(erl, 1, 0); - int bytes, err, retries = 0; - size_t total = 0; + int bytes, err; - //do { - bytes = SSL_write(ssl, (uint8_t *)buf + total, (int)(num - total)); + bytes = SSL_write(ssl, (uint8_t *)buf, (int)num); err = SSL_get_error(ssl, bytes); - retries++; - - if(bytes > 0) - total += bytes; - - //} while ((bytes <= 0 && (err == SSL_ERROR_WANT_WRITE)) || (bytes > 0 && total < num)); if(unlikely(bytes <= 0)) { if (err == SSL_ERROR_WANT_WRITE || err == SSL_ERROR_WANT_READ) { bytes = 0; } else - error("SSL_write() returned %d bytes, SSL error %d", bytes, err); + error_limit(&erl, "SSL_write() returned %d bytes, SSL error %d", bytes, err); } - if(retries > 1) - error_limit(&erl, "SSL_write() retried %d times", retries); - return bytes; } #endif |