2 * connection_list.c - ACPI daemon connection list
4 * Copyright (C) 2008, Ted Felix (www.tedfelix.com)
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #include "connection_list.h"
28 #define max(a, b) (((a)>(b))?(a):(b))
30 /*---------------------------------------------------------------*/
33 #define MAX_CONNECTIONS 20
35 static struct connection connection_list[MAX_CONNECTIONS];
37 static int nconnections = 0;
39 /* fd_set containing all the fd's that come in */
42 /* highest fd that is opened */
43 /* (-2 + 1) causes select() to return immediately */
44 static int highestfd = -2;
46 /*---------------------------------------------------------------*/
47 /* public functions */
50 add_connection(struct connection *p)
54 if (nconnections >= MAX_CONNECTIONS) {
55 printf("add_connection(): Too many connections.\n");
59 if (nconnections == 0)
62 /* add the connection to the connection list */
63 connection_list[nconnections] = *p;
66 /* add to the fd set */
67 FD_SET(p->fd, &allfds);
68 highestfd = max(highestfd, p->fd);
71 /*---------------------------------------------------------------*/
74 find_connection(int fd)
78 /* for each connection */
79 for (i = 0; i < nconnections; ++i) {
80 /* if the file descriptors match, return the connection */
81 if (connection_list[i].fd == fd)
82 return &connection_list[i];
88 /*---------------------------------------------------------------*/
91 get_number_of_connections(void)
96 /*---------------------------------------------------------------*/
101 if (i < 0 || i >= nconnections)
104 return &connection_list[i];
107 /*---------------------------------------------------------------*/
115 /*---------------------------------------------------------------*/