Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
micropython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
micropython
Commits
6b4d4a25
Commit
6b4d4a25
authored
Jul 21, 2017
by
Eric Poulsen
Committed by
Damien George
Jul 26, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
extmod/modussl_mbedtls: Implement non-blocking SSL sockets.
parent
f3687109
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
6 deletions
+19
-6
extmod/modussl_mbedtls.c
extmod/modussl_mbedtls.c
+19
-6
No files found.
extmod/modussl_mbedtls.c
View file @
6b4d4a25
...
...
@@ -29,6 +29,7 @@
#include <stdio.h>
#include <string.h>
#include <errno.h> // needed because mp_is_nonblocking_error uses system error codes
#include "py/nlr.h"
#include "py/runtime.h"
...
...
@@ -83,6 +84,9 @@ int _mbedtls_ssl_send(void *ctx, const byte *buf, size_t len) {
int
out_sz
=
sock_stream
->
write
(
sock
,
buf
,
len
,
&
err
);
if
(
out_sz
==
MP_STREAM_ERROR
)
{
if
(
mp_is_nonblocking_error
(
err
))
{
return
MBEDTLS_ERR_SSL_WANT_WRITE
;
}
return
-
err
;
}
else
{
return
out_sz
;
...
...
@@ -97,6 +101,9 @@ int _mbedtls_ssl_recv(void *ctx, byte *buf, size_t len) {
int
out_sz
=
sock_stream
->
read
(
sock
,
buf
,
len
,
&
err
);
if
(
out_sz
==
MP_STREAM_ERROR
)
{
if
(
mp_is_nonblocking_error
(
err
))
{
return
MBEDTLS_ERR_SSL_WANT_READ
;
}
return
-
err
;
}
else
{
return
out_sz
;
...
...
@@ -199,6 +206,9 @@ STATIC mp_uint_t socket_read(mp_obj_t o_in, void *buf, mp_uint_t size, int *errc
if
(
ret
>=
0
)
{
return
ret
;
}
if
(
ret
==
MBEDTLS_ERR_SSL_WANT_READ
)
{
ret
=
MP_EWOULDBLOCK
;
}
*
errcode
=
ret
;
return
MP_STREAM_ERROR
;
}
...
...
@@ -210,17 +220,20 @@ STATIC mp_uint_t socket_write(mp_obj_t o_in, const void *buf, mp_uint_t size, in
if
(
ret
>=
0
)
{
return
ret
;
}
if
(
ret
==
MBEDTLS_ERR_SSL_WANT_WRITE
)
{
ret
=
MP_EWOULDBLOCK
;
}
*
errcode
=
ret
;
return
MP_STREAM_ERROR
;
}
STATIC
mp_obj_t
socket_setblocking
(
mp_obj_t
self_in
,
mp_obj_t
flag_in
)
{
// Currently supports only blocking mode
(
void
)
self_in
;
if
(
!
mp_obj_is_true
(
flag_in
))
{
mp_not_implemented
(
""
);
}
return
mp_c
onst_none
;
mp_obj_ssl_socket_t
*
o
=
MP_OBJ_TO_PTR
(
self_in
);
mp_obj_t
sock
=
o
->
sock
;
mp_obj_t
dest
[
3
];
mp_load_method
(
sock
,
MP_QSTR_setblocking
,
dest
);
dest
[
2
]
=
flag_in
;
return
mp_c
all_method_n_kw
(
1
,
0
,
dest
)
;
}
STATIC
MP_DEFINE_CONST_FUN_OBJ_2
(
socket_setblocking_obj
,
socket_setblocking
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment