From 875d72a00f01f052f04e1ccf3a35fb3c27586770 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Fri, 6 Feb 2004 12:35:51 +0000 Subject: [PATCH] Garbage collection to side-step sparse file descriptor problem. (io_select, io_flush, io_iopfromfd): Unused, remove. (io_open): Allow more than one open for the same file descriptor. The check is the last remaining use of io_list[], and it's unimportant. (io_list, niop, io_init): io_list[] no longer serves any purpose, remove. Sparse allocation of file descriptors (deplorable misfeature of Winsock, at least some versions) is no longer a problem. (getfdtablesize): Unused, remove. Was broken for Windows anyway. --- include/empio.h | 3 -- include/prototypes.h | 1 - src/lib/gen/Makefile | 4 +-- src/lib/gen/dtable.c | 49 ------------------------------ src/lib/gen/io.c | 72 +------------------------------------------- 5 files changed, 3 insertions(+), 126 deletions(-) delete mode 100644 src/lib/gen/dtable.c diff --git a/include/empio.h b/include/empio.h index 3858102bc..ac7ea4df1 100644 --- a/include/empio.h +++ b/include/empio.h @@ -59,8 +59,6 @@ extern int io_input(struct iop *, int); extern int io_inputwaiting(struct iop *); extern int io_outputwaiting(struct iop *); extern int io_output(struct iop *, int); -extern int io_select(struct timeval *); -extern void io_flush(int); extern int io_peek(struct iop *, s_char *, int); extern int io_read(struct iop *, s_char *, int); extern int io_write(struct iop *, s_char *, int, int); @@ -72,6 +70,5 @@ extern int io_conn(struct iop *); extern int io_error(struct iop *); extern int io_eof(struct iop *); extern int io_fileno(struct iop *); -extern struct iop *io_iopfromfd(int); #endif /* _EMPIO_H_ */ diff --git a/include/prototypes.h b/include/prototypes.h index baa069ca8..f282a0416 100644 --- a/include/prototypes.h +++ b/include/prototypes.h @@ -412,7 +412,6 @@ extern int roll(int); extern int roundavg(double); extern int chance(double); extern void disassoc(void); -extern int getfdtablesize(void); extern s_char *getstarg(s_char *, s_char *, s_char *); extern s_char *getstring(s_char *, s_char *); #if !defined(_WIN32) diff --git a/src/lib/gen/Makefile b/src/lib/gen/Makefile index c0ee62e3b..b5fbe4134 100644 --- a/src/lib/gen/Makefile +++ b/src/lib/gen/Makefile @@ -35,13 +35,13 @@ include ../../make.defs LIB = $(SRCDIR)/lib/libgen.a NTLIB = $(SRCDIR)\lib\libgen.lib -OBJS = atoip.o chance.o copy.o disassoc.o dtable.o \ +OBJS = atoip.o chance.o copy.o disassoc.o \ emp_config.o getstarg.o getstring.o inet.o io.o \ io_mask.o ioqueue.o mapdist.o minmax.o numstr.o onearg.o \ parse.o plur.o queue.o round.o scthash.o \ strdup.o -NTOBJS = atoip.obj chance.obj copy.obj disassoc.obj dtable.obj \ +NTOBJS = atoip.obj chance.obj copy.obj disassoc.obj \ emp_config.obj getstarg.obj getstring.obj \ inet.obj io.obj io_mask.obj ioqueue.obj mapdist.obj minmax.obj \ numstr.obj onearg.obj parse.obj plur.obj queue.obj round.obj \ diff --git a/src/lib/gen/dtable.c b/src/lib/gen/dtable.c deleted file mode 100644 index 35357e48a..000000000 --- a/src/lib/gen/dtable.c +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Empire - A multi-player, client/server Internet based war game. - * Copyright (C) 1986-2000, Dave Pare, Jeff Bailey, Thomas Ruschak, - * Ken Stevens, Steve McClure - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * --- - * - * See the "LEGAL", "LICENSE", "CREDITS" and "README" files for all the - * related information and legal notices. It is expected that any future - * projects/authors will amend these files as needed. - * - * --- - * - * dtable.c: Machine-dependant descriptor table management - * - * Known contributors to this file: - * Doug Hay, 1998 - */ - -#if !defined(_WIN32) -#include -#endif -#include "gen.h" - -int -getfdtablesize(void) -{ -#if defined(_WIN32) - return (_NFILE); -#elif defined(hpux) - return (int)sysconf(_SC_OPEN_MAX); -#else - return getdtablesize(); -#endif -} diff --git a/src/lib/gen/io.c b/src/lib/gen/io.c index 10e55ed31..ac9aacdda 100644 --- a/src/lib/gen/io.c +++ b/src/lib/gen/io.c @@ -66,8 +66,6 @@ extern struct player *player; /* XXX */ -static struct iop **io_list; -static int niop; static struct io_mask *iom; static int fdmax; /* largest file descriptor seen */ static fd_set newoutput; @@ -86,24 +84,16 @@ void io_init(void) { iom = iom_create(IO_READ | IO_WRITE); - niop = getfdtablesize(); - io_list = (struct iop **)calloc(niop, sizeof(*io_list)); fdmax = 0; FD_ZERO(&newoutput); } struct iop * -io_open(int fd, int flags, int bufsize, int (*notify)(void), +io_open(int fd, int flags, int bufsize, int (*notify) (void), s_char *assoc) { struct iop *iop; - if (fd < 0 || niop < fd) - return NULL; - if (io_list[fd] != 0) { - /* already exists */ - return NULL; - } flags = flags & (IO_READ | IO_WRITE | IO_NBLOCK | IO_NEWSOCK); if ((flags & (IO_READ | IO_WRITE)) == 0) return NULL; @@ -124,7 +114,6 @@ io_open(int fd, int flags, int bufsize, int (*notify)(void), iop->flags = flags; iop->assoc = assoc; iop->notify = notify; - io_list[fd] = iop; iom_set(iom, flags, fd); if (fd > fdmax) fdmax = fd; return iop; @@ -140,7 +129,6 @@ io_close(struct iop *iop) ioq_destroy(iop->output); iom_clear(iom, iop->flags, iop->fd); FD_CLR(iop->fd, &newoutput); - io_list[iop->fd] = 0; #if !defined(_WIN32) (void)close(iop->fd); #else @@ -337,56 +325,6 @@ io_output(struct iop *iop, int waitforoutput) return cc; } -int -io_select(struct timeval *tv) -{ - fd_set *readmask; - fd_set *writemask; - int n; - int maxfd; - int fd; - struct iop *iop; - - iom_getmask(iom, &maxfd, &readmask, &writemask); - n = select(maxfd + 1, readmask, writemask, NULL, tv); - if (n <= 0) { - if (errno == EINTR) - return 0; - return -1; - } - for (fd = 0; fd <= maxfd; ++fd) { - if (!FD_ISSET(fd, readmask)) continue; - iop = io_list[fd]; - if ((iop->flags & IO_NEWSOCK) == 0) - (void)io_input(iop, IO_NOWAIT); - if (iop->notify != 0) - iop->notify(iop, IO_READ, iop->assoc); - FD_CLR(fd, readmask); - } - for (fd = 0; fd <= maxfd; ++fd) { - if (!FD_ISSET(fd, writemask)) continue; - iop = io_list[fd]; - if (io_output(iop, IO_NOWAIT) < 0 && iop->notify != 0) - iop->notify(iop, IO_WRITE, iop->assoc); - FD_CLR(fd, writemask); - } - return n; -} - -void -io_flush(int doWait) -{ - int fd; - struct iop *iop; - - for (fd = 0; fd <= fdmax; ++fd) { - if (!FD_ISSET(fd, &newoutput)) continue; - iop = io_list[fd]; - if (io_output(iop, doWait) < 0 && iop->notify != 0) - iop->notify(iop, IO_WRITE, iop->assoc); - } -} - int io_peek(struct iop *iop, s_char *buf, int nbytes) { @@ -524,11 +462,3 @@ io_fileno(struct iop *iop) { return iop->fd; } - -struct iop * -io_iopfromfd(int fd) -{ - if (fd < 0 || niop < fd) - return NULL; - return io_list[fd]; -} -- 2.43.0