Browse Source

Reuse timeout for SSL Connect and Accept operation.

The SSL_Accept and SSL_Connect operations had a timeout of 2 seconds,
for slow and bad networks, this caused disconnects in the Connect and
Accept stages. This change allow the timeout to be reused to allow
SSL_Connect and SSL_Accept to be longer.
Retallack Mark mark.retallack 6 years ago
parent
commit
1917a2222a
1 changed files with 9 additions and 1 deletions
  1. 9 1
      src/civetweb.c

+ 9 - 1
src/civetweb.c

@@ -15059,6 +15059,7 @@ sslize(struct mg_connection *conn,
 {
 	int ret, err;
 	int short_trust;
+	unsigned timeout=1024;
 	unsigned i;
 
 	if (!conn) {
@@ -15098,10 +15099,17 @@ sslize(struct mg_connection *conn,
 		}
 	}
 
+	/* Reuse the request timeout for the SSL_Accept/SSL_connect timeout  */
+	if (conn->dom_ctx->config[REQUEST_TIMEOUT]) {
+		/* NOTE: The loop below acts as a back-off, so we can end 
+		 * up sleeping for more (or less) than the REQUEST_TIMEOUT. */
+		timeout = atoi(conn->dom_ctx->config[REQUEST_TIMEOUT]);
+	}
+
 	/* SSL functions may fail and require to be called again:
 	 * see https://www.openssl.org/docs/manmaster/ssl/SSL_get_error.html
 	 * Here "func" could be SSL_connect or SSL_accept. */
-	for (i = 16; i <= 1024; i *= 2) {
+	for (i = 16; i <= timeout; i *= 2) {
 		ret = func(conn->ssl);
 		if (ret != 1) {
 			err = SSL_get_error(conn->ssl, ret);