X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=src%2Fconnection.c;h=cbe7a9d610277e0f9c1ef57910ced33f7b9a956c;hb=5dec7459d9920c930bdfb3ac0f2a3740a6247ec0;hp=0a7662dbafd4b8c1bcf952da84d32eac96494ddc;hpb=93f89bcae11e8d250831896bc5694ee8bd2ad22b;p=meshlink diff --git a/src/connection.c b/src/connection.c index 0a7662db..cbe7a9d6 100644 --- a/src/connection.c +++ b/src/connection.c @@ -28,16 +28,21 @@ #include "utils.h" #include "xalloc.h" -void init_connections(void) { +void init_connections(meshlink_handle_t *mesh) { mesh->connections = list_alloc((list_action_t) free_connection); mesh->everyone = new_connection(); mesh->everyone->name = xstrdup("mesh->everyone"); mesh->everyone->hostname = xstrdup("BROADCAST"); } -void exit_connections(void) { - list_delete_list(mesh->connections); +void exit_connections(meshlink_handle_t *mesh) { + if(mesh->connections) + list_delete_list(mesh->connections); + free_connection(mesh->everyone); + + mesh->connections = NULL; + mesh->everyone = NULL; } connection_t *new_connection(void) { @@ -54,7 +59,8 @@ void free_connection(connection_t *c) { buffer_clear(&c->inbuf); buffer_clear(&c->outbuf); - io_del(&mesh->loop, &c->io); + if(c->io.cb) + abort(); if(c->socket > 0) closesocket(c->socket); @@ -68,10 +74,12 @@ void free_connection(connection_t *c) { free(c); } -void connection_add(connection_t *c) { +void connection_add(meshlink_handle_t *mesh, connection_t *c) { + c->mesh = mesh; list_insert_tail(mesh->connections, c); } -void connection_del(connection_t *c) { +void connection_del(meshlink_handle_t *mesh, connection_t *c) { + io_del(&mesh->loop, &c->io); list_delete(mesh->connections, c); }