Skip to content

Commit

Permalink
Fix usage of mbedtls_ssl_read and mbedtls_ssl_write
Browse files Browse the repository at this point in the history
Signed-off-by: Jianhui Zhao <jianhuizhao329@gmail.com>
  • Loading branch information
Jianhui Zhao committed Feb 23, 2019
1 parent 2de3c0c commit 8681d4a
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/ssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,11 @@ int uwsc_ssl_read(int fd, void *buf, size_t count, void *arg)
}

ret = mbedtls_ssl_read(&ctx->ssl, buf, count);
if (ret == MBEDTLS_ERR_SSL_WANT_READ)
return P_FD_PENDING;
if (ret == 0)
if (ret < 0) {
if (ret == MBEDTLS_ERR_SSL_WANT_READ)
return P_FD_PENDING;
return P_FD_ERR;
}
if (ret > 0)
ctx->last_read_ok = true;
#else
Expand All @@ -186,10 +187,11 @@ int uwsc_ssl_write(int fd, void *buf, size_t count, void *arg)

#if UWSC_HAVE_MBEDTLS
int ret = mbedtls_ssl_write(&ctx->ssl, buf, count);
if (ret == MBEDTLS_ERR_SSL_WANT_WRITE)
return P_FD_PENDING;
if (ret == 0)
if (ret < 0) {
if (ret == MBEDTLS_ERR_SSL_WANT_WRITE)
return P_FD_PENDING;
return P_FD_ERR;
}
#else
int ret = SSL_write(ctx->ssl, buf, count);
if (ret < 0) {
Expand Down

0 comments on commit 8681d4a

Please sign in to comment.