summaryrefslogtreecommitdiff
path: root/libavformat/network.c
diff options
context:
space:
mode:
authorRémi Denis-Courmont <remi@remlab.net>2013-08-08 22:26:42 +0300
committerMartin Storsjö <martin@martin.st>2013-08-09 11:26:50 +0300
commit9d5ec50ead97e088d77317e77b18cef06cb3d053 (patch)
tree7e5fc7b137bd4afcc4a221eb0d426e0e7ceaf755 /libavformat/network.c
parentfa09e76010b7db5ae0c7af9b7412096359ecd8c8 (diff)
ff_socket: put out-of-line and fallback to fcntl() for close-on-exec
This supports non-Linux systems (SOCK_CLOEXEC is non-standard) and older Linux kernels to the extent possible. Signed-off-by: Martin Storsjö <martin@martin.st>
Diffstat (limited to 'libavformat/network.c')
-rw-r--r--libavformat/network.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/libavformat/network.c b/libavformat/network.c
index 810a907212..6d308ebd01 100644
--- a/libavformat/network.c
+++ b/libavformat/network.c
@@ -18,6 +18,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#include <fcntl.h>
#include "network.h"
#include "url.h"
#include "libavcodec/internal.h"
@@ -210,6 +211,24 @@ static int ff_poll_interrupt(struct pollfd *p, nfds_t nfds, int timeout,
return ret;
}
+int ff_socket(int af, int type, int proto)
+{
+ int fd;
+
+#ifdef SOCK_CLOEXEC
+ fd = socket(af, type | SOCK_CLOEXEC, proto);
+ if (fd == -1 && errno == EINVAL)
+#endif
+ {
+ fd = socket(af, type, proto);
+#if HAVE_FCNTL
+ if (fd != -1)
+ fcntl(fd, F_SETFD, FD_CLOEXEC);
+#endif
+ }
+ return fd;
+}
+
int ff_listen_bind(int fd, const struct sockaddr *addr,
socklen_t addrlen, int timeout, URLContext *h)
{