Commit ae281959 authored by Linus Nordberg's avatar Linus Nordberg

Don't wait for _writable_ when _reading_ an SSL socket.

Also, don't select() at all if SSL_pending() says there's data to
read.

Patch by Fabian Mauchle.
parent edaa77bc
...@@ -169,7 +169,7 @@ int tlsconnect(struct server *server, struct timeval *when, int timeout, char *t ...@@ -169,7 +169,7 @@ int tlsconnect(struct server *server, struct timeval *when, int timeout, char *t
/* returns 0 on timeout, -1 on error and num if ok */ /* returns 0 on timeout, -1 on error and num if ok */
int sslreadtimeout(SSL *ssl, unsigned char *buf, int num, int timeout) { int sslreadtimeout(SSL *ssl, unsigned char *buf, int num, int timeout) {
int s, ndesc, cnt, len; int s, ndesc, cnt, len;
fd_set readfds, writefds; fd_set readfds;
struct timeval timer; struct timeval timer;
s = SSL_get_fd(ssl); s = SSL_get_fd(ssl);
...@@ -177,16 +177,17 @@ int sslreadtimeout(SSL *ssl, unsigned char *buf, int num, int timeout) { ...@@ -177,16 +177,17 @@ int sslreadtimeout(SSL *ssl, unsigned char *buf, int num, int timeout) {
return -1; return -1;
/* make socket non-blocking? */ /* make socket non-blocking? */
for (len = 0; len < num; len += cnt) { for (len = 0; len < num; len += cnt) {
FD_ZERO(&readfds); if (SSL_pending(ssl) == 0) {
FD_SET(s, &readfds); FD_ZERO(&readfds);
writefds = readfds; FD_SET(s, &readfds);
if (timeout) { if (timeout) {
timer.tv_sec = timeout; timer.tv_sec = timeout;
timer.tv_usec = 0; timer.tv_usec = 0;
}
ndesc = select(s + 1, &readfds, NULL, NULL, timeout ? &timer : NULL);
if (ndesc < 1)
return ndesc;
} }
ndesc = select(s + 1, &readfds, &writefds, NULL, timeout ? &timer : NULL);
if (ndesc < 1)
return ndesc;
cnt = SSL_read(ssl, buf + len, num - len); cnt = SSL_read(ssl, buf + len, num - len);
if (cnt <= 0) if (cnt <= 0)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment