FFmpeg
Loading...
Searching...
No Matches
network.c
Go to the documentation of this file.
1/*
2 * Copyright (c) 2007 The FFmpeg Project
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21#include <string.h>
22
23#include "config.h"
24#include "config_components.h"
26
27#if CONFIG_TLS_PROTOCOL && CONFIG_OPENSSL
28#include <openssl/opensslv.h>
29#endif
30
31#include <fcntl.h>
32#if HAVE_EVENTFD
33#include <sys/eventfd.h>
34#endif
35#include "network.h"
36#include "tls.h"
37#include "url.h"
38#include "libavutil/avassert.h"
39#include "libavutil/mem.h"
40#include "libavutil/time.h"
41
42int ff_tls_init(void)
43{
44#if CONFIG_TLS_PROTOCOL
45#if CONFIG_GNUTLS
47#endif
48#endif
49 return 0;
50}
51
52void ff_tls_deinit(void)
53{
54#if CONFIG_TLS_PROTOCOL
55#if CONFIG_GNUTLS
57#endif
58#endif
59}
60
61/**
62 * Initialize the network subsystem. On Windows, this calls WSAStartup().
63 *
64 * @return 0 on success, a negative AVERROR code on failure.
65 */
67{
68#if HAVE_WINSOCK2_H
69 WSADATA wsaData;
70
71 if (WSAStartup(MAKEWORD(1,1), &wsaData))
72 return AVERROR(EIO);
73#endif
74 return 0;
75}
76
77int ff_network_wait_fd(int fd, int write)
78{
79 int ev = write ? POLLOUT : POLLIN;
80 struct pollfd p = { .fd = fd, .events = ev, .revents = 0 };
81 int ret;
82 ret = poll(&p, 1, POLLING_TIME);
83 return ret < 0 ? ff_neterrno() : p.revents & (ev | POLLERR | POLLHUP) ? 0 : AVERROR(EAGAIN);
84}
85
87{
88 int ret;
89 int64_t wait_start = 0;
90
91 while (1) {
93 return AVERROR_EXIT;
94 ret = ff_network_wait_fd(fd, write);
95 if (ret != AVERROR(EAGAIN))
96 return ret;
97 if (timeout > 0) {
98 if (!wait_start)
99 wait_start = av_gettime_relative();
100 else if (av_gettime_relative() - wait_start > timeout)
101 return AVERROR(ETIMEDOUT);
102 }
103 }
104}
105
107{
108#if HAVE_WINSOCK2_H
109 /* select() and WSAPoll() only accept sockets, so use a datagram socket
110 * connected to itself: sending a datagram to it makes it readable.
111 */
112 struct sockaddr_in addr = { .sin_family = AF_INET };
113 socklen_t len = sizeof(addr);
114 int ret, fd = ff_socket(AF_INET, SOCK_DGRAM, 0, NULL);
115
116 if (fd < 0)
117 return ff_neterrno();
118
119 addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
120 if (bind(fd, (struct sockaddr *)&addr, sizeof(addr)) < 0 ||
121 getsockname(fd, (struct sockaddr *)&addr, &len) < 0 ||
122 connect(fd, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
123 ret = ff_neterrno();
124 closesocket(fd);
125 return ret;
126 }
127
128 w->rfd = w->wfd = fd;
129#elif HAVE_EVENTFD
130 int fd = eventfd(0, EFD_CLOEXEC);
131
132 if (fd < 0)
133 return AVERROR(errno);
134
135 w->rfd = w->wfd = fd;
136#else
137 int fds[2];
138
139 if (pipe(fds) < 0)
140 return AVERROR(errno);
141
142#if HAVE_FCNTL
143 for (int i = 0; i < 2; i++) {
144 if (fcntl(fds[i], F_SETFD, FD_CLOEXEC) < 0) {
145 int ret = AVERROR(errno);
146 closesocket(fds[0]);
147 closesocket(fds[1]);
148 return ret;
149 }
150 }
151#endif
152
153 w->rfd = fds[0];
154 w->wfd = fds[1];
155#endif
156
157 atomic_init(&w->signaled, 0);
158
159 return 0;
160}
161
163{
164 /* An eventfd only accepts 8-byte writes; a pipe or a socket takes any
165 * payload, so the same value serves every channel type.
166 */
167 const uint64_t one = 1;
168 int ret;
169
170 /* wfd is blocking; writing at most once keeps the write from blocking.
171 * The flag publishes no other data, so relaxed ordering is enough.
172 */
174 return 0;
175
176#if HAVE_WINSOCK2_H
177 ret = send(w->wfd, (const char *)&one, sizeof(one), 0);
178#else
179 ret = write(w->wfd, &one, sizeof(one));
180#endif
181
182 return ret < 0 ? ff_neterrno() : 0;
183}
184
186{
187 if (w->wfd != w->rfd)
188 closesocket(w->wfd);
189 closesocket(w->rfd);
190
191 w->rfd = w->wfd = -1;
192}
193
194int ff_network_wait_fd_wakeup(int fd, int write, int timeout_ms,
195 FFNetWakeup *w)
196{
197 int ev = write ? POLLOUT : POLLIN;
198 struct pollfd p[2] = {
199 { .fd = w->rfd, .events = POLLIN },
200 { .fd = fd, .events = ev },
201 };
202 int ret;
203
204 /* Return without polling once signaled. This also ends the wait when
205 * the write in ff_network_wakeup_signal() failed and rfd never became
206 * readable.
207 */
209 return AVERROR_EXIT;
210
211 ret = poll(p, 2, timeout_ms);
212 if (ret < 0)
213 return ff_neterrno();
214
215 if (p[0].revents & POLLIN)
216 return AVERROR_EXIT;
217
218 return p[1].revents & (ev | POLLERR | POLLHUP) ? 0 : AVERROR(EAGAIN);
219}
220
222{
223 int64_t wait_start = av_gettime_relative();
224
225 while (1) {
226 int64_t time_left;
227
229 return AVERROR_EXIT;
230
231 time_left = timeout - (av_gettime_relative() - wait_start);
232 if (time_left <= 0)
233 return AVERROR(ETIMEDOUT);
234
235 av_usleep(FFMIN(time_left, POLLING_TIME * 1000));
236 }
237}
238
240{
241#if HAVE_WINSOCK2_H
242 WSACleanup();
243#endif
244}
245
246#if HAVE_WINSOCK2_H
247int ff_neterrno(void)
248{
249 int err = WSAGetLastError();
250 switch (err) {
251 case WSAEWOULDBLOCK:
252 return AVERROR(EAGAIN);
253 case WSAEINTR:
254 return AVERROR(EINTR);
255 case WSAEPROTONOSUPPORT:
256 return AVERROR(EPROTONOSUPPORT);
257 case WSAETIMEDOUT:
258 return AVERROR(ETIMEDOUT);
259 case WSAECONNREFUSED:
260 return AVERROR(ECONNREFUSED);
261 case WSAEINPROGRESS:
262 return AVERROR(EINPROGRESS);
263 }
264 return -err;
265}
266#endif
267
268int ff_is_multicast_address(struct sockaddr *addr)
269{
270 if (addr->sa_family == AF_INET) {
271 return IN_MULTICAST(ntohl(((struct sockaddr_in *)addr)->sin_addr.s_addr));
272 }
273#if HAVE_STRUCT_SOCKADDR_IN6
274 if (addr->sa_family == AF_INET6) {
275 return IN6_IS_ADDR_MULTICAST(&((struct sockaddr_in6 *)addr)->sin6_addr);
276 }
277#endif
278
279 return 0;
280}
281
282static int ff_poll_interrupt(struct pollfd *p, nfds_t nfds, int timeout,
284{
285 int runs = timeout / POLLING_TIME;
286 int ret = 0;
287
288 do {
290 return AVERROR_EXIT;
291 ret = poll(p, nfds, POLLING_TIME);
292 if (ret != 0) {
293 if (ret < 0)
294 ret = ff_neterrno();
295 if (ret == AVERROR(EINTR))
296 continue;
297 break;
298 }
299 } while (timeout <= 0 || runs-- > 0);
300
301 if (!ret)
302 return AVERROR(ETIMEDOUT);
303 return ret;
304}
305
306int ff_socket(int af, int type, int proto, void *logctx)
307{
308 int fd;
309
310#ifdef SOCK_CLOEXEC
311 fd = socket(af, type | SOCK_CLOEXEC, proto);
312 if (fd == -1 && errno == EINVAL)
313#endif
314 {
315 fd = socket(af, type, proto);
316#if HAVE_FCNTL
317 if (fd != -1) {
318 if (fcntl(fd, F_SETFD, FD_CLOEXEC) == -1)
319 av_log(logctx, AV_LOG_DEBUG, "Failed to set close on exec\n");
320 }
321#endif
322 }
323#ifdef SO_NOSIGPIPE
324 if (fd != -1) {
325 if (setsockopt(fd, SOL_SOCKET, SO_NOSIGPIPE, &(int){1}, sizeof(int))) {
326 av_log(logctx, AV_LOG_WARNING, "setsockopt(SO_NOSIGPIPE) failed\n");
327 }
328 }
329#endif
330 return fd;
331}
332
333int ff_listen(int fd, const struct sockaddr *addr,
334 socklen_t addrlen, void *logctx)
335{
336 int ret;
337 int reuse = 1;
338 if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof(reuse))) {
339 av_log(logctx, AV_LOG_WARNING, "setsockopt(SO_REUSEADDR) failed\n");
340 }
341 ret = bind(fd, addr, addrlen);
342 if (ret)
343 return ff_neterrno();
344
345 ret = listen(fd, 1);
346 if (ret)
347 return ff_neterrno();
348 return ret;
349}
350
351int ff_accept(int fd, int timeout, URLContext *h)
352{
353 int ret;
354 struct pollfd lp = { fd, POLLIN, 0 };
355
356 ret = ff_poll_interrupt(&lp, 1, timeout, &h->interrupt_callback);
357 if (ret < 0)
358 return ret;
359
360 ret = accept(fd, NULL, NULL);
361 if (ret < 0)
362 return ff_neterrno();
363 if (ff_socket_nonblock(ret, 1) < 0)
364 av_log(h, AV_LOG_DEBUG, "ff_socket_nonblock failed\n");
365
366 return ret;
367}
368
369int ff_listen_bind(int fd, const struct sockaddr *addr,
370 socklen_t addrlen, int timeout, URLContext *h)
371{
372 int ret;
373 if ((ret = ff_listen(fd, addr, addrlen, h)) < 0)
374 return ret;
375 if ((ret = ff_accept(fd, timeout, h)) < 0)
376 return ret;
377 closesocket(fd);
378 return ret;
379}
380
381int ff_listen_connect(int fd, const struct sockaddr *addr,
382 socklen_t addrlen, int timeout, URLContext *h,
383 int will_try_next)
384{
385 struct pollfd p = {fd, POLLOUT, 0};
386 int ret;
387 socklen_t optlen;
388
389 if (ff_socket_nonblock(fd, 1) < 0)
390 av_log(h, AV_LOG_DEBUG, "ff_socket_nonblock failed\n");
391
392 while ((ret = connect(fd, addr, addrlen))) {
393 ret = ff_neterrno();
394 switch (ret) {
395 case AVERROR(EINTR):
396 if (ff_check_interrupt(&h->interrupt_callback))
397 return AVERROR_EXIT;
398 continue;
399 case AVERROR(EINPROGRESS):
400 case AVERROR(EAGAIN):
401 ret = ff_poll_interrupt(&p, 1, timeout, &h->interrupt_callback);
402 if (ret < 0)
403 return ret;
404 optlen = sizeof(ret);
405 if (getsockopt (fd, SOL_SOCKET, SO_ERROR, &ret, &optlen))
407 if (ret != 0) {
408 ret = AVERROR(ret);
409 if (will_try_next)
411 "Connection to %s failed (%s), trying next address\n",
412 h->filename, av_err2str(ret));
413 else
414 av_log(h, AV_LOG_ERROR, "Connection to %s failed: %s\n",
415 h->filename, av_err2str(ret));
416 }
418 default:
419 return ret;
420 }
421 }
422 return ret;
423}
424
426{
427 struct addrinfo **next = &base->ai_next;
428 while (*next) {
429 struct addrinfo *cur = *next;
430 // Iterate forward until we find an entry of a different family.
431 if (cur->ai_family == base->ai_family) {
432 next = &cur->ai_next;
433 continue;
434 }
435 if (cur == base->ai_next) {
436 // If the first one following base is of a different family, just
437 // move base forward one step and continue.
438 base = cur;
439 next = &base->ai_next;
440 continue;
441 }
442 // Unchain cur from the rest of the list from its current spot.
443 *next = cur->ai_next;
444 // Hook in cur directly after base.
445 cur->ai_next = base->ai_next;
446 base->ai_next = cur;
447 // Restart with a new base. We know that before moving the cur element,
448 // everything between the previous base and cur had the same family,
449 // different from cur->ai_family. Therefore, we can keep next pointing
450 // where it was, and continue from there with base at the one after
451 // cur.
452 base = cur->ai_next;
453 }
454}
455
456static void print_address_list(void *ctx, const struct addrinfo *addr,
457 const char *title)
458{
459 char hostbuf[100], portbuf[20];
460 av_log(ctx, AV_LOG_DEBUG, "%s:\n", title);
461 while (addr) {
462 getnameinfo(addr->ai_addr, addr->ai_addrlen,
463 hostbuf, sizeof(hostbuf), portbuf, sizeof(portbuf),
465 av_log(ctx, AV_LOG_DEBUG, "Address %s port %s\n", hostbuf, portbuf);
466 addr = addr->ai_next;
467 }
468}
469
475
476// Returns < 0 on error, 0 on successfully started connection attempt,
477// > 0 for a connection that succeeded already.
478static int start_connect_attempt(struct ConnectionAttempt *attempt,
479 struct addrinfo **ptr, int timeout_ms,
480 URLContext *h,
481 int (*customize_fd)(void *, int, int), void *customize_ctx)
482{
483 struct addrinfo *ai = *ptr;
484 int ret;
485
486 *ptr = ai->ai_next;
487
488 attempt->fd = ff_socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol, h);
489 if (attempt->fd < 0)
490 return ff_neterrno();
491 attempt->deadline_us = av_gettime_relative() + timeout_ms * 1000;
492 attempt->addr = ai;
493
494 ff_socket_nonblock(attempt->fd, 1);
495
496 if (customize_fd) {
497 ret = customize_fd(customize_ctx, attempt->fd, ai->ai_family);
498 if (ret) {
499 closesocket(attempt->fd);
500 attempt->fd = -1;
501 return ret;
502 }
503 }
504
505 while ((ret = connect(attempt->fd, ai->ai_addr, ai->ai_addrlen))) {
506 ret = ff_neterrno();
507 switch (ret) {
508 case AVERROR(EINTR):
509 if (ff_check_interrupt(&h->interrupt_callback)) {
510 closesocket(attempt->fd);
511 attempt->fd = -1;
512 return AVERROR_EXIT;
513 }
514 continue;
515 case AVERROR(EINPROGRESS):
516 case AVERROR(EAGAIN):
517 return 0;
518 default:
519 closesocket(attempt->fd);
520 attempt->fd = -1;
521 return ret;
522 }
523 }
524 return 1;
525}
526
527// Try a new connection to another address after 200 ms, as suggested in
528// RFC 8305 (or sooner if an earlier attempt fails).
529#define NEXT_ATTEMPT_DELAY_MS 200
530
531int ff_connect_parallel(struct addrinfo *addrs, int timeout_ms_per_address,
532 int parallel, URLContext *h, int *fd,
533 int (*customize_fd)(void *, int, int), void *customize_ctx)
534{
535 struct ConnectionAttempt attempts[3];
536 struct pollfd pfd[3];
537 int nb_attempts = 0, i, j;
538 int64_t next_attempt_us = av_gettime_relative(), next_deadline_us;
539 int last_err = AVERROR(EIO);
540 socklen_t optlen;
541 char hostbuf[100], portbuf[20];
542
543 if (parallel > FF_ARRAY_ELEMS(attempts))
544 parallel = FF_ARRAY_ELEMS(attempts);
545
546 print_address_list(h, addrs, "Original list of addresses");
547 // This mutates the list, but the head of the list is still the same
548 // element, so the caller, who owns the list, doesn't need to get
549 // an updated pointer.
550 interleave_addrinfo(addrs);
551 print_address_list(h, addrs, "Interleaved list of addresses");
552
553 while (nb_attempts > 0 || addrs) {
554 // Start a new connection attempt, if possible.
555 if (nb_attempts < parallel && addrs) {
556 getnameinfo(addrs->ai_addr, addrs->ai_addrlen,
557 hostbuf, sizeof(hostbuf), portbuf, sizeof(portbuf),
559 av_log(h, AV_LOG_VERBOSE, "Starting connection attempt to %s port %s\n",
560 hostbuf, portbuf);
561 last_err = start_connect_attempt(&attempts[nb_attempts], &addrs,
562 timeout_ms_per_address, h,
563 customize_fd, customize_ctx);
564 if (last_err < 0) {
565 av_log(h, AV_LOG_VERBOSE, "Connected attempt failed: %s\n",
566 av_err2str(last_err));
567 continue;
568 }
569 if (last_err > 0) {
570 for (i = 0; i < nb_attempts; i++)
571 closesocket(attempts[i].fd);
572 *fd = attempts[nb_attempts].fd;
573 return 0;
574 }
575 pfd[nb_attempts].fd = attempts[nb_attempts].fd;
576 pfd[nb_attempts].events = POLLOUT;
577 next_attempt_us = av_gettime_relative() + NEXT_ATTEMPT_DELAY_MS * 1000;
578 nb_attempts++;
579 }
580
581 av_assert0(nb_attempts > 0);
582 // The connection attempts are sorted from oldest to newest, so the
583 // first one will have the earliest deadline.
584 next_deadline_us = attempts[0].deadline_us;
585 // If we can start another attempt in parallel, wait until that time.
586 if (nb_attempts < parallel && addrs)
587 next_deadline_us = FFMIN(next_deadline_us, next_attempt_us);
588 last_err = ff_poll_interrupt(pfd, nb_attempts,
589 (next_deadline_us - av_gettime_relative())/1000,
590 &h->interrupt_callback);
591 if (last_err < 0 && last_err != AVERROR(ETIMEDOUT))
592 break;
593
594 // Check the status from the poll output.
595 for (i = 0; i < nb_attempts; i++) {
596 last_err = 0;
597 if (pfd[i].revents) {
598 // Some sort of action for this socket, check its status (either
599 // a successful connection or an error).
600 optlen = sizeof(last_err);
601 if (getsockopt(attempts[i].fd, SOL_SOCKET, SO_ERROR, &last_err, &optlen))
602 last_err = ff_neterrno();
603 else if (last_err != 0)
604 last_err = AVERROR(last_err);
605 if (last_err == 0) {
606 // Everything is ok, we seem to have a successful
607 // connection. Close other sockets and return this one.
608 for (j = 0; j < nb_attempts; j++)
609 if (j != i)
610 closesocket(attempts[j].fd);
611 *fd = attempts[i].fd;
612 getnameinfo(attempts[i].addr->ai_addr, attempts[i].addr->ai_addrlen,
613 hostbuf, sizeof(hostbuf), portbuf, sizeof(portbuf),
615 av_log(h, AV_LOG_VERBOSE, "Successfully connected to %s port %s\n",
616 hostbuf, portbuf);
617 return 0;
618 }
619 }
620 if (attempts[i].deadline_us < av_gettime_relative() && !last_err)
621 last_err = AVERROR(ETIMEDOUT);
622 if (!last_err)
623 continue;
624 // Error (or timeout) for this socket; close the socket and remove
625 // it from the attempts/pfd arrays, to let a new attempt start
626 // directly.
627 getnameinfo(attempts[i].addr->ai_addr, attempts[i].addr->ai_addrlen,
628 hostbuf, sizeof(hostbuf), portbuf, sizeof(portbuf),
630 av_log(h, AV_LOG_VERBOSE, "Connection attempt to %s port %s "
631 "failed: %s\n", hostbuf, portbuf, av_err2str(last_err));
632 closesocket(attempts[i].fd);
633 memmove(&attempts[i], &attempts[i + 1],
634 (nb_attempts - i - 1) * sizeof(*attempts));
635 memmove(&pfd[i], &pfd[i + 1],
636 (nb_attempts - i - 1) * sizeof(*pfd));
637 i--;
638 nb_attempts--;
639 }
640 }
641 for (i = 0; i < nb_attempts; i++)
642 closesocket(attempts[i].fd);
643 if (last_err >= 0)
644 last_err = AVERROR(ECONNREFUSED);
645 if (last_err != AVERROR_EXIT) {
646 av_log(h, AV_LOG_ERROR, "Connection to %s failed: %s\n",
647 h->filename, av_err2str(last_err));
648 }
649 return last_err;
650}
651
652static int match_host_pattern(const char *pattern, const char *hostname)
653{
654 int len_p, len_h;
655 if (!strcmp(pattern, "*"))
656 return 1;
657 // Skip a possible *. at the start of the pattern
658 if (pattern[0] == '*')
659 pattern++;
660 if (pattern[0] == '.')
661 pattern++;
662 len_p = strlen(pattern);
663 len_h = strlen(hostname);
664 if (len_p > len_h)
665 return 0;
666 // Simply check if the end of hostname is equal to 'pattern'
667 if (!strcmp(pattern, &hostname[len_h - len_p])) {
668 if (len_h == len_p)
669 return 1; // Exact match
670 if (hostname[len_h - len_p - 1] == '.')
671 return 1; // The matched substring is a domain and not just a substring of a domain
672 }
673 return 0;
674}
675
676int ff_http_match_no_proxy(const char *no_proxy, const char *hostname)
677{
678 char *buf, *start;
679 int ret = 0;
680 if (!no_proxy)
681 return 0;
682 if (!hostname)
683 return 0;
684 buf = av_strdup(no_proxy);
685 if (!buf)
686 return 0;
687 start = buf;
688 while (start) {
689 char *sep, *next = NULL;
690 start += strspn(start, " ,");
691 sep = start + strcspn(start, " ,");
692 if (*sep) {
693 next = sep + 1;
694 *sep = '\0';
695 }
696 if (match_host_pattern(start, hostname)) {
697 ret = 1;
698 break;
699 }
700 start = next;
701 }
702 av_free(buf);
703 return ret;
704}
705
706void ff_log_net_error(void *ctx, int level, const char* prefix)
707{
708 av_log(ctx, level, "%s: %s\n", prefix, av_err2str(ff_neterrno()));
709}
static AVFormatContext * ctx
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition avassert.h:42
int ff_check_interrupt(AVIOInterruptCB *cb)
Check if the user has requested to interrupt a blocking function associated with cb.
Definition avio.c:935
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define NULL
Definition coverity.c:32
long long int64_t
Definition coverity.c:34
const AVIOInterruptCB int_cb
Definition ffmpeg.c:322
int ret
Definition ffplay.c:391
#define AVUNERROR(e)
Definition error.h:46
#define AVERROR_EXIT
Immediate exit was requested; the called function should not be restarted.
Definition error.h:58
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
Definition error.h:122
#define AVERROR(e)
Definition error.h:45
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition log.h:231
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition log.h:216
#define AV_LOG_VERBOSE
Detailed information.
Definition log.h:226
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition log.h:210
enum MPFType type
Definition jpegmpfenc.c:55
Macro definitions for various function/variable attributes.
#define av_fallthrough
Definition attributes.h:67
uint8_t w
Definition llvidencdsp.c:39
#define FFMIN(a, b)
Definition macros.h:49
Memory handling functions.
int ff_connect_parallel(struct addrinfo *addrs, int timeout_ms_per_address, int parallel, URLContext *h, int *fd, int(*customize_fd)(void *, int, int), void *customize_ctx)
Connect to any of the given addrinfo addresses, with multiple attempts running in parallel.
Definition network.c:531
int ff_is_multicast_address(struct sockaddr *addr)
Definition network.c:268
static int start_connect_attempt(struct ConnectionAttempt *attempt, struct addrinfo **ptr, int timeout_ms, URLContext *h, int(*customize_fd)(void *, int, int), void *customize_ctx)
Definition network.c:478
int ff_socket(int af, int type, int proto, void *logctx)
Definition network.c:306
int ff_network_wait_fd_wakeup(int fd, int write, int timeout_ms, FFNetWakeup *w)
Like ff_network_wait_fd(), but also returns as soon as the wakeup channel is signaled,...
Definition network.c:194
int ff_network_wakeup_open(FFNetWakeup *w)
Create a wakeup channel.
Definition network.c:106
int ff_network_sleep_interruptible(int64_t timeout, AVIOInterruptCB *int_cb)
Waits for up to 'timeout' microseconds.
Definition network.c:221
int ff_listen(int fd, const struct sockaddr *addr, socklen_t addrlen, void *logctx)
Bind to a file descriptor to an address without accepting connections.
Definition network.c:333
void ff_log_net_error(void *ctx, int level, const char *prefix)
Definition network.c:706
int ff_listen_connect(int fd, const struct sockaddr *addr, socklen_t addrlen, int timeout, URLContext *h, int will_try_next)
Connect to a file descriptor and poll for result.
Definition network.c:381
int ff_network_wakeup_signal(FFNetWakeup *w)
Wake the thread blocked in ff_network_wait_fd_wakeup() on this channel, or the next one that waits on...
Definition network.c:162
void ff_network_wakeup_close(FFNetWakeup *w)
Close the channel.
Definition network.c:185
static void print_address_list(void *ctx, const struct addrinfo *addr, const char *title)
Definition network.c:456
static void interleave_addrinfo(struct addrinfo *base)
Definition network.c:425
int ff_listen_bind(int fd, const struct sockaddr *addr, socklen_t addrlen, int timeout, URLContext *h)
Bind to a file descriptor and poll for a connection.
Definition network.c:369
static int ff_poll_interrupt(struct pollfd *p, nfds_t nfds, int timeout, AVIOInterruptCB *cb)
Definition network.c:282
int ff_network_wait_fd(int fd, int write)
Definition network.c:77
int ff_network_init(void)
Initialize the network subsystem.
Definition network.c:66
static int match_host_pattern(const char *pattern, const char *hostname)
Definition network.c:652
int ff_tls_init(void)
Definition network.c:42
#define NEXT_ATTEMPT_DELAY_MS
Definition network.c:529
int ff_network_wait_fd_timeout(int fd, int write, int64_t timeout, AVIOInterruptCB *int_cb)
This works similarly to ff_network_wait_fd, but waits up to 'timeout' microseconds Uses ff_network_wa...
Definition network.c:86
void ff_network_close(void)
Definition network.c:239
void ff_tls_deinit(void)
Definition network.c:52
int ff_http_match_no_proxy(const char *no_proxy, const char *hostname)
Definition network.c:676
int ff_accept(int fd, int timeout, URLContext *h)
Poll for a single connection on the passed file descriptor.
Definition network.c:351
int ff_socket_nonblock(int socket, int enable)
#define POLLING_TIME
Definition network.h:312
#define NI_NUMERICHOST
Definition network.h:258
#define ff_neterrno()
Definition network.h:69
#define IN_MULTICAST(a)
Definition network.h:304
#define getnameinfo
Definition network.h:282
#define INADDR_LOOPBACK
Definition network.h:292
#define IN6_IS_ADDR_MULTICAST(a)
Definition network.h:307
#define NI_NUMERICSERV
Definition network.h:266
#define av_strdup(s)
Definition ops_static.c:55
#define FF_ARRAY_ELEMS(a)
@ memory_order_relaxed
Definition stdatomic.h:29
#define atomic_load_explicit(object, order)
Definition stdatomic.h:247
#define atomic_exchange_explicit(object, desired, order)
Definition stdatomic.h:259
#define atomic_init(obj, value)
Definition stdatomic.h:119
Callback for checking whether to abort blocking functions.
Definition avio.h:59
int64_t deadline_us
Definition network.c:472
struct addrinfo * addr
Definition network.c:473
A channel for waking a thread that is blocked in ff_network_wait_fd_wakeup(), from another thread.
Definition network.h:126
struct sockaddr * ai_addr
Definition network.h:206
int ai_socktype
Definition network.h:203
int ai_protocol
Definition network.h:204
int ai_addrlen
Definition network.h:205
struct addrinfo * ai_next
Definition network.h:208
int ai_family
Definition network.h:202
uint8_t level
Definition svq3.c:208
#define av_free(p)
#define av_log(a,...)
static int customize_fd(void *ctx, int fd, int family)
Definition tcp.c:80
int av_usleep(unsigned usec)
Sleep for a period of time.
Definition time.c:93
int64_t av_gettime_relative(void)
Get the current time in microseconds since some unspecified starting point.
Definition time.c:57
void ff_gnutls_deinit(void)
Definition tls_gnutls.c:359
void ff_gnutls_init(void)
Definition tls_gnutls.c:348
char prefix[8]
unbuffered private I/O API
static double cb(void *priv, double x, double y)
Definition vf_geq.c:247
int len
uint8_t base
Definition vp3data.h:128