X-Git-Url: http://lists.indexdata.dk/cgi-bin?a=blobdiff_plain;f=src%2Feventl.c;h=da2f7f901b8c0b549c22ccfdb246205a52352e8f;hb=cc9efe948e97e8f6f785bdd2e37a17ba0cce672d;hp=40dfeb472bc556afd0524be1eeff688520450e92;hpb=c4a0e7bd9ac4994ad56c637945c55aeb8bfe2c9c;p=pazpar2-moved-to-github.git diff --git a/src/eventl.c b/src/eventl.c index 40dfeb4..da2f7f9 100644 --- a/src/eventl.c +++ b/src/eventl.c @@ -50,6 +50,7 @@ #include #include #include +#include #include "eventl.h" #include "sel_thread.h" @@ -103,6 +104,7 @@ struct iochan_man_s { int log_level; YAZ_MUTEX iochan_mutex; int size_fds; + int limit_fd; struct yaz_poll_fd *fds; }; @@ -117,6 +119,16 @@ iochan_man_t iochan_man_create(int no_threads) man->iochan_mutex = 0; man->size_fds = 0; man->fds = 0; + man->limit_fd = 0; +#if HAVE_GETRLIMIT + { + struct rlimit limit_data; + getrlimit(RLIMIT_NOFILE, &limit_data); + yaz_log(YLOG_LOG, "getrlimit NOFILE cur=%ld max=%ld", + (long) limit_data.rlim_cur, (long) limit_data.rlim_max); + man->limit_fd = limit_data.rlim_cur - 200; + } +#endif yaz_mutex_create(&man->iochan_mutex); return man; } @@ -152,15 +164,26 @@ void iochan_man_destroy(iochan_man_t *mp) } } -void iochan_add(iochan_man_t man, IOCHAN chan) +int iochan_add(iochan_man_t man, IOCHAN chan) { + int r = 0, no_fds = 0; + IOCHAN p; chan->man = man; - yaz_mutex_enter(man->iochan_mutex); + yaz_log(man->log_level, "iochan_add : chan=%p channel list=%p", chan, man->channel_list); - chan->next = man->channel_list; - man->channel_list = chan; + yaz_mutex_enter(man->iochan_mutex); + for (p = man->channel_list; p; p = p->next) + no_fds++; + if (man->limit_fd > 0 && no_fds >= man->limit_fd) + r = -1; + else + { + chan->next = man->channel_list; + man->channel_list = chan; + } yaz_mutex_leave(man->iochan_mutex); + return r; } IOCHAN iochan_create(int fd, IOC_CALLBACK cb, int flags, const char *name)