diff options
author | Natanael Copa <ncopa@alpinelinux.org> | 2015-06-19 11:19:36 +0200 |
---|---|---|
committer | Natanael Copa <ncopa@alpinelinux.org> | 2015-06-19 11:19:36 +0200 |
commit | afcbe568a5587f73427c0d30a262b1b79a130738 (patch) | |
tree | 31a9268c9a54d279e3511739b4f90bec3bff2f35 | |
parent | d885a6cb64765a9dff58db7cddd2dd86d9619a84 (diff) | |
download | sircbot-afcbe568a5587f73427c0d30a262b1b79a130738.tar.bz2 sircbot-afcbe568a5587f73427c0d30a262b1b79a130738.tar.xz |
handle irc server disconnects better
-rw-r--r-- | sircbot.c | 28 |
1 files changed, 19 insertions, 9 deletions
@@ -314,6 +314,7 @@ int parse_irc_data(struct sircbot_session *sb, char *buf) static int irc_server_disconnect(struct irc_session *is) { syslog(LOG_ERR, "%s: connection closed", is->server); + printf("%s: connection closed", is->server); close(is->fd); is->fd = -1; return 0; @@ -327,20 +328,29 @@ static int irc_server_cb(struct sircbot_session *sb, struct pollfd *fds, int r; struct irc_session *sess = (struct irc_session *) ctx; - if (fds->revents & POLLHUP) - /* server hang up on us */ - return irc_server_disconnect(sess); - if (fds->revents & POLLERR) { log_err(sess->server); return -1; } - r = read(fds->fd, buf, sizeof(buf)-1); - if (r < 0) - return -1; - buf[r] = '\0'; - parse_irc_data(sb, buf); + if (fds->revents & POLLIN) { + r = read(fds->fd, buf, sizeof(buf)-1); + printf("DEBUG: read %i chars from server\n", r); + if (r < 0) + return -1; + if (r == 0) + return irc_server_disconnect(sess); + buf[r] = '\0'; + if (r) + parse_irc_data(sb, buf); + } + + if (fds->revents & POLLHUP) { + printf("DEBUG: server hangup\n"); + /* server hang up on us */ + return irc_server_disconnect(sess); + } + return 1; } |