aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNatanael Copa <ncopa@alpinelinux.org>2015-06-19 11:19:36 +0200
committerNatanael Copa <ncopa@alpinelinux.org>2015-06-19 11:19:36 +0200
commitafcbe568a5587f73427c0d30a262b1b79a130738 (patch)
tree31a9268c9a54d279e3511739b4f90bec3bff2f35
parentd885a6cb64765a9dff58db7cddd2dd86d9619a84 (diff)
downloadsircbot-afcbe568a5587f73427c0d30a262b1b79a130738.tar.bz2
sircbot-afcbe568a5587f73427c0d30a262b1b79a130738.tar.xz
handle irc server disconnects better
-rw-r--r--sircbot.c28
1 files changed, 19 insertions, 9 deletions
diff --git a/sircbot.c b/sircbot.c
index 13531ba..3bd1f61 100644
--- a/sircbot.c
+++ b/sircbot.c
@@ -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;
}