Skip to content

Commit d96100e

Browse files
committed
libvncclient: tls_openssl: inline wait_for_data()
1 parent e859760 commit d96100e

File tree

1 file changed

+30
-40
lines changed

1 file changed

+30
-40
lines changed

src/libvncclient/tls_openssl.c

Lines changed: 30 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -182,37 +182,6 @@ static int sock_read_ready(SSL *ssl, uint32_t ms)
182182
return r;
183183
}
184184

185-
static int wait_for_data(SSL *ssl, int ret, int timeout)
186-
{
187-
int err;
188-
int retval = 1;
189-
190-
err = SSL_get_error(ssl, ret);
191-
192-
switch(err)
193-
{
194-
case SSL_ERROR_WANT_READ:
195-
case SSL_ERROR_WANT_WRITE:
196-
ret = sock_read_ready(ssl, timeout*1000);
197-
198-
if (ret == -1) {
199-
retval = 2;
200-
}
201-
202-
break;
203-
default:
204-
retval = 3;
205-
long verify_res = SSL_get_verify_result(ssl);
206-
if (verify_res != X509_V_OK)
207-
rfbClientLog("Could not verify server certificate: %s.\n",
208-
X509_verify_cert_error_string(verify_res));
209-
break;
210-
}
211-
212-
ERR_clear_error();
213-
214-
return retval;
215-
}
216185

217186
static rfbBool
218187
load_crls_from_file(char *file, SSL_CTX *ssl_ctx)
@@ -257,7 +226,7 @@ open_ssl_connection (rfbClient *client, int sockfd, rfbBool anonTLS, rfbCredenti
257226
{
258227
SSL_CTX *ssl_ctx = NULL;
259228
SSL *ssl = NULL;
260-
int n, finished = 0;
229+
int n;
261230
X509_VERIFY_PARAM *param;
262231
uint8_t verify_crls;
263232

@@ -364,15 +333,36 @@ open_ssl_connection (rfbClient *client, int sockfd, rfbBool anonTLS, rfbCredenti
364333

365334
if (n != 1)
366335
{
367-
if (wait_for_data(ssl, n, 1) != 1)
368-
{
369-
finished = 1;
370-
SSL_shutdown(ssl);
371-
372-
goto error_free_ssl;
373-
}
336+
int ready;
337+
long verify_res;
338+
339+
switch(SSL_get_error(ssl, n))
340+
{
341+
case SSL_ERROR_WANT_READ:
342+
case SSL_ERROR_WANT_WRITE:
343+
ready = sock_read_ready(ssl, 1000);
344+
345+
if (ready == -1) {
346+
ERR_clear_error();
347+
SSL_shutdown(ssl);
348+
goto error_free_ssl;
349+
}
350+
351+
break;
352+
default:
353+
verify_res = SSL_get_verify_result(ssl);
354+
if (verify_res != X509_V_OK)
355+
rfbClientLog("Could not verify server certificate: %s.\n",
356+
X509_verify_cert_error_string(verify_res));
357+
358+
ERR_clear_error();
359+
SSL_shutdown(ssl);
360+
goto error_free_ssl;
361+
break;
362+
}
363+
ERR_clear_error();
374364
}
375-
} while( n != 1 && finished != 1 );
365+
} while( n != 1 );
376366

377367
X509_VERIFY_PARAM_free(param);
378368
return ssl;

0 commit comments

Comments
 (0)