diff options
author | Thijs <thijsvermeir@telenet.be> | 2006-10-28 17:16:18 +0000 |
---|---|---|
committer | Guillaume Poirier <gpoirier@mplayerhq.hu> | 2006-10-28 17:16:18 +0000 |
commit | 34ecc3975fa4f7d27deafd7eec636dc1fa828a09 (patch) | |
tree | dda0c1ea35ce1558cc97ed065822bef0100aa442 /libavformat/udp.c | |
parent | 973cbc2a28d78761654efdd1cd54e13a8eee806c (diff) | |
download | ffmpeg-34ecc3975fa4f7d27deafd7eec636dc1fa828a09.tar.gz |
Make it possible to reuse UDP socket (optional, disabled by default)
Patch by Thijs % thijsvermeir A telenet P be %
Original thread:
Subject: Re: [Ffmpeg-devel] [PATCH proposal] Reuse UDP socket v2
Date: October 28, 2006 11:09:00 AM CEDT
Originally committed as revision 6825 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavformat/udp.c')
-rw-r--r-- | libavformat/udp.c | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/libavformat/udp.c b/libavformat/udp.c index 861da00e5c..96fa4e152c 100644 --- a/libavformat/udp.c +++ b/libavformat/udp.c @@ -40,6 +40,7 @@ typedef struct { int ttl; int is_multicast; int local_port; + int reuse_socket; #ifndef CONFIG_IPV6 struct ip_mreq mreq; struct sockaddr_in dest_addr; @@ -236,6 +237,7 @@ static int udp_ipv6_set_local(URLContext *h) { * 'ttl=n' : set the ttl value (for multicast only) * 'localport=n' : set the local port * 'pkt_size=n' : set max packet size + * 'reuse=1' : enable reusing the socket * * @param s1 media file context * @param uri of the remote server @@ -311,9 +313,11 @@ static int udp_open(URLContext *h, const char *uri, int flags) s->ttl = 16; s->is_multicast = 0; s->local_port = 0; + s->reuse_socket = 0; p = strchr(uri, '?'); if (p) { s->is_multicast = find_info_tag(buf, sizeof(buf), "multicast", p); + s->reuse_socket = find_info_tag(buf, sizeof(buf), "reuse", p); if (find_info_tag(buf, sizeof(buf), "ttl", p)) { s->ttl = strtol(buf, NULL, 10); } @@ -351,6 +355,10 @@ static int udp_open(URLContext *h, const char *uri, int flags) my_addr.sin_port = htons(s->local_port); } + if (s->reuse_socket) + 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 (bind(udp_fd,(struct sockaddr *)&my_addr, sizeof(my_addr)) < 0) goto fail; |