X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=src%2Feventl.c;h=ba4ba599272e13c5a24f7e2addca3a0689ea55d7;hb=37ae4386bd764d62ae43c68df1560be55ff813ca;hp=da2f7f901b8c0b549c22ccfdb246205a52352e8f;hpb=cc9efe948e97e8f6f785bdd2e37a17ba0cce672d;p=pazpar2-moved-to-github.git diff --git a/src/eventl.c b/src/eventl.c index da2f7f9..ba4ba59 100644 --- a/src/eventl.c +++ b/src/eventl.c @@ -108,7 +108,7 @@ struct iochan_man_s { struct yaz_poll_fd *fds; }; -iochan_man_t iochan_man_create(int no_threads) +iochan_man_t iochan_man_create(int no_threads, int max_sockets) { iochan_man_t man = xmalloc(sizeof(*man)); man->channel_list = 0; @@ -129,6 +129,10 @@ iochan_man_t iochan_man_create(int no_threads) man->limit_fd = limit_data.rlim_cur - 200; } #endif + if (max_sockets) + man->limit_fd = max_sockets; + yaz_log(YLOG_LOG, "iochan threads %d limit fd %d", no_threads, + man->limit_fd); yaz_mutex_create(&man->iochan_mutex); return man; } @@ -164,21 +168,27 @@ void iochan_man_destroy(iochan_man_t *mp) } } -int iochan_add(iochan_man_t man, IOCHAN chan) +int iochan_add(iochan_man_t man, IOCHAN chan, int slack) { int r = 0, no_fds = 0; IOCHAN p; - chan->man = man; yaz_log(man->log_level, "iochan_add : chan=%p channel list=%p", chan, man->channel_list); 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) + { + if (p->fd >= 0) + no_fds++; + } + if (slack >= 0 && man->limit_fd > 0 && no_fds >= man->limit_fd - slack) + { r = -1; + yaz_log(YLOG_WARN, "max channels %d in use", no_fds); + } else { + chan->man = man; chan->next = man->channel_list; man->channel_list = chan; } @@ -186,6 +196,14 @@ int iochan_add(iochan_man_t man, IOCHAN chan) return r; } +void iochan_destroy(IOCHAN chan) +{ + if (chan->man) + chan->destroyed = 1; + else + iochan_destroy_real(chan); +} + IOCHAN iochan_create(int fd, IOC_CALLBACK cb, int flags, const char *name) { IOCHAN new_iochan;