mirror of
https://github.com/cuberite/libevent.git
synced 2025-09-09 12:28:19 -04:00
use maximum number of fds for epoll_create; from Davide Libenzi
svn:r63
This commit is contained in:
parent
9eb31e5307
commit
b0b72eb05e
32
epoll.c
32
epoll.c
@ -33,6 +33,7 @@
|
|||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
#include <sys/resource.h>
|
||||||
#ifdef HAVE_SYS_TIME_H
|
#ifdef HAVE_SYS_TIME_H
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#else
|
#else
|
||||||
@ -62,7 +63,7 @@ extern struct event_list eventqueue;
|
|||||||
|
|
||||||
extern volatile sig_atomic_t evsignal_caught;
|
extern volatile sig_atomic_t evsignal_caught;
|
||||||
|
|
||||||
/* due to limitations in the epoll interface, we need to keep track of
|
/* due to limitations in the epoll interface, we need to keep track of
|
||||||
* all file descriptors outself.
|
* all file descriptors outself.
|
||||||
*/
|
*/
|
||||||
struct evepoll {
|
struct evepoll {
|
||||||
@ -94,12 +95,13 @@ struct eventop epollops = {
|
|||||||
epoll_dispatch
|
epoll_dispatch
|
||||||
};
|
};
|
||||||
|
|
||||||
#define NEVENT 64
|
#define NEVENT 32000
|
||||||
|
|
||||||
void *
|
void *
|
||||||
epoll_init(void)
|
epoll_init(void)
|
||||||
{
|
{
|
||||||
int epfd;
|
int epfd, nfiles = NEVENT;
|
||||||
|
struct rlimit rl;
|
||||||
|
|
||||||
/* Disable epollueue when this environment variable is set */
|
/* Disable epollueue when this environment variable is set */
|
||||||
if (getenv("EVENT_NOEPOLL"))
|
if (getenv("EVENT_NOEPOLL"))
|
||||||
@ -107,9 +109,13 @@ epoll_init(void)
|
|||||||
|
|
||||||
memset(&epollop, 0, sizeof(epollop));
|
memset(&epollop, 0, sizeof(epollop));
|
||||||
|
|
||||||
|
if (getrlimit(RLIMIT_NOFILE, &rl) == 0 &&
|
||||||
|
rl.rlim_cur != RLIM_INFINITY)
|
||||||
|
nfiles = rl.rlim_cur;
|
||||||
|
|
||||||
/* Initalize the kernel queue */
|
/* Initalize the kernel queue */
|
||||||
|
|
||||||
if ((epfd = epoll_create(NEVENT)) == -1) {
|
if ((epfd = epoll_create(nfiles)) == -1) {
|
||||||
log_error("epoll_create");
|
log_error("epoll_create");
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
@ -117,17 +123,17 @@ epoll_init(void)
|
|||||||
epollop.epfd = epfd;
|
epollop.epfd = epfd;
|
||||||
|
|
||||||
/* Initalize fields */
|
/* Initalize fields */
|
||||||
epollop.events = malloc(NEVENT * sizeof(struct epoll_event));
|
epollop.events = malloc(nfiles * sizeof(struct epoll_event));
|
||||||
if (epollop.events == NULL)
|
if (epollop.events == NULL)
|
||||||
return (NULL);
|
return (NULL);
|
||||||
epollop.nevents = NEVENT;
|
epollop.nevents = nfiles;
|
||||||
|
|
||||||
epollop.fds = calloc(NEVENT, sizeof(struct evepoll));
|
epollop.fds = calloc(nfiles, sizeof(struct evepoll));
|
||||||
if (epollop.fds == NULL) {
|
if (epollop.fds == NULL) {
|
||||||
free(epollop.events);
|
free(epollop.events);
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
epollop.nfds = NEVENT;
|
epollop.nfds = nfiles;
|
||||||
|
|
||||||
evsignal_init(&epollop.evsigmask);
|
evsignal_init(&epollop.evsigmask);
|
||||||
|
|
||||||
@ -143,9 +149,9 @@ epoll_recalc(void *arg, int max)
|
|||||||
struct evepoll *fds;
|
struct evepoll *fds;
|
||||||
int nfds;
|
int nfds;
|
||||||
|
|
||||||
nfds = 2*epollop->nfds;
|
nfds = epollop->nfds;
|
||||||
if (nfds < max)
|
while (nfds < max)
|
||||||
nfds = max;
|
nfds <<= 1;
|
||||||
|
|
||||||
fds = realloc(epollop->fds, nfds * sizeof(struct evepoll));
|
fds = realloc(epollop->fds, nfds * sizeof(struct evepoll));
|
||||||
if (fds == NULL) {
|
if (fds == NULL) {
|
||||||
@ -321,6 +327,6 @@ epoll_del(void *arg, struct event *ev)
|
|||||||
evep->evread = NULL;
|
evep->evread = NULL;
|
||||||
if (needwritedelete)
|
if (needwritedelete)
|
||||||
evep->evwrite = NULL;
|
evep->evwrite = NULL;
|
||||||
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user