Fix networking bugs

This commit is contained in:
Michael Spang 2009-07-25 05:29:05 -04:00
parent 60e272e8c6
commit e75390b7de
1 changed files with 14 additions and 3 deletions

View File

@ -2,6 +2,7 @@
#include <sys/utsname.h> #include <sys/utsname.h>
#include <unistd.h> #include <unistd.h>
#include <netdb.h> #include <netdb.h>
#include <errno.h>
#include "util.h" #include "util.h"
#include "net.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) { static size_t recv_one_message(int sock, struct sctp_meta *msg_meta, struct strbuf *msg, int *notification) {
size_t len = 0; size_t len = 0;
int flags; int flags = 0;
int bytes; int bytes;
strbuf_reset(msg); 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, bytes = sctp_recvmsg(sock, msg->buf + len, strbuf_avail(msg) - len,
(sa *)&msg_meta->from, &msg_meta->fromlen, &msg_meta->sinfo, &flags); (sa *)&msg_meta->from, &msg_meta->fromlen, &msg_meta->sinfo, &flags);
if (bytes < 0) if (bytes < 0) {
if (errno == EAGAIN)
continue;
fatalpe("sctp_recvmsg"); fatalpe("sctp_recvmsg");
}
if (!bytes) if (!bytes)
break; break;
len += bytes; 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"); fatalpe("EOF in the middle of a message");
*notification = flags & MSG_NOTIFICATION; *notification = flags & MSG_NOTIFICATION;
if (*notification) if (*notification) {
notification_dbg(msg->buf); 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); strbuf_setlen(msg, len);
return len; return len;