* commit '9d5ec50ead97e088d77317e77b18cef06cb3d053':
ff_socket: put out-of-line and fallback to fcntl() for close-on-exec
Conflicts:
libavformat/network.c
Merged-by: Michael Niedermayer <michaelni@gmx.at>
... | ... |
@@ -18,10 +18,11 @@ |
18 | 18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
19 | 19 |
*/ |
20 | 20 |
|
21 |
-#include "libavutil/avutil.h" |
|
21 |
+#include <fcntl.h> |
|
22 | 22 |
#include "network.h" |
23 | 23 |
#include "url.h" |
24 | 24 |
#include "libavcodec/internal.h" |
25 |
+#include "libavutil/avutil.h" |
|
25 | 26 |
#include "libavutil/mem.h" |
26 | 27 |
#include "url.h" |
27 | 28 |
#include "libavutil/time.h" |
... | ... |
@@ -235,6 +236,24 @@ static int ff_poll_interrupt(struct pollfd *p, nfds_t nfds, int timeout, |
235 | 235 |
return ret; |
236 | 236 |
} |
237 | 237 |
|
238 |
+int ff_socket(int af, int type, int proto) |
|
239 |
+{ |
|
240 |
+ int fd; |
|
241 |
+ |
|
242 |
+#ifdef SOCK_CLOEXEC |
|
243 |
+ fd = socket(af, type | SOCK_CLOEXEC, proto); |
|
244 |
+ if (fd == -1 && errno == EINVAL) |
|
245 |
+#endif |
|
246 |
+ { |
|
247 |
+ fd = socket(af, type, proto); |
|
248 |
+#if HAVE_FCNTL |
|
249 |
+ if (fd != -1) |
|
250 |
+ fcntl(fd, F_SETFD, FD_CLOEXEC); |
|
251 |
+#endif |
|
252 |
+ } |
|
253 |
+ return fd; |
|
254 |
+} |
|
255 |
+ |
|
238 | 256 |
int ff_listen_bind(int fd, const struct sockaddr *addr, |
239 | 257 |
socklen_t addrlen, int timeout, URLContext *h) |
240 | 258 |
{ |
... | ... |
@@ -262,13 +262,6 @@ int ff_listen_connect(int fd, const struct sockaddr *addr, |
262 | 262 |
|
263 | 263 |
int ff_http_match_no_proxy(const char *no_proxy, const char *hostname); |
264 | 264 |
|
265 |
-#ifndef SOCK_CLOEXEC |
|
266 |
-#define SOCK_CLOEXEC 0 |
|
267 |
-#endif |
|
268 |
- |
|
269 |
-static inline int ff_socket(int domain, int type, int protocol) |
|
270 |
-{ |
|
271 |
- return socket(domain, type | SOCK_CLOEXEC, protocol); |
|
272 |
-} |
|
265 |
+int ff_socket(int domain, int type, int protocol); |
|
273 | 266 |
|
274 | 267 |
#endif /* AVFORMAT_NETWORK_H */ |