From e75390b7defc688dd3ff5abf11793a78389d52a3 Mon Sep 17 00:00:00 2001 From: Michael Spang Date: Sat, 25 Jul 2009 05:29:05 -0400 Subject: [PATCH] Fix networking bugs --- src/net.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/net.c b/src/net.c index f46e5c1..5bf3be7 100644 --- a/src/net.c +++ b/src/net.c @@ -2,6 +2,7 @@ #include #include #include +#include #include "util.h" #include "net.h" @@ -32,7 +33,7 @@ void free_fqdn(void) { static size_t recv_one_message(int sock, struct sctp_meta *msg_meta, struct strbuf *msg, int *notification) { size_t len = 0; - int flags; + int flags = 0; int bytes; strbuf_reset(msg); @@ -43,8 +44,11 @@ static size_t recv_one_message(int sock, struct sctp_meta *msg_meta, struct strb bytes = sctp_recvmsg(sock, msg->buf + len, strbuf_avail(msg) - len, (sa *)&msg_meta->from, &msg_meta->fromlen, &msg_meta->sinfo, &flags); - if (bytes < 0) + if (bytes < 0) { + if (errno == EAGAIN) + continue; fatalpe("sctp_recvmsg"); + } if (!bytes) break; len += bytes; @@ -60,8 +64,15 @@ static size_t recv_one_message(int sock, struct sctp_meta *msg_meta, struct strb fatalpe("EOF in the middle of a message"); *notification = flags & MSG_NOTIFICATION; - if (*notification) + if (*notification) { notification_dbg(msg->buf); + union sctp_notification *sn = (union sctp_notification *) msg->buf; + switch (sn->sn_header.sn_type) { + case SCTP_SHUTDOWN_EVENT: + fatal("connection shut down"); + break; + } + } strbuf_setlen(msg, len); return len;