extmod/modussl: Support polling in ussl objects by passing through ioctl
The underlying socket can handling polling, and any other transparent ioctl requests. Note that CPython handles the case of polling an ssl object by polling the file descriptor of the underlying socket file, and that behaviour is emulated here.
This commit is contained in:
parent
4a2051eec7
commit
7a67f057d7
@ -177,21 +177,13 @@ STATIC mp_uint_t socket_write(mp_obj_t o_in, const void *buf, mp_uint_t size, in
|
|||||||
|
|
||||||
STATIC mp_uint_t socket_ioctl(mp_obj_t o_in, mp_uint_t request, uintptr_t arg, int *errcode) {
|
STATIC mp_uint_t socket_ioctl(mp_obj_t o_in, mp_uint_t request, uintptr_t arg, int *errcode) {
|
||||||
mp_obj_ssl_socket_t *self = MP_OBJ_TO_PTR(o_in);
|
mp_obj_ssl_socket_t *self = MP_OBJ_TO_PTR(o_in);
|
||||||
(void)arg;
|
if (request == MP_STREAM_CLOSE && self->ssl_sock != NULL) {
|
||||||
switch (request) {
|
|
||||||
case MP_STREAM_CLOSE:
|
|
||||||
if (self->ssl_sock != NULL) {
|
|
||||||
ssl_free(self->ssl_sock);
|
ssl_free(self->ssl_sock);
|
||||||
ssl_ctx_free(self->ssl_ctx);
|
ssl_ctx_free(self->ssl_ctx);
|
||||||
self->ssl_sock = NULL;
|
self->ssl_sock = NULL;
|
||||||
mp_stream_close(self->sock);
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
default:
|
|
||||||
*errcode = MP_EINVAL;
|
|
||||||
return MP_STREAM_ERROR;
|
|
||||||
}
|
}
|
||||||
|
// Pass all requests down to the underlying socket
|
||||||
|
return mp_get_stream(self->sock)->ioctl(self->sock, request, arg, errcode);
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC mp_obj_t socket_setblocking(mp_obj_t self_in, mp_obj_t flag_in) {
|
STATIC mp_obj_t socket_setblocking(mp_obj_t self_in, mp_obj_t flag_in) {
|
||||||
|
@ -270,9 +270,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_setblocking_obj, socket_setblocking);
|
|||||||
|
|
||||||
STATIC mp_uint_t socket_ioctl(mp_obj_t o_in, mp_uint_t request, uintptr_t arg, int *errcode) {
|
STATIC mp_uint_t socket_ioctl(mp_obj_t o_in, mp_uint_t request, uintptr_t arg, int *errcode) {
|
||||||
mp_obj_ssl_socket_t *self = MP_OBJ_TO_PTR(o_in);
|
mp_obj_ssl_socket_t *self = MP_OBJ_TO_PTR(o_in);
|
||||||
(void)arg;
|
if (request == MP_STREAM_CLOSE) {
|
||||||
switch (request) {
|
|
||||||
case MP_STREAM_CLOSE:
|
|
||||||
mbedtls_pk_free(&self->pkey);
|
mbedtls_pk_free(&self->pkey);
|
||||||
mbedtls_x509_crt_free(&self->cert);
|
mbedtls_x509_crt_free(&self->cert);
|
||||||
mbedtls_x509_crt_free(&self->cacert);
|
mbedtls_x509_crt_free(&self->cacert);
|
||||||
@ -280,13 +278,9 @@ STATIC mp_uint_t socket_ioctl(mp_obj_t o_in, mp_uint_t request, uintptr_t arg, i
|
|||||||
mbedtls_ssl_config_free(&self->conf);
|
mbedtls_ssl_config_free(&self->conf);
|
||||||
mbedtls_ctr_drbg_free(&self->ctr_drbg);
|
mbedtls_ctr_drbg_free(&self->ctr_drbg);
|
||||||
mbedtls_entropy_free(&self->entropy);
|
mbedtls_entropy_free(&self->entropy);
|
||||||
mp_stream_close(self->sock);
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
default:
|
|
||||||
*errcode = MP_EINVAL;
|
|
||||||
return MP_STREAM_ERROR;
|
|
||||||
}
|
}
|
||||||
|
// Pass all requests down to the underlying socket
|
||||||
|
return mp_get_stream(self->sock)->ioctl(self->sock, request, arg, errcode);
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC const mp_rom_map_elem_t ussl_socket_locals_dict_table[] = {
|
STATIC const mp_rom_map_elem_t ussl_socket_locals_dict_table[] = {
|
||||||
|
Loading…
Reference in New Issue
Block a user