Browse Source

[core] isolate fdevent processing

personal/stbuehler/ci-build
Glenn Strauss 3 years ago
parent
commit
41384a3657
  1. 11
      src/fdevent.c
  2. 1
      src/fdevent.h
  3. 10
      src/server.c

11
src/fdevent.c

@ -306,7 +306,8 @@ void fdevent_sched_close(fdevents *ev, int fd, int issock) {
ev->pendclose = fdn;
}
void fdevent_sched_run(server *srv, fdevents *ev) {
static void fdevent_sched_run(fdevents *ev) {
server *srv = ev->srv;
for (fdnode *fdn = ev->pendclose; fdn; ) {
int fd, rc;
fdnode *fdn_tmp;
@ -399,7 +400,13 @@ void fdevent_event_clr(fdevents *ev, int fd, int event) {
}
int fdevent_poll(fdevents *ev, int timeout_ms) {
return ev->poll(ev, timeout_ms);
int n = ev->poll(ev, timeout_ms);
if (n >= 0)
fdevent_sched_run(ev);
else if (errno != EINTR)
log_error_write(ev->srv, __FILE__, __LINE__, "SS",
"fdevent_poll failed: ", strerror(errno));
return n;
}
void fdevent_setfd_cloexec(int fd) {

1
src/fdevent.h

@ -61,7 +61,6 @@ int fdevent_poll(fdevents *ev, int timeout_ms);
void fdevent_register(fdevents *ev, int fd, fdevent_handler handler, void *ctx);
void fdevent_unregister(fdevents *ev, int fd);
void fdevent_sched_close(fdevents *ev, int fd, int issock);
void fdevent_sched_run(struct server *srv, fdevents *ev);
void fdevent_setfd_cloexec(int fd);
void fdevent_clrfd_cloexec(int fd);

10
src/server.c

@ -2003,7 +2003,6 @@ static int server_main_loop (server * const srv) {
time_t last_active_ts = time(NULL);
while (!srv_shutdown) {
int n;
if (handle_sig_hup) {
handle_sig_hup = 0;
@ -2043,13 +2042,8 @@ static int server_main_loop (server * const srv) {
server_process_want_fds(srv);
}
if ((n = fdevent_poll(srv->ev, 1000)) >= 0) {
if (n > 0) last_active_ts = srv->cur_ts;
fdevent_sched_run(srv, srv->ev);
} else if (errno != EINTR) {
log_error_write(srv, __FILE__, __LINE__, "ss",
"fdevent_poll failed:",
strerror(errno));
if (fdevent_poll(srv->ev, 1000) > 0) {
last_active_ts = srv->cur_ts;
}
for (size_t ndx = 0; ndx < joblist->used; ++ndx) {

Loading…
Cancel
Save