[PATCH] Default socket reuse when multicasting.
David Fries
David.D.Fries
Thu Jul 1 19:33:43 CEST 2010
Follow the requested reuse option, unless it's multicast in which
case enable reuse unless explicitely disabled. The comment in
udp_set_remote_url lists reuse=1 to enable reuse, which implies
reuse=0 would disable it, modifying to match.
---
libavformat/udp.c | 13 +++++++++++--
1 files changed, 11 insertions(+), 2 deletions(-)
diff --git a/libavformat/udp.c b/libavformat/udp.c
index 70d0e2b..711e693 100644
--- a/libavformat/udp.c
+++ b/libavformat/udp.c
@@ -348,6 +348,7 @@ static int udp_open(URLContext *h, const char *uri, int flags)
struct sockaddr_storage my_addr;
#endif
int len;
+ int reuse_specified = 0;
h->is_streamed = 1;
h->max_packet_size = 1472;
@@ -367,7 +368,10 @@ static int udp_open(URLContext *h, const char *uri, int flags)
p = strchr(uri, '?');
if (p) {
- s->reuse_socket = find_info_tag(buf, sizeof(buf), "reuse", p);
+ if (find_info_tag(buf, sizeof(buf), "reuse", p)) {
+ s->reuse_socket = strtol(buf, NULL, 10);
+ reuse_specified = 1;
+ }
if (find_info_tag(buf, sizeof(buf), "ttl", p)) {
s->ttl = strtol(buf, NULL, 10);
}
@@ -400,9 +404,14 @@ static int udp_open(URLContext *h, const char *uri, int flags)
if (udp_fd < 0)
goto fail;
- if (s->reuse_socket)
+ /* Follow the requested reuse option, unless it's multicast in which
+ * case enable reuse unless explicitely disabled.
+ */
+ if (s->reuse_socket || (s->is_multicast && !reuse_specified)) {
+ s->reuse_socket = 1;
if (setsockopt (udp_fd, SOL_SOCKET, SO_REUSEADDR, &(s->reuse_socket), sizeof(s->reuse_socket)) != 0)
goto fail;
+ }
/* the bind is needed to give a port to the socket now */
/* if multicast, try the multicast address bind first */
--
1.7.0
More information about the ffmpeg-devel
mailing list