X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=src%2Fconnection.c;h=05a9d653dc3bf377128b5eb73bd4017dfba2c2c5;hb=b6ceafe7a5db5802e483795738943f01f1732926;hp=1732b150fcfd499e57f810502266be83f5f10b90;hpb=eb049936ffce049cf6b53de8ca0f39c98a360363;p=meshlink diff --git a/src/connection.c b/src/connection.c index 1732b150..05a9d653 100644 --- a/src/connection.c +++ b/src/connection.c @@ -20,7 +20,6 @@ #include "system.h" #include "list.h" -#include "cipher.h" #include "conf.h" #include "connection.h" #include "list.h" @@ -29,14 +28,14 @@ #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) { +void exit_connections(meshlink_handle_t *mesh) { list_delete_list(mesh->connections); free_connection(mesh->everyone); } @@ -55,7 +54,8 @@ void free_connection(connection_t *c) { buffer_clear(&c->inbuf); buffer_clear(&c->outbuf); - io_del(&c->io); + if(c->io.cb) + abort(); if(c->socket > 0) closesocket(c->socket); @@ -69,10 +69,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); }