aboutsummaryrefslogtreecommitdiff
path: root/extmod/modussl_axtls.c
diff options
context:
space:
mode:
Diffstat (limited to 'extmod/modussl_axtls.c')
-rw-r--r--extmod/modussl_axtls.c31
1 files changed, 26 insertions, 5 deletions
diff --git a/extmod/modussl_axtls.c b/extmod/modussl_axtls.c
index da5941a55..9d5934206 100644
--- a/extmod/modussl_axtls.c
+++ b/extmod/modussl_axtls.c
@@ -167,10 +167,15 @@ STATIC mp_obj_ssl_socket_t *ussl_socket_new(mp_obj_t sock, struct ssl_args *args
o->ssl_sock = ssl_client_new(o->ssl_ctx, (long)sock, NULL, 0, ext);
if (args->do_handshake.u_bool) {
- int res = ssl_handshake_status(o->ssl_sock);
-
- if (res != SSL_OK) {
- ussl_raise_error(res);
+ int r = ssl_handshake_status(o->ssl_sock);
+
+ if (r != SSL_OK) {
+ if (r == SSL_CLOSE_NOTIFY) { // EOF
+ r = MP_ENOTCONN;
+ } else if (r == SSL_EAGAIN) {
+ r = MP_EAGAIN;
+ }
+ ussl_raise_error(r);
}
}
@@ -242,8 +247,24 @@ STATIC mp_uint_t ussl_socket_write(mp_obj_t o_in, const void *buf, mp_uint_t siz
return MP_STREAM_ERROR;
}
- mp_int_t r = ssl_write(o->ssl_sock, buf, size);
+ mp_int_t r;
+eagain:
+ r = ssl_write(o->ssl_sock, buf, size);
+ if (r == 0) {
+ // see comment in ussl_socket_read above
+ if (o->blocking) {
+ goto eagain;
+ } else {
+ r = SSL_EAGAIN;
+ }
+ }
if (r < 0) {
+ if (r == SSL_CLOSE_NOTIFY || r == SSL_ERROR_CONN_LOST) {
+ return 0; // EOF
+ }
+ if (r == SSL_EAGAIN) {
+ r = MP_EAGAIN;
+ }
*errcode = r;
return MP_STREAM_ERROR;
}