@@ -71,6 +71,10 @@ STATIC NORETURN void mbedtls_raise_error(int err) {
71
71
mp_raise_OSError (- err );
72
72
}
73
73
74
+ if (err == MBEDTLS_ERR_SSL_WANT_WRITE || err == MBEDTLS_ERR_SSL_WANT_READ ) {
75
+ mp_raise_OSError (MP_EWOULDBLOCK );
76
+ }
77
+
74
78
#if defined(MBEDTLS_ERROR_C )
75
79
// Including mbedtls_strerror takes about 1.5KB due to the error strings.
76
80
// MBEDTLS_ERROR_C is the define used by mbedtls to conditionally include mbedtls_strerror.
@@ -271,16 +275,8 @@ mp_uint_t common_hal_ssl_sslsocket_recv_into(ssl_sslsocket_obj_t *self, uint8_t
271
275
DEBUG_PRINT ("returning %d\n" , ret );
272
276
return ret ;
273
277
}
274
- if (ret == MBEDTLS_ERR_SSL_WANT_READ ) {
275
- ret = MP_EWOULDBLOCK ;
276
- } else if (ret == MBEDTLS_ERR_SSL_WANT_WRITE ) {
277
- // If handshake is not finished, read attempt may end up in protocol
278
- // wanting to write next handshake message. The same may happen with
279
- // renegotiation.
280
- ret = MP_EWOULDBLOCK ;
281
- }
282
278
DEBUG_PRINT ("raising errno [error case] %d\n" , ret );
283
- mp_raise_OSError (ret );
279
+ mbedtls_raise_error (ret );
284
280
}
285
281
286
282
mp_uint_t common_hal_ssl_sslsocket_send (ssl_sslsocket_obj_t * self , const uint8_t * buf , uint32_t len ) {
@@ -290,16 +286,8 @@ mp_uint_t common_hal_ssl_sslsocket_send(ssl_sslsocket_obj_t *self, const uint8_t
290
286
DEBUG_PRINT ("returning %d\n" , ret );
291
287
return ret ;
292
288
}
293
- if (ret == MBEDTLS_ERR_SSL_WANT_WRITE ) {
294
- ret = MP_EWOULDBLOCK ;
295
- } else if (ret == MBEDTLS_ERR_SSL_WANT_READ ) {
296
- // If handshake is not finished, write attempt may end up in protocol
297
- // wanting to read next handshake message. The same may happen with
298
- // renegotiation.
299
- ret = MP_EWOULDBLOCK ;
300
- }
301
289
DEBUG_PRINT ("raising errno [error case] %d\n" , ret );
302
- mp_raise_OSError (ret );
290
+ mbedtls_raise_error (ret );
303
291
}
304
292
305
293
size_t common_hal_ssl_sslsocket_bind (ssl_sslsocket_obj_t * self , const char * host , size_t hostlen , uint32_t port ) {
0 commit comments