diff options
author | Natanael Copa <ncopa@alpinelinux.org> | 2015-06-19 11:30:04 +0200 |
---|---|---|
committer | Natanael Copa <ncopa@alpinelinux.org> | 2015-06-19 11:30:04 +0200 |
commit | 6183dc8923888d1873afcfad7c2b28e227299d3d (patch) | |
tree | 34f9a88c94492778affb1b1fd4c4231fec6794b0 | |
parent | afcbe568a5587f73427c0d30a262b1b79a130738 (diff) | |
download | sircbot-6183dc8923888d1873afcfad7c2b28e227299d3d.tar.bz2 sircbot-6183dc8923888d1873afcfad7c2b28e227299d3d.tar.xz |
dont close unix socket til after message is read
we need check POLLIN before POLLHUP so we dont close the connection
before we got the message.
-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; } |