示例#1
0
文件: client.c 项目: AlexanderS/pen
void expand_clienttable(int size)
{
	if (size <= clients_max) return;	/* nothing to do */
	clients = pen_realloc(clients, size*sizeof *clients);
	memset(&clients[clients_max], 0, (size-clients_max)*sizeof clients[0]);
	clients_max = size;
}
示例#2
0
文件: server.c 项目: AlexanderS/pen
/* we want size server slots plus two for abuse and emergency */
void expand_servertable(int size)
{
	static server *server_storage = NULL;
	static int real_size = 0;
	int new_size = size+2;	/* for emergency and abuse servers */
	if (new_size <= real_size) return;	/* nothing to expand here */
	server_storage = pen_realloc(server_storage, new_size*sizeof *server_storage);
	memset(&server_storage[real_size], 0, (new_size-real_size)*sizeof server_storage[0]);
	servers = &server_storage[2];	/* making server[0] the first regular server */
	real_size = new_size;
	if (size > nservers) nservers = size;
}
static void poll_event_ctl(int fd, int events)
{
    int pollevents = 0;
    DEBUG(2, "poll_event_ctl(fd=%d, events=%d)", fd, events);
    if (fd >= poll_nfds_max) {
        int i, new_max = fd+10000;
        DEBUG(2, "expanding poll_ufds to %d entries", new_max);
        poll_ufds = pen_realloc(poll_ufds, new_max * sizeof *poll_ufds);
        for (i = poll_nfds_max; i < new_max; i++) {
            poll_ufds[i].fd = -1;
            poll_ufds[i].events = 0;
        }
        poll_nfds_max = new_max;
    }
    if (events & EVENT_READ) pollevents |= POLLIN;
    if (events & EVENT_WRITE) pollevents |= POLLOUT;
    poll_ufds[fd].fd = fd;
    poll_ufds[fd].events = pollevents;
    if (fd >= poll_nfds) poll_nfds = fd+1;
}