summaryrefslogtreecommitdiff
path: root/vio
diff options
context:
space:
mode:
authorVladislav Vaintroub <wlad@mariadb.com>2021-03-25 08:41:27 +0100
committerVladislav Vaintroub <wlad@mariadb.com>2021-03-25 11:16:54 +0100
commitda26e2e673970761d5000501f6171910f248d829 (patch)
treea81eefa4ee73bce91161d2619027bba42881b904 /vio
parent5a79807119974c37b4e9d3d46f8d68d29cfdba9e (diff)
downloadmariadb-git-da26e2e673970761d5000501f6171910f248d829.tar.gz
Cleanup - reduce duplicate code, in SSL IO error handling.bb-10.2-sysprg
Diffstat (limited to 'vio')
-rw-r--r--vio/viossl.c52
1 files changed, 29 insertions, 23 deletions
diff --git a/vio/viossl.c b/vio/viossl.c
index bdd3c9ca024..ebcc5246a1c 100644
--- a/vio/viossl.c
+++ b/vio/viossl.c
@@ -154,6 +154,32 @@ static my_bool ssl_should_retry(Vio *vio, int ret, enum enum_vio_io_event *event
}
+/**
+ Handle SSL io error.
+
+ @param[in] vio Vio
+ @param[in] ret return from the failed IO operation
+
+ @return 0 - should retry last read/write operation
+ 1 - some error has occured
+*/
+static int handle_ssl_io_error(Vio *vio, int ret)
+{
+ enum enum_vio_io_event event;
+ my_bool should_wait;
+
+ /* Process the SSL I/O error. */
+ if (!ssl_should_retry(vio, ret, &event, &should_wait))
+ return 1;
+
+ if (!should_wait)
+ return 1;
+
+ /* Attempt to wait for an I/O event. */
+ return vio_socket_io_wait(vio, event);
+}
+
+
size_t vio_ssl_read(Vio *vio, uchar *buf, size_t size)
{
int ret;
@@ -169,14 +195,7 @@ size_t vio_ssl_read(Vio *vio, uchar *buf, size_t size)
{
while ((ret= SSL_read(ssl, buf, (int)size)) < 0)
{
- enum enum_vio_io_event event;
- my_bool should_wait;
-
- /* Process the SSL I/O error. */
- if (!ssl_should_retry(vio, ret, &event, &should_wait))
- break;
- /* Attempt to wait for an I/O event. */
- if (should_wait && vio_socket_io_wait(vio, event))
+ if (handle_ssl_io_error(vio,ret))
break;
}
}
@@ -203,13 +222,7 @@ size_t vio_ssl_write(Vio *vio, const uchar *buf, size_t size)
{
while ((ret= SSL_write(ssl, buf, (int)size)) < 0)
{
- enum enum_vio_io_event event;
- my_bool should_wait;
- /* Process the SSL I/O error. */
- if (!ssl_should_retry(vio, ret, &event, &should_wait))
- break;
- /* Attempt to wait for an I/O event. */
- if (should_wait && vio_socket_io_wait(vio, event))
+ if (handle_ssl_io_error(vio,ret))
break;
}
}
@@ -316,14 +329,7 @@ static int ssl_handshake_loop(Vio *vio, SSL *ssl, ssl_handshake_func_t func)
/* Initiate the SSL handshake. */
while ((ret= func(ssl)) < 1)
{
- enum enum_vio_io_event event;
- my_bool should_wait;
-
- /* Process the SSL I/O error. */
- if (!ssl_should_retry(vio, ret, &event, &should_wait))
- break;
- /* Wait for I/O so that the handshake can proceed. */
- if (should_wait && vio_socket_io_wait(vio, event))
+ if (handle_ssl_io_error(vio,ret))
break;
}