Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle READ_WANT and WRITE_WANT during SSL read operation. #45

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
40 changes: 39 additions & 1 deletion src/est/est_client_http.c
Original file line number Diff line number Diff line change
Expand Up @@ -1169,7 +1169,45 @@ static int est_ssl_read (SSL *ssl, unsigned char *buf, int buf_max,
EST_LOG_ERR("Socket read failure. errno = %d", errno);
return -1;
} else {
return (SSL_read(ssl, buf, buf_max));
int err, ret, sock;
fd_set fds;
struct timeval timeout;
timeout.tv_sec = 5;

for (;;) {
ret = SSL_read(ssl, buf, buf_max);

// If we got bytes, return
if (ret > 0) return ret;

// Otherwise, check the error
switch (SSL_get_error(ssl, ret)) {
case SSL_ERROR_NONE:
break;
case SSL_ERROR_ZERO_RETURN:
return 0;
case SSL_ERROR_WANT_READ:
sock = SSL_get_rfd(ssl);
FD_ZERO(&fds);
FD_SET(sock, &fds);

err = select(sock+1, &fds, NULL, NULL, &timeout);

if (err > 0) continue;
return err;
case SSL_ERROR_WANT_WRITE:
sock = SSL_get_wfd(ssl);
FD_ZERO(&fds);
FD_SET(sock, &fds);

err = select(sock+1, NULL, &fds, NULL, &timeout);

if (err > 0) continue;
return err;
default:
return ret;
}
}
}
}

Expand Down