From 68c1c4514426385e025e2e2d55a2da9008b26fa6 Mon Sep 17 00:00:00 2001 From: Natanael Copa Date: Wed, 3 Mar 2010 14:36:18 +0100 Subject: also listen to POLLHUP and POLLERR --- sircbot.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/sircbot.c b/sircbot.c index 4321638..cbfe51c 100644 --- a/sircbot.c +++ b/sircbot.c @@ -128,6 +128,14 @@ int init_fifo(struct sircbot_channel *chan) return 0; } +int close_fifo(struct sircbot_channel *chan) +{ + close(chan->fd); + chan->fd = -1; + unlink(chan->fifo); +} + + int find_channel(struct sircbot_channel *chan, int numchan, char *name) { int i; @@ -245,12 +253,12 @@ static void irc_reset_pollfds(struct irc_session *sess, struct pollfd *fds, int i; /* first pollfd struc is the irc session */ fds[0].fd = sess->fd; - fds[0].events = POLLIN; + fds[0].events = POLLIN | POLLHUP | POLLERR; fds[0].revents = 0; /* rest is channel fifos */ for (i = 1; i < numchan + 1; i++) { fds[i].fd = chan[i-1].fd; - fds[i].events = POLLIN; + fds[i].events = POLLIN | POLLHUP | POLLERR; fds[i].revents = 0; } } @@ -289,6 +297,7 @@ static int irc_loop(struct irc_session *sess, struct sircbot_channel *chan, tv.tv_sec = 1; tv.tv_nsec = 0; while (!sigterm) { + irc_reset_pollfds(sess, fds, chan, numchan); r = ppoll(fds, numchan+1, &tv, &sigmask); // r = poll(fds, numchan+1, 120000); @@ -312,7 +321,7 @@ static int irc_loop(struct irc_session *sess, struct sircbot_channel *chan, send_fifo_queue(sess, &chan[i-1], now) < 0) goto ret_err; - if (!(fds[i].revents & POLLIN)) + if (!(fds[i].revents)) continue; /* no data available for read */ printf("DEBUG: data available from fds[%i]\n", i); @@ -431,11 +440,8 @@ int main(int argc, char *argv[]) irc_loop(s, chan, argc); irc_close(s, "bye"); /* reset fifos */ - for (i = 0; i < argc; i++) { - close(chan[i].fd); - chan[i].fd = -1; - unlink(chan[i].fifo); - } + for (i = 0; i < argc; i++) + close_fifo(&chan[i]); } unlink(pidfile); return 0; -- cgit v1.2.3