int no_threads;
int log_level;
YAZ_MUTEX iochan_mutex;
+ int size_fds;
+ struct yaz_poll_fd *fds;
};
iochan_man_t iochan_man_create(int no_threads) {
man->no_threads = no_threads;
man->log_level = yaz_log_module_level("iochan");
man->iochan_mutex = 0;
+ man->size_fds = 0;
+ man->fds = 0;
yaz_mutex_create(&man->iochan_mutex);
return man;
}
c = iochan_destroy_real(c);
}
yaz_mutex_destroy(&(*mp)->iochan_mutex);
+ xfree((*mp)->fds);
xfree(*mp);
*mp = 0;
}
IOCHAN inv_start;
int res;
static struct timeval to;
-
struct yaz_poll_fd *fds;
int i, no_fds = 0;
int connection_fired = 0;
yaz_mutex_leave(man->iochan_mutex);
inv_start = start;
for (p = start; p; p = p->next)
- if (p->fd >= 0)
- no_fds++;
+ no_fds++;
if (man->sel_fd != -1)
no_fds++;
- fds = (struct yaz_poll_fd *) xmalloc(no_fds * sizeof(*fds));
+ if (no_fds > man->size_fds)
+ {
+ man->size_fds = no_fds * 2;
+ man->fds = xrealloc(man->fds, man->size_fds * sizeof(*man->fds));
+ }
+ fds = man->fds;
i = 0;
if (man->sel_fd != -1)
{
fds[i].fd = man->sel_fd;
- fds[i].input_mask = 0;
- if (p->flags & EVENT_INPUT)
- fds[i].input_mask |= yaz_poll_read;
+ fds[i].input_mask = yaz_poll_read;
+ fds[i].client_data = 0;
i++;
}
- for (p = start; p; p = p->next)
+ for (p = start; p; p = p->next, i++)
{
+ fds[i].client_data = p;
+ fds[i].fd = p->fd;
+ fds[i].input_mask = 0;
if (p->thread_users > 0)
continue;
if (p->max_idle && p->max_idle < to.tv_sec)
to.tv_sec = p->max_idle;
if (p->fd < 0)
continue;
- fds[i].fd = p->fd;
- fds[i].input_mask = 0;
if (p->flags & EVENT_INPUT)
fds[i].input_mask |= yaz_poll_read;
if (p->flags & EVENT_OUTPUT)
fds[i].input_mask |= yaz_poll_write;
if (p->flags & EVENT_EXCEPT)
fds[i].input_mask |= yaz_poll_except;
- i++;
}
yaz_log(man->log_level, "yaz_poll begin nofds=%d", no_fds);
res = yaz_poll(fds, no_fds, to.tv_sec, 0);
no++;
yaz_log(man->log_level, "%d channels", no);
}
- for (p = start; p; p = p->next)
+ for (; i < no_fds; i++)
{
time_t now = time(0);
+ p = fds[i].client_data;
if (p->destroyed)
{
yaz_log(man->log_level,
"eventl: skip destroyed chan=%p name=%s", p,
p->name ? p->name : "");
- if (p->fd >= 0)
- i++;
continue;
}
if (p->thread_users > 0)
yaz_log(man->log_level,
"eventl: skip chan=%p name=%s users=%d", p,
p->name ? p->name : "", p->thread_users);
- if (p->fd >= 0)
- i++;
continue;
}
p->this_event = 0;
-
if (p->max_idle && now - p->last_event > p->max_idle)
{
p->last_event = now;
p->this_event |= EVENT_TIMEOUT;
}
- if (p->fd >= 0)
+ if (fds[i].fd >= 0)
{
- assert(fds[i].fd == p->fd);
if (fds[i].output_mask & yaz_poll_read)
{
p->last_event = now;
p->last_event = now;
p->this_event |= EVENT_EXCEPT;
}
- i++;
}
/* only fire one Z39.50/SRU socket event.. except for timeout */
if (p->this_event) {
nextp = &p->next;
}
yaz_mutex_leave(man->iochan_mutex);
- xfree(fds);
} while (*iochans);
return 0;
}