2 connection.c -- connection list management
3 Copyright (C) 2000-2013 Guus Sliepen <guus@meshlink.io>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 #include "connection.h"
27 #include "meshlink_internal.h"
31 void init_connections(meshlink_handle_t *mesh) {
32 assert(!mesh->connection);
33 mesh->connection = NULL;
36 void exit_connections(meshlink_handle_t *mesh) {
37 if(mesh->connection) {
38 free_connection(mesh->connection);
41 mesh->connection = NULL;
44 connection_t *new_connection(void) {
45 return xzalloc(sizeof(connection_t));
48 void free_connection(connection_t *c) {
51 sptps_stop(&c->sptps);
54 buffer_clear(&c->inbuf);
55 buffer_clear(&c->outbuf);
62 closesocket(c->socket);
70 void connection_add(meshlink_handle_t *mesh, connection_t *c) {
72 assert(!mesh->connection);
78 void connection_del(meshlink_handle_t *mesh, connection_t *c) {
80 assert(mesh->connection == c);
82 io_del(&mesh->loop, &c->io);
83 free(mesh->connection);
84 mesh->connection = NULL;