diff options
-rw-r--r-- | sircbot.c | 39 |
1 files changed, 23 insertions, 16 deletions
@@ -424,26 +424,33 @@ static int channel_conn_cb(struct sircbot_session *sb, struct pollfd *fds, char buf[4096]; char *p, *n; struct sircbot_channel *chan = ctx; - if (fds->revents & (POLLHUP | POLLERR | POLLNVAL)) + + if (fds->revents & (POLLERR | POLLNVAL)) return channel_del_connection(chan, fds->fd); - if (!(fds->revents & POLLIN)) - return 1; + if (fds->revents & POLLIN) { + r = read(fds->fd, buf, sizeof(buf)-1); + if (r < 0) { + log_err(chan->socket_path); + return -1; + } - r = read(fds->fd, buf, sizeof(buf)-1); - if (r < 0) { - log_err(chan->socket_path); - return -1; - } - buf[r] = '\0'; - p = buf; - while ((n = strchr(p, '\n')) != NULL) { - *n = '\0'; - tq_stringlist_add(&chan->indata_head, p); - p = n + 1; + /* eof */ + if (r == 0) + return channel_del_connection(chan, fds->fd); + + buf[r] = '\0'; + p = buf; + while ((n = strchr(p, '\n')) != NULL) { + *n = '\0'; + tq_stringlist_add(&chan->indata_head, p); + p = n + 1; + } + if (*p) + tq_stringlist_add(&chan->indata_head, p); } - if (*p) - tq_stringlist_add(&chan->indata_head, p); + if (fds->revents & POLLHUP) + return channel_del_connection(chan, fds->fd); return 1; } |