X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=src%2Fmeshlink.c;h=4162b36e7c7f569b01be95f675546868ccc16d1c;hb=4216a7e7a1897c0e34ce82e7c2c4cc82070c7b10;hp=f504e5af116e1ec8006c7a46d37b3665dee0a89a;hpb=ea20fcfcded669ce8fbbda3a1f93f354ed254603;p=meshlink diff --git a/src/meshlink.c b/src/meshlink.c index f504e5af..4162b36e 100644 --- a/src/meshlink.c +++ b/src/meshlink.c @@ -1617,10 +1617,12 @@ void meshlink_close(meshlink_handle_t *mesh) { free(mesh->confbase); free(mesh->config_key); ecdsa_free(mesh->private_key); - pthread_mutex_destroy(&(mesh->mesh_mutex)); main_config_unlock(mesh); + pthread_mutex_unlock(&mesh->mesh_mutex); + pthread_mutex_destroy(&mesh->mesh_mutex); + memset(mesh, 0, sizeof(*mesh)); free(mesh); @@ -1716,6 +1718,17 @@ void meshlink_set_log_cb(meshlink_handle_t *mesh, meshlink_log_level_t level, me } } +void meshlink_set_error_cb(struct meshlink_handle *mesh, meshlink_error_cb_t cb) { + if(!mesh) { + meshlink_errno = MESHLINK_EINVAL; + return; + } + + pthread_mutex_lock(&(mesh->mesh_mutex)); + mesh->error_cb = cb; + pthread_mutex_unlock(&(mesh->mesh_mutex)); +} + bool meshlink_send(meshlink_handle_t *mesh, meshlink_node_t *destination, const void *data, size_t len) { meshlink_packethdr_t *hdr; @@ -3522,6 +3535,22 @@ void handle_network_change(meshlink_handle_t *mesh, bool online) { retry(mesh); } +void call_error_cb(meshlink_handle_t *mesh) { + // We should only call the callback function if we are in the background thread. + if(!mesh->error_cb) { + return; + } + + if(!mesh->threadstarted) { + return; + } + + if(mesh->thread == pthread_self()) { + mesh->error_cb(mesh, meshlink_errno); + } +} + + static void __attribute__((constructor)) meshlink_init(void) { crypto_init(); }