extmod/modusocket: Add timeout and callback to socket object.

This commit is contained in:
iabdalkader 2022-05-19 08:11:45 +02:00 committed by Damien George
parent 6841fecbb2
commit b9d2f1e844
2 changed files with 6 additions and 4 deletions

View File

@ -86,9 +86,10 @@ typedef struct _mod_network_socket_obj_t {
uint32_t proto : 5;
uint32_t bound : 1;
int32_t fileno : 16;
int32_t timeout;
mp_obj_t callback;
#if MICROPY_PY_USOCKET_EXTENDED_STATE
// Extended socket state for NICs/ports that need it.
int32_t timeout;
void *state;
#endif
} mod_network_socket_obj_t;

View File

@ -71,9 +71,9 @@ STATIC mp_obj_t socket_make_new(const mp_obj_type_t *type, size_t n_args, size_t
}
}
}
#if MICROPY_PY_USOCKET_EXTENDED_STATE
s->timeout = -1;
s->callback = MP_OBJ_NULL;
#if MICROPY_PY_USOCKET_EXTENDED_STATE
s->state = NULL;
#endif
@ -169,8 +169,9 @@ STATIC mp_obj_t socket_accept(mp_obj_t self_in) {
socket2->proto = self->proto;
socket2->bound = false;
socket2->fileno = -1;
#if MICROPY_PY_USOCKET_EXTENDED_STATE
socket2->timeout = -1;
socket2->callback = MP_OBJ_NULL;
#if MICROPY_PY_USOCKET_EXTENDED_STATE
socket2->state = NULL;
#endif