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;
io_init(void)
{
iom = iom_create(IO_READ | IO_WRITE);
- io_list = (struct iop **)calloc(getfdtablesize(), sizeof(*io_list));
+ 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 0;
+ return NULL;
}
flags = flags & (IO_READ | IO_WRITE | IO_NBLOCK | IO_NEWSOCK);
if ((flags & (IO_READ | IO_WRITE)) == 0)
- return 0;
+ return NULL;
iop = (struct iop *)malloc(sizeof(struct iop));
+ if (!iop)
+ return NULL;
iop->fd = fd;
iop->input = 0;
iop->output = 0;
struct iop *
io_iopfromfd(int fd)
{
+ if (fd < 0 || niop < fd)
+ return NULL;
return io_list[fd];
}
int s;
short port;
int val;
- int maxfd;
struct player *np;
int len;
int ns;
exit(1);
}
#endif
- maxfd = getfdtablesize() - 1;
while (1) {
empth_select(s, EMPTH_FD_READ);
len = sizeof(sin);
}
(void)setsockopt(ns, SOL_SOCKET, SO_KEEPALIVE,
(char *)&set, sizeof(set));
- if (ns >= maxfd) {
- logerror("new fd %d, max %d, no fd's left for new user",
- ns, maxfd);
- close(ns);
- continue;
- }
np = player_new(ns, &sin);
if (!np) {
logerror("can't create player for fd %d", ns);