8000 Merge pull request #9006 from jepler/issue8988 · ladyada/circuitpython@bf423ff · GitHub
[go: up one dir, main page]

Skip to content

Commit bf423ff

Browse files
authored
Merge pull request adafruit#9006 from jepler/issue8988
ssl: Give correct errno value for "timed out" exceptions
2 parents 4a335af + 3e029a9 commit bf423ff

File tree

1 file changed

+6
-18
lines changed

1 file changed

+6
-18
lines changed

shared-module/ssl/SSLSocket.c

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ STATIC NORETURN void mbedtls_raise_error(int err) {
7171
mp_raise_OSError(-err);
7272
}
7373

74+
if (err == MBEDTLS_ERR_SSL_WANT_WRITE || err == MBEDTLS_ERR_SSL_WANT_READ) {
75+
mp_raise_OSError(MP_EWOULDBLOCK);
76+
}
77+
7478
#if defined(MBEDTLS_ERROR_C)
7579
// Including mbedtls_strerror takes about 1.5KB due to the error strings.
7680
// 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
271275
DEBUG_PRINT("returning %d\n", ret);
272276
return ret;
273277
}
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-
}
282278
DEBUG_PRINT("raising errno [error case] %d\n", ret);
283-
mp_raise_OSError(ret);
279+
mbedtls_raise_error(ret);
284280
}
285281

286282
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
290286
DEBUG_PRINT("returning %d\n", ret);
291287
return ret;
292288
}
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-
}
301289
DEBUG_PRINT("raising errno [error case] %d\n", ret);
302-
mp_raise_OSError(ret);
290+
mbedtls_raise_error(ret);
303291
}
304292

305293
size_t common_hal_ssl_sslsocket_bind(ssl_sslsocket_obj_t *self, const char *host, size_t hostlen, uint32_t port) {

0 commit comments

Comments
 (0)
0