extmod/modnetwork: Add deinit function to NIC protocol.

This is usually called on soft-reboot, a NIC can implement this to do any
necessary cleaning up (such as invalidating root pointers).

Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
This commit is contained in:
iabdalkader 2023-11-02 09:10:38 +01:00 committed by Damien George
parent d30d5c99af
commit 50f31cc902
2 changed files with 10 additions and 0 deletions

View File

@ -65,6 +65,15 @@ void mod_network_init(void) {
}
void mod_network_deinit(void) {
#if !MICROPY_PY_LWIP
for (mp_uint_t i = 0; i < MP_STATE_PORT(mod_network_nic_list).len; i++) {
mp_obj_t nic = MP_STATE_PORT(mod_network_nic_list).items[i];
const mod_network_nic_protocol_t *nic_protocol = MP_OBJ_TYPE_GET_SLOT(mp_obj_get_type(nic), protocol);
if (nic_protocol->deinit) {
nic_protocol->deinit();
}
}
#endif
}
void mod_network_register_nic(mp_obj_t nic) {

View File

@ -80,6 +80,7 @@ struct _mod_network_socket_obj_t;
typedef struct _mod_network_nic_protocol_t {
// API for non-socket operations
int (*gethostbyname)(mp_obj_t nic, const char *name, mp_uint_t len, uint8_t *ip_out);
void (*deinit)(void);
// API for socket operations; return -1 on error
int (*socket)(struct _mod_network_socket_obj_t *socket, int *_errno);