aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--sircbot.c39
1 files changed, 23 insertions, 16 deletions
diff --git a/sircbot.c b/sircbot.c
index 3bd1f61..5a40695 100644
--- a/sircbot.c
+++ b/sircbot.c
@@ -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;
}