libavformat: use MSG_NOSIGNAL when applicable

If the remote end of a connection oriented socket hangs up, generating
an EPIPE error is preferable over an unhandled SIGPIPE signal.

Signed-off-by: Martin Storsjö <martin@martin.st>
This commit is contained in:
Rémi Denis-Courmont 2014-08-20 23:06:07 +03:00 committed by Martin Storsjö
parent b263f8ffe7
commit 6ee1cb5740
4 changed files with 8 additions and 4 deletions

View File

@ -98,6 +98,10 @@ struct sockaddr_storage {
};
#endif /* !HAVE_STRUCT_SOCKADDR_STORAGE */
#ifndef MSG_NOSIGNAL
#define MSG_NOSIGNAL 0
#endif
#if !HAVE_STRUCT_ADDRINFO
struct addrinfo {
int ai_flags;

View File

@ -143,7 +143,7 @@ static int ff_sctp_send(int s, const void *msg, size_t len,
memcpy(CMSG_DATA(cmsg), sinfo, sizeof(struct sctp_sndrcvinfo));
}
return sendmsg(s, &outmsg, flags);
return sendmsg(s, &outmsg, flags | MSG_NOSIGNAL);
}
typedef struct SCTPContext {
@ -300,7 +300,7 @@ static int sctp_write(URLContext *h, const uint8_t *buf, int size)
abort();
ret = ff_sctp_send(s->fd, buf + 2, size - 2, &info, MSG_EOR);
} else
ret = send(s->fd, buf, size, 0);
ret = send(s->fd, buf, size, MSG_NOSIGNAL);
return ret < 0 ? ff_neterrno() : ret;
}

View File

@ -154,7 +154,7 @@ static int tcp_write(URLContext *h, const uint8_t *buf, int size)
if (ret < 0)
return ret;
}
ret = send(s->fd, buf, size, 0);
ret = send(s->fd, buf, size, MSG_NOSIGNAL);
return ret < 0 ? ff_neterrno() : ret;
}

View File

@ -124,7 +124,7 @@ static int unix_write(URLContext *h, const uint8_t *buf, int size)
if (ret < 0)
return ret;
}
ret = send(s->fd, buf, size, 0);
ret = send(s->fd, buf, size, MSG_NOSIGNAL);
return ret < 0 ? ff_neterrno() : ret;
}