summaryrefslogtreecommitdiff
path: root/extmod/modussl_mbedtls.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2018-06-13 12:37:49 +1000
committerDamien George <damien.p.george@gmail.com>2018-06-18 12:35:56 +1000
commite8398a58567cc94b866d46721fd06289601f5c8a (patch)
tree945e71ba803c72eb420b3b4d08c65cc647076027 /extmod/modussl_mbedtls.c
parent6abede2ca9e221b6aefcaccbda0c89e367507df1 (diff)
extmod: Update to use new mp_get_stream helper.
With this patch objects are only checked that they have the stream protocol at the start of their use as a stream, and afterwards the efficient mp_get_stream() helper is used to extract the stream protocol C methods.
Diffstat (limited to 'extmod/modussl_mbedtls.c')
-rw-r--r--extmod/modussl_mbedtls.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/extmod/modussl_mbedtls.c b/extmod/modussl_mbedtls.c
index 1c9dfd17f..08807d20b 100644
--- a/extmod/modussl_mbedtls.c
+++ b/extmod/modussl_mbedtls.c
@@ -76,7 +76,7 @@ STATIC void mbedtls_debug(void *ctx, int level, const char *file, int line, cons
STATIC int _mbedtls_ssl_send(void *ctx, const byte *buf, size_t len) {
mp_obj_t sock = *(mp_obj_t*)ctx;
- const mp_stream_p_t *sock_stream = mp_get_stream_raise(sock, MP_STREAM_OP_WRITE);
+ const mp_stream_p_t *sock_stream = mp_get_stream(sock);
int err;
mp_uint_t out_sz = sock_stream->write(sock, buf, len, &err);
@@ -93,7 +93,7 @@ STATIC int _mbedtls_ssl_send(void *ctx, const byte *buf, size_t len) {
STATIC int _mbedtls_ssl_recv(void *ctx, byte *buf, size_t len) {
mp_obj_t sock = *(mp_obj_t*)ctx;
- const mp_stream_p_t *sock_stream = mp_get_stream_raise(sock, MP_STREAM_OP_READ);
+ const mp_stream_p_t *sock_stream = mp_get_stream(sock);
int err;
mp_uint_t out_sz = sock_stream->read(sock, buf, len, &err);
@@ -109,6 +109,9 @@ STATIC int _mbedtls_ssl_recv(void *ctx, byte *buf, size_t len) {
STATIC mp_obj_ssl_socket_t *socket_new(mp_obj_t sock, struct ssl_args *args) {
+ // Verify the socket object has the full stream protocol
+ mp_get_stream_raise(sock, MP_STREAM_OP_READ | MP_STREAM_OP_WRITE | MP_STREAM_OP_IOCTL);
+
#if MICROPY_PY_USSL_FINALISER
mp_obj_ssl_socket_t *o = m_new_obj_with_finaliser(mp_obj_ssl_socket_t);
#else