WEB SERVER: retry sending data when errno is EAGAIN (#18607)
retry sending data when errno is EAGAIN
Costa Tsaousis committed
Sep 24, 2024 at 13:57 UTC
9fee3df924ac3cf38def297614568531e2ff5828
1 file changed
+20
-13
src/web/server/web_client.c
+20
-13
@@ -818,21 +818,28 @@ HTTP_VALIDATION http_request_validate(struct web_client *w) {
818
819
static inline ssize_t web_client_send_data(struct web_client *w,const void *buf,size_t len, int flags)
820
{
821
- ssize_t bytes;
822
- if ((web_client_check_conn_tcp(w)) && (netdata_ssl_web_server_ctx)) {
823
- if (SSL_connection(&w->ssl)) {
824
- bytes = netdata_ssl_write(&w->ssl, buf, len) ;
825
- web_client_enable_wait_from_ssl(w);
826
- }
821
+ do {
822
+ errno_clear();
823
+
824
+ ssize_t bytes;
825
+ if ((web_client_check_conn_tcp(w)) && (netdata_ssl_web_server_ctx)) {
826
+ if (SSL_connection(&w->ssl)) {
827
+ bytes = netdata_ssl_write(&w->ssl, buf, len);
828
+ web_client_enable_wait_from_ssl(w);
829
+ } else
830
+ bytes = send(w->ofd, buf, len, flags);
831
+ } else if (web_client_check_conn_tcp(w) || web_client_check_conn_unix(w))
832
+ bytes = send(w->ofd, buf, len, flags);
833
else
828
- bytes = send(w->ofd,buf, len , flags);
829
- }
830
- else if(web_client_check_conn_tcp(w) || web_client_check_conn_unix(w))
831
- bytes = send(w->ofd,buf, len , flags);
832
- else
833
- bytes = -999;
834
+ bytes = -999;
835
835
- return bytes;
836
+ if(bytes < 0 && errno == EAGAIN) {
837
+ tinysleep();
838
+ continue;
839
+ }
840
+
841
+ return bytes;
842
+ } while(true);
843
}
844
845
void web_client_build_http_header(struct web_client *w) {