X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=src%2Fconnection.c;h=fd95ce922a3d109d1b1278759112a7efb201a43c;hb=e6fd39f4c772aa43c900d19c6971ad153085fc43;hp=9cc64914cd4ba217a85d824f9ff378e5f41884b1;hpb=9d23fe58052b3ef971305699a00ea6dbd1111744;p=meshlink-tiny diff --git a/src/connection.c b/src/connection.c index 9cc6491..fd95ce9 100644 --- a/src/connection.c +++ b/src/connection.c @@ -29,25 +29,16 @@ #include "xalloc.h" void init_connections(meshlink_handle_t *mesh) { - assert(!mesh->connections); - assert(!mesh->everyone); - - mesh->connections = list_alloc((list_action_t) free_connection); - mesh->everyone = new_connection(); - mesh->everyone->name = xstrdup("mesh->everyone"); + assert(!mesh->connection); + mesh->connection = NULL; } void exit_connections(meshlink_handle_t *mesh) { - if(mesh->connections) { - list_delete_list(mesh->connections); - } - - if(mesh->everyone) { - free_connection(mesh->everyone); + if(mesh->connection) { + free_connection(mesh->connection); } - mesh->connections = NULL; - mesh->everyone = NULL; + mesh->connection = NULL; } connection_t *new_connection(void) { @@ -78,14 +69,17 @@ void free_connection(connection_t *c) { void connection_add(meshlink_handle_t *mesh, connection_t *c) { assert(c); + assert(!mesh->connection); c->mesh = mesh; - list_insert_tail(mesh->connections, c); + mesh->connection = c; } void connection_del(meshlink_handle_t *mesh, connection_t *c) { assert(c); + assert(mesh->connection == c); io_del(&mesh->loop, &c->io); - list_delete(mesh->connections, c); + free(mesh->connection); + mesh->connection = NULL; }