+++ /dev/null
-/*
- * 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.
- *
- * ---
- *
- * io_mask.h: Describes an i/o mask
- *
- * Known contributors to this file:
- *
- */
-
-#ifndef _IO_MASK_H_
-#define _IO_MASK_H_
-
-#include <sys/types.h>
-#ifdef _WIN32
-#include <winsock.h>
-#endif
-
-struct io_mask {
- int what;
- int maxfd;
- fd_set *readmask;
- fd_set *user_readmask;
- fd_set *writemask;
- fd_set *user_writemask;
-};
-
-extern struct io_mask *iom_create(int);
-extern void iom_getmask(struct io_mask *, int *, fd_set **, fd_set **);
-extern void iom_set(struct io_mask *, int, int);
-extern void iom_clear(struct io_mask *, int, int);
-extern void iom_zero(struct io_mask *, int);
-
-#endif /* _IO_MASK_H_ */
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 \
+ 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 \
emp_config.obj getstarg.obj getstring.obj \
- inet.obj io.obj io_mask.obj ioqueue.obj mapdist.obj minmax.obj \
+ inet.obj io.obj ioqueue.obj mapdist.obj minmax.obj \
numstr.obj onearg.obj parse.obj plur.obj queue.obj round.obj \
scthash.obj strdup.obj
#include "misc.h"
#include "queue.h"
#include "ioqueue.h"
-#include "io_mask.h"
#include "empio.h"
#include "gen.h" /* getfdtablesize */
extern struct player *player; /* XXX */
-static struct io_mask *iom;
-static int fdmax; /* largest file descriptor seen */
-static fd_set newoutput;
-
struct iop {
int fd;
struct ioqueue *input;
void
io_init(void)
{
- iom = iom_create(IO_READ | IO_WRITE);
- fdmax = 0;
- FD_ZERO(&newoutput);
}
struct iop *
iop->flags = flags;
iop->assoc = assoc;
iop->notify = notify;
- iom_set(iom, flags, fd);
- if (fd > fdmax) fdmax = fd;
return iop;
}
ioq_destroy(iop->input);
if (iop->output != 0)
ioq_destroy(iop->output);
- iom_clear(iom, iop->flags, iop->fd);
- FD_CLR(iop->fd, &newoutput);
#if !defined(_WIN32)
(void)close(iop->fd);
#else
/* Some form of file error occurred... */
iop->flags |= IO_ERROR;
- iom_clear(iom, IO_READ, iop->fd);
return -1;
}
#else
/* Some form of file error occurred... */
iop->flags |= IO_ERROR;
- iom_clear(iom, IO_READ, iop->fd);
return -1;
}
#endif
if (!io_outputwaiting(iop))
return 0;
- /* bit clear */
- FD_CLR(iop->fd, &newoutput);
-
/* If the iop is not write enabled. */
if ((iop->flags & IO_WRITE) == 0)
return -1;
#endif
if (n <= 0) {
- /* If we got no elements, we have no output.... */
- iom_clear(iom, IO_WRITE, iop->fd);
return 0;
}
if (errno == EWOULDBLOCK) {
/* If there are remaining bytes, set the IO as remaining.. */
remain = ioq_qsize(iop->output);
- if (remain > 0)
- iom_set(iom, IO_WRITE, iop->fd);
return remain;
}
iop->flags |= IO_ERROR;
- iom_clear(iom, IO_WRITE, iop->fd);
return -1;
}
#else
if (err == WSAEWOULDBLOCK) {
/* If there are remaining bytes, set the IO as remaining.. */
remain = ioq_qsize(iop->output);
- if (remain > 0)
- iom_set(iom, IO_WRITE, iop->fd);
return remain;
}
iop->flags |= IO_ERROR;
- iom_clear(iom, IO_WRITE, iop->fd);
return -1;
}
#endif
#else
if (cc == 0) {
remain = ioq_qsize(iop->output);
- if (remain > 0)
- iom_set(iom, IO_WRITE, iop->fd);
return remain;
}
#endif /* hpux */
/* Remove the number of written bytes from the queue. */
ioq_dequeue(iop->output, cc);
- /* If the queue has stuff remaining, set it still needing output. */
- remain = ioq_qsize(iop->output);
- if (remain == 0) {
- iom_clear(iom, IO_WRITE, iop->fd);
- } else {
- iom_set(iom, IO_WRITE, iop->fd);
- }
return cc;
}
if ((iop->flags & IO_WRITE) == 0)
return -1;
ioq_append(iop->output, buf, nbytes);
- FD_SET(iop->fd, &newoutput);
len = ioq_qsize(iop->output);
if (len > iop->bufsize) {
if (doWait) {
{
if ((iop->flags & IO_WRITE) == 0)
return -1;
- FD_SET(iop->fd, &newoutput);
return ioq_puts(iop->output, buf);
}
+++ /dev/null
-/*
- * 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.
- *
- * ---
- *
- * iom.c: implements the io mask routines
- *
- * Known contributors to this file:
- *
- */
-
-#include <stdlib.h>
-#include "misc.h"
-#include "empio.h"
-#include "io_mask.h"
-
-struct io_mask *
-iom_create(int what)
-{
- struct io_mask *imp;
-
- imp = (struct io_mask *)malloc(sizeof(*imp));
- if (what & IO_READ) {
- imp->readmask = malloc(sizeof(*imp->readmask));
- FD_ZERO(imp->readmask);
- imp->user_readmask = malloc(sizeof(*imp->user_readmask));
- FD_ZERO(imp->user_readmask);
- } else {
- imp->readmask = 0;
- imp->user_readmask = 0;
- }
- if (what & IO_WRITE) {
- imp->writemask = malloc(sizeof(*imp->writemask));
- FD_ZERO(imp->writemask);
- imp->user_writemask = malloc(sizeof(*imp->user_writemask));
- FD_ZERO(imp->user_writemask);
- } else {
- imp->writemask = 0;
- imp->user_writemask = 0;
- }
- imp->what = what;
- imp->maxfd = 0;
- return imp;
-}
-
-void
-iom_getmask(struct io_mask *mask,
- int *maxfdp, fd_set **readp, fd_set **writep)
-{
- if (mask->what & IO_READ)
- *mask->user_readmask = *mask->readmask;
- if (mask->what & IO_WRITE)
- *mask->user_writemask = *mask->writemask;
- *readp = mask->user_readmask;
- *writep = mask->user_writemask;
- *maxfdp = mask->maxfd;
-}
-
-void
-iom_set(struct io_mask *mask, int what, int fd)
-{
- if ((mask->what & what) == 0)
- return;
- if (what & IO_READ)
- FD_SET(fd, mask->readmask);
- if (what & IO_WRITE)
- FD_SET(fd, mask->writemask);
- if (fd > mask->maxfd)
- mask->maxfd = fd;
-}
-
-void
-iom_clear(struct io_mask *mask, int what, int fd)
-{
- if ((mask->what & what) == 0)
- return;
- if (what & IO_READ)
- FD_CLR(fd, mask->readmask);
- if (what & IO_WRITE)
- FD_CLR(fd, mask->writemask);
-}
-
-void
-iom_zero(struct io_mask *mask, int what)
-{
- if ((mask->what & what) == 0)
- return;
- if (what & IO_READ)
- FD_ZERO(mask->readmask);
- if (what & IO_WRITE)
- FD_ZERO(mask->writemask);
-}
#include "empthread.h"
#include "player.h"
#include "file.h"
-#include "io_mask.h"
#include "empio.h"
#include "power.h"
#include "common.h"