Skip to content

Commit a8a4358

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

1 file changed

Lines changed: 30 additions & 38 deletions

File tree

src/libvncclient/tls_openssl.c

Lines changed: 30 additions & 38 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)
@@ -364,13 +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+
finished = 1;
348+
SSL_shutdown(ssl);
349+
goto error_free_ssl;
350+
}
351+
352+
break;
353+
default:
354+
verify_res = SSL_get_verify_result(ssl);
355+
if (verify_res != X509_V_OK)
356+
rfbClientLog("Could not verify server certificate: %s.\n",
357+
X509_verify_cert_error_string(verify_res));
358+
359+
ERR_clear_error();
360+
finished = 1;
361+
SSL_shutdown(ssl);
362+
goto error_free_ssl;
363+
break;
364+
}
365+
ERR_clear_error();
374366
}
375367
} while( n != 1 && finished != 1 );
376368

0 commit comments

Comments
 (0)