FFmpeg
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 "config.h"
22 #include "config_components.h"
23 
24 #if CONFIG_TLS_PROTOCOL && CONFIG_OPENSSL
25 #include <openssl/opensslv.h>
26 #endif
27 
28 #include <fcntl.h>
29 #include "network.h"
30 #include "tls.h"
31 #include "url.h"
32 #include "libavutil/avassert.h"
33 #include "libavutil/mem.h"
34 #include "libavutil/time.h"
35 
36 int ff_tls_init(void)
37 {
38 #if CONFIG_TLS_PROTOCOL
39 #if CONFIG_OPENSSL && OPENSSL_VERSION_NUMBER < 0x10100000L
40  int ret;
41  if ((ret = ff_openssl_init()) < 0)
42  return ret;
43 #endif
44 #if CONFIG_GNUTLS
46 #endif
47 #endif
48  return 0;
49 }
50 
51 void ff_tls_deinit(void)
52 {
53 #if CONFIG_TLS_PROTOCOL
54 #if CONFIG_OPENSSL && OPENSSL_VERSION_NUMBER < 0x10100000L
56 #endif
57 #if CONFIG_GNUTLS
59 #endif
60 #endif
61 }
62 
63 int ff_network_init(void)
64 {
65 #if HAVE_WINSOCK2_H
66  WSADATA wsaData;
67 
68  if (WSAStartup(MAKEWORD(1,1), &wsaData))
69  return 0;
70 #endif
71  return 1;
72 }
73 
74 int ff_network_wait_fd(int fd, int write)
75 {
76  int ev = write ? POLLOUT : POLLIN;
77  struct pollfd p = { .fd = fd, .events = ev, .revents = 0 };
78  int ret;
79  ret = poll(&p, 1, POLLING_TIME);
80  return ret < 0 ? ff_neterrno() : p.revents & (ev | POLLERR | POLLHUP) ? 0 : AVERROR(EAGAIN);
81 }
82 
83 int ff_network_wait_fd_timeout(int fd, int write, int64_t timeout, AVIOInterruptCB *int_cb)
84 {
85  int ret;
86  int64_t wait_start = 0;
87 
88  while (1) {
90  return AVERROR_EXIT;
91  ret = ff_network_wait_fd(fd, write);
92  if (ret != AVERROR(EAGAIN))
93  return ret;
94  if (timeout > 0) {
95  if (!wait_start)
96  wait_start = av_gettime_relative();
97  else if (av_gettime_relative() - wait_start > timeout)
98  return AVERROR(ETIMEDOUT);
99  }
100  }
101 }
102 
104 {
105  int64_t wait_start = av_gettime_relative();
106 
107  while (1) {
108  int64_t time_left;
109 
111  return AVERROR_EXIT;
112 
113  time_left = timeout - (av_gettime_relative() - wait_start);
114  if (time_left <= 0)
115  return AVERROR(ETIMEDOUT);
116 
117  av_usleep(FFMIN(time_left, POLLING_TIME * 1000));
118  }
119 }
120 
122 {
123 #if HAVE_WINSOCK2_H
124  WSACleanup();
125 #endif
126 }
127 
128 #if HAVE_WINSOCK2_H
129 int ff_neterrno(void)
130 {
131  int err = WSAGetLastError();
132  switch (err) {
133  case WSAEWOULDBLOCK:
134  return AVERROR(EAGAIN);
135  case WSAEINTR:
136  return AVERROR(EINTR);
137  case WSAEPROTONOSUPPORT:
138  return AVERROR(EPROTONOSUPPORT);
139  case WSAETIMEDOUT:
140  return AVERROR(ETIMEDOUT);
141  case WSAECONNREFUSED:
142  return AVERROR(ECONNREFUSED);
143  case WSAEINPROGRESS:
144  return AVERROR(EINPROGRESS);
145  }
146  return -err;
147 }
148 #endif
149 
150 int ff_is_multicast_address(struct sockaddr *addr)
151 {
152  if (addr->sa_family == AF_INET) {
153  return IN_MULTICAST(ntohl(((struct sockaddr_in *)addr)->sin_addr.s_addr));
154  }
155 #if HAVE_STRUCT_SOCKADDR_IN6
156  if (addr->sa_family == AF_INET6) {
157  return IN6_IS_ADDR_MULTICAST(&((struct sockaddr_in6 *)addr)->sin6_addr);
158  }
159 #endif
160 
161  return 0;
162 }
163 
164 static int ff_poll_interrupt(struct pollfd *p, nfds_t nfds, int timeout,
166 {
167  int runs = timeout / POLLING_TIME;
168  int ret = 0;
169 
170  do {
171  if (ff_check_interrupt(cb))
172  return AVERROR_EXIT;
173  ret = poll(p, nfds, POLLING_TIME);
174  if (ret != 0) {
175  if (ret < 0)
176  ret = ff_neterrno();
177  if (ret == AVERROR(EINTR))
178  continue;
179  break;
180  }
181  } while (timeout <= 0 || runs-- > 0);
182 
183  if (!ret)
184  return AVERROR(ETIMEDOUT);
185  return ret;
186 }
187 
188 int ff_socket(int af, int type, int proto, void *logctx)
189 {
190  int fd;
191 
192 #ifdef SOCK_CLOEXEC
193  fd = socket(af, type | SOCK_CLOEXEC, proto);
194  if (fd == -1 && errno == EINVAL)
195 #endif
196  {
197  fd = socket(af, type, proto);
198 #if HAVE_FCNTL
199  if (fd != -1) {
200  if (fcntl(fd, F_SETFD, FD_CLOEXEC) == -1)
201  av_log(logctx, AV_LOG_DEBUG, "Failed to set close on exec\n");
202  }
203 #endif
204  }
205 #ifdef SO_NOSIGPIPE
206  if (fd != -1) {
207  if (setsockopt(fd, SOL_SOCKET, SO_NOSIGPIPE, &(int){1}, sizeof(int))) {
208  av_log(logctx, AV_LOG_WARNING, "setsockopt(SO_NOSIGPIPE) failed\n");
209  }
210  }
211 #endif
212  return fd;
213 }
214 
215 int ff_listen(int fd, const struct sockaddr *addr,
216  socklen_t addrlen, void *logctx)
217 {
218  int ret;
219  int reuse = 1;
220  if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof(reuse))) {
221  av_log(logctx, AV_LOG_WARNING, "setsockopt(SO_REUSEADDR) failed\n");
222  }
223  ret = bind(fd, addr, addrlen);
224  if (ret)
225  return ff_neterrno();
226 
227  ret = listen(fd, 1);
228  if (ret)
229  return ff_neterrno();
230  return ret;
231 }
232 
233 int ff_accept(int fd, int timeout, URLContext *h)
234 {
235  int ret;
236  struct pollfd lp = { fd, POLLIN, 0 };
237 
238  ret = ff_poll_interrupt(&lp, 1, timeout, &h->interrupt_callback);
239  if (ret < 0)
240  return ret;
241 
242  ret = accept(fd, NULL, NULL);
243  if (ret < 0)
244  return ff_neterrno();
245  if (ff_socket_nonblock(ret, 1) < 0)
246  av_log(h, AV_LOG_DEBUG, "ff_socket_nonblock failed\n");
247 
248  return ret;
249 }
250 
251 int ff_listen_bind(int fd, const struct sockaddr *addr,
252  socklen_t addrlen, int timeout, URLContext *h)
253 {
254  int ret;
255  if ((ret = ff_listen(fd, addr, addrlen, h)) < 0)
256  return ret;
257  if ((ret = ff_accept(fd, timeout, h)) < 0)
258  return ret;
259  closesocket(fd);
260  return ret;
261 }
262 
263 int ff_listen_connect(int fd, const struct sockaddr *addr,
264  socklen_t addrlen, int timeout, URLContext *h,
265  int will_try_next)
266 {
267  struct pollfd p = {fd, POLLOUT, 0};
268  int ret;
269  socklen_t optlen;
270 
271  if (ff_socket_nonblock(fd, 1) < 0)
272  av_log(h, AV_LOG_DEBUG, "ff_socket_nonblock failed\n");
273 
274  while ((ret = connect(fd, addr, addrlen))) {
275  ret = ff_neterrno();
276  switch (ret) {
277  case AVERROR(EINTR):
278  if (ff_check_interrupt(&h->interrupt_callback))
279  return AVERROR_EXIT;
280  continue;
281  case AVERROR(EINPROGRESS):
282  case AVERROR(EAGAIN):
283  ret = ff_poll_interrupt(&p, 1, timeout, &h->interrupt_callback);
284  if (ret < 0)
285  return ret;
286  optlen = sizeof(ret);
287  if (getsockopt (fd, SOL_SOCKET, SO_ERROR, &ret, &optlen))
289  if (ret != 0) {
290  char errbuf[100];
291  ret = AVERROR(ret);
292  av_strerror(ret, errbuf, sizeof(errbuf));
293  if (will_try_next)
295  "Connection to %s failed (%s), trying next address\n",
296  h->filename, errbuf);
297  else
298  av_log(h, AV_LOG_ERROR, "Connection to %s failed: %s\n",
299  h->filename, errbuf);
300  }
301  default:
302  return ret;
303  }
304  }
305  return ret;
306 }
307 
308 static void interleave_addrinfo(struct addrinfo *base)
309 {
310  struct addrinfo **next = &base->ai_next;
311  while (*next) {
312  struct addrinfo *cur = *next;
313  // Iterate forward until we find an entry of a different family.
314  if (cur->ai_family == base->ai_family) {
315  next = &cur->ai_next;
316  continue;
317  }
318  if (cur == base->ai_next) {
319  // If the first one following base is of a different family, just
320  // move base forward one step and continue.
321  base = cur;
322  next = &base->ai_next;
323  continue;
324  }
325  // Unchain cur from the rest of the list from its current spot.
326  *next = cur->ai_next;
327  // Hook in cur directly after base.
328  cur->ai_next = base->ai_next;
329  base->ai_next = cur;
330  // Restart with a new base. We know that before moving the cur element,
331  // everything between the previous base and cur had the same family,
332  // different from cur->ai_family. Therefore, we can keep next pointing
333  // where it was, and continue from there with base at the one after
334  // cur.
335  base = cur->ai_next;
336  }
337 }
338 
339 static void print_address_list(void *ctx, const struct addrinfo *addr,
340  const char *title)
341 {
342  char hostbuf[100], portbuf[20];
343  av_log(ctx, AV_LOG_DEBUG, "%s:\n", title);
344  while (addr) {
345  getnameinfo(addr->ai_addr, addr->ai_addrlen,
346  hostbuf, sizeof(hostbuf), portbuf, sizeof(portbuf),
348  av_log(ctx, AV_LOG_DEBUG, "Address %s port %s\n", hostbuf, portbuf);
349  addr = addr->ai_next;
350  }
351 }
352 
354  int fd;
355  int64_t deadline_us;
356  struct addrinfo *addr;
357 };
358 
359 // Returns < 0 on error, 0 on successfully started connection attempt,
360 // > 0 for a connection that succeeded already.
361 static int start_connect_attempt(struct ConnectionAttempt *attempt,
362  struct addrinfo **ptr, int timeout_ms,
363  URLContext *h,
364  int (*customize_fd)(void *, int, int), void *customize_ctx)
365 {
366  struct addrinfo *ai = *ptr;
367  int ret;
368 
369  *ptr = ai->ai_next;
370 
371  attempt->fd = ff_socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol, h);
372  if (attempt->fd < 0)
373  return ff_neterrno();
374  attempt->deadline_us = av_gettime_relative() + timeout_ms * 1000;
375  attempt->addr = ai;
376 
377  ff_socket_nonblock(attempt->fd, 1);
378 
379  if (customize_fd) {
380  ret = customize_fd(customize_ctx, attempt->fd, ai->ai_family);
381  if (ret) {
382  closesocket(attempt->fd);
383  attempt->fd = -1;
384  return ret;
385  }
386  }
387 
388  while ((ret = connect(attempt->fd, ai->ai_addr, ai->ai_addrlen))) {
389  ret = ff_neterrno();
390  switch (ret) {
391  case AVERROR(EINTR):
392  if (ff_check_interrupt(&h->interrupt_callback)) {
393  closesocket(attempt->fd);
394  attempt->fd = -1;
395  return AVERROR_EXIT;
396  }
397  continue;
398  case AVERROR(EINPROGRESS):
399  case AVERROR(EAGAIN):
400  return 0;
401  default:
402  closesocket(attempt->fd);
403  attempt->fd = -1;
404  return ret;
405  }
406  }
407  return 1;
408 }
409 
410 // Try a new connection to another address after 200 ms, as suggested in
411 // RFC 8305 (or sooner if an earlier attempt fails).
412 #define NEXT_ATTEMPT_DELAY_MS 200
413 
414 int ff_connect_parallel(struct addrinfo *addrs, int timeout_ms_per_address,
415  int parallel, URLContext *h, int *fd,
416  int (*customize_fd)(void *, int, int), void *customize_ctx)
417 {
418  struct ConnectionAttempt attempts[3];
419  struct pollfd pfd[3];
420  int nb_attempts = 0, i, j;
421  int64_t next_attempt_us = av_gettime_relative(), next_deadline_us;
422  int last_err = AVERROR(EIO);
423  socklen_t optlen;
424  char errbuf[100], hostbuf[100], portbuf[20];
425 
426  if (parallel > FF_ARRAY_ELEMS(attempts))
427  parallel = FF_ARRAY_ELEMS(attempts);
428 
429  print_address_list(h, addrs, "Original list of addresses");
430  // This mutates the list, but the head of the list is still the same
431  // element, so the caller, who owns the list, doesn't need to get
432  // an updated pointer.
433  interleave_addrinfo(addrs);
434  print_address_list(h, addrs, "Interleaved list of addresses");
435 
436  while (nb_attempts > 0 || addrs) {
437  // Start a new connection attempt, if possible.
438  if (nb_attempts < parallel && addrs) {
439  getnameinfo(addrs->ai_addr, addrs->ai_addrlen,
440  hostbuf, sizeof(hostbuf), portbuf, sizeof(portbuf),
442  av_log(h, AV_LOG_VERBOSE, "Starting connection attempt to %s port %s\n",
443  hostbuf, portbuf);
444  last_err = start_connect_attempt(&attempts[nb_attempts], &addrs,
445  timeout_ms_per_address, h,
446  customize_fd, customize_ctx);
447  if (last_err < 0) {
448  av_strerror(last_err, errbuf, sizeof(errbuf));
449  av_log(h, AV_LOG_VERBOSE, "Connected attempt failed: %s\n",
450  errbuf);
451  continue;
452  }
453  if (last_err > 0) {
454  for (i = 0; i < nb_attempts; i++)
455  closesocket(attempts[i].fd);
456  *fd = attempts[nb_attempts].fd;
457  return 0;
458  }
459  pfd[nb_attempts].fd = attempts[nb_attempts].fd;
460  pfd[nb_attempts].events = POLLOUT;
461  next_attempt_us = av_gettime_relative() + NEXT_ATTEMPT_DELAY_MS * 1000;
462  nb_attempts++;
463  }
464 
465  av_assert0(nb_attempts > 0);
466  // The connection attempts are sorted from oldest to newest, so the
467  // first one will have the earliest deadline.
468  next_deadline_us = attempts[0].deadline_us;
469  // If we can start another attempt in parallel, wait until that time.
470  if (nb_attempts < parallel && addrs)
471  next_deadline_us = FFMIN(next_deadline_us, next_attempt_us);
472  last_err = ff_poll_interrupt(pfd, nb_attempts,
473  (next_deadline_us - av_gettime_relative())/1000,
474  &h->interrupt_callback);
475  if (last_err < 0 && last_err != AVERROR(ETIMEDOUT))
476  break;
477 
478  // Check the status from the poll output.
479  for (i = 0; i < nb_attempts; i++) {
480  last_err = 0;
481  if (pfd[i].revents) {
482  // Some sort of action for this socket, check its status (either
483  // a successful connection or an error).
484  optlen = sizeof(last_err);
485  if (getsockopt(attempts[i].fd, SOL_SOCKET, SO_ERROR, &last_err, &optlen))
486  last_err = ff_neterrno();
487  else if (last_err != 0)
488  last_err = AVERROR(last_err);
489  if (last_err == 0) {
490  // Everything is ok, we seem to have a successful
491  // connection. Close other sockets and return this one.
492  for (j = 0; j < nb_attempts; j++)
493  if (j != i)
494  closesocket(attempts[j].fd);
495  *fd = attempts[i].fd;
496  getnameinfo(attempts[i].addr->ai_addr, attempts[i].addr->ai_addrlen,
497  hostbuf, sizeof(hostbuf), portbuf, sizeof(portbuf),
499  av_log(h, AV_LOG_VERBOSE, "Successfully connected to %s port %s\n",
500  hostbuf, portbuf);
501  return 0;
502  }
503  }
504  if (attempts[i].deadline_us < av_gettime_relative() && !last_err)
505  last_err = AVERROR(ETIMEDOUT);
506  if (!last_err)
507  continue;
508  // Error (or timeout) for this socket; close the socket and remove
509  // it from the attempts/pfd arrays, to let a new attempt start
510  // directly.
511  getnameinfo(attempts[i].addr->ai_addr, attempts[i].addr->ai_addrlen,
512  hostbuf, sizeof(hostbuf), portbuf, sizeof(portbuf),
514  av_strerror(last_err, errbuf, sizeof(errbuf));
515  av_log(h, AV_LOG_VERBOSE, "Connection attempt to %s port %s "
516  "failed: %s\n", hostbuf, portbuf, errbuf);
517  closesocket(attempts[i].fd);
518  memmove(&attempts[i], &attempts[i + 1],
519  (nb_attempts - i - 1) * sizeof(*attempts));
520  memmove(&pfd[i], &pfd[i + 1],
521  (nb_attempts - i - 1) * sizeof(*pfd));
522  i--;
523  nb_attempts--;
524  }
525  }
526  for (i = 0; i < nb_attempts; i++)
527  closesocket(attempts[i].fd);
528  if (last_err >= 0)
529  last_err = AVERROR(ECONNREFUSED);
530  if (last_err != AVERROR_EXIT) {
531  av_strerror(last_err, errbuf, sizeof(errbuf));
532  av_log(h, AV_LOG_ERROR, "Connection to %s failed: %s\n",
533  h->filename, errbuf);
534  }
535  return last_err;
536 }
537 
538 static int match_host_pattern(const char *pattern, const char *hostname)
539 {
540  int len_p, len_h;
541  if (!strcmp(pattern, "*"))
542  return 1;
543  // Skip a possible *. at the start of the pattern
544  if (pattern[0] == '*')
545  pattern++;
546  if (pattern[0] == '.')
547  pattern++;
548  len_p = strlen(pattern);
549  len_h = strlen(hostname);
550  if (len_p > len_h)
551  return 0;
552  // Simply check if the end of hostname is equal to 'pattern'
553  if (!strcmp(pattern, &hostname[len_h - len_p])) {
554  if (len_h == len_p)
555  return 1; // Exact match
556  if (hostname[len_h - len_p - 1] == '.')
557  return 1; // The matched substring is a domain and not just a substring of a domain
558  }
559  return 0;
560 }
561 
562 int ff_http_match_no_proxy(const char *no_proxy, const char *hostname)
563 {
564  char *buf, *start;
565  int ret = 0;
566  if (!no_proxy)
567  return 0;
568  if (!hostname)
569  return 0;
570  buf = av_strdup(no_proxy);
571  if (!buf)
572  return 0;
573  start = buf;
574  while (start) {
575  char *sep, *next = NULL;
576  start += strspn(start, " ,");
577  sep = start + strcspn(start, " ,");
578  if (*sep) {
579  next = sep + 1;
580  *sep = '\0';
581  }
582  if (match_host_pattern(start, hostname)) {
583  ret = 1;
584  break;
585  }
586  start = next;
587  }
588  av_free(buf);
589  return ret;
590 }
591 
592 void ff_log_net_error(void *ctx, int level, const char* prefix)
593 {
594  char errbuf[100];
595  av_strerror(ff_neterrno(), errbuf, sizeof(errbuf));
596  av_log(ctx, level, "%s: %s\n", prefix, errbuf);
597 }
ConnectionAttempt::fd
int fd
Definition: network.c:354
ConnectionAttempt::addr
struct addrinfo * addr
Definition: network.c:356
av_gettime_relative
int64_t av_gettime_relative(void)
Get the current time in microseconds since some unspecified starting point.
Definition: time.c:56
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:186
level
uint8_t level
Definition: svq3.c:205
interleave_addrinfo
static void interleave_addrinfo(struct addrinfo *base)
Definition: network.c:308
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
cb
static double cb(void *priv, double x, double y)
Definition: vf_geq.c:246
NI_NUMERICSERV
#define NI_NUMERICSERV
Definition: network.h:203
ff_poll_interrupt
static int ff_poll_interrupt(struct pollfd *p, nfds_t nfds, int timeout, AVIOInterruptCB *cb)
Definition: network.c:164
ff_gnutls_init
void ff_gnutls_init(void)
Definition: tls_gnutls.c:55
ff_log_net_error
void ff_log_net_error(void *ctx, int level, const char *prefix)
Definition: network.c:592
AV_LOG_VERBOSE
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:196
base
uint8_t base
Definition: vp3data.h:128
print_address_list
static void print_address_list(void *ctx, const struct addrinfo *addr, const char *title)
Definition: network.c:339
ff_network_close
void ff_network_close(void)
Definition: network.c:121
ConnectionAttempt::deadline_us
int64_t deadline_us
Definition: network.c:355
IN6_IS_ADDR_MULTICAST
#define IN6_IS_ADDR_MULTICAST(a)
Definition: network.h:244
ff_network_init
int ff_network_init(void)
Definition: network.c:63
ff_tls_init
int ff_tls_init(void)
Definition: network.c:36
AVIOInterruptCB
Callback for checking whether to abort blocking functions.
Definition: avio.h:59
AVUNERROR
#define AVUNERROR(e)
Definition: error.h:46
ff_gnutls_deinit
void ff_gnutls_deinit(void)
Definition: tls_gnutls.c:66
ff_openssl_deinit
void ff_openssl_deinit(void)
Definition: tls_openssl.c:105
av_strerror
int av_strerror(int errnum, char *errbuf, size_t errbuf_size)
Put a description of the AVERROR code errnum in errbuf.
Definition: error.c:109
type
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf type
Definition: writing_filters.txt:86
ff_check_interrupt
int ff_check_interrupt(AVIOInterruptCB *cb)
Check if the user has requested to interrupt a blocking function associated with cb.
Definition: avio.c:854
ff_listen_bind
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:251
ff_openssl_init
int ff_openssl_init(void)
Definition: tls_openssl.c:75
avassert.h
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
customize_fd
static int customize_fd(void *ctx, int fd, int family)
Definition: tcp.c:77
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:40
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:201
ctx
AVFormatContext * ctx
Definition: movenc.c:49
av_usleep
int av_usleep(unsigned usec)
Sleep for a period of time.
Definition: time.c:84
ff_http_match_no_proxy
int ff_http_match_no_proxy(const char *no_proxy, const char *hostname)
Definition: network.c:562
NULL
#define NULL
Definition: coverity.c:32
ff_is_multicast_address
int ff_is_multicast_address(struct sockaddr *addr)
Definition: network.c:150
ff_listen_connect
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:263
ff_network_wait_fd_timeout
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:83
time.h
ff_neterrno
#define ff_neterrno()
Definition: network.h:68
addrinfo::ai_addr
struct sockaddr * ai_addr
Definition: network.h:143
addrinfo::ai_family
int ai_family
Definition: network.h:139
NI_NUMERICHOST
#define NI_NUMERICHOST
Definition: network.h:195
ff_accept
int ff_accept(int fd, int timeout, URLContext *h)
Poll for a single connection on the passed file descriptor.
Definition: network.c:233
addrinfo::ai_protocol
int ai_protocol
Definition: network.h:141
ff_socket_nonblock
int ff_socket_nonblock(int socket, int enable)
addrinfo::ai_next
struct addrinfo * ai_next
Definition: network.h:145
addrinfo::ai_addrlen
int ai_addrlen
Definition: network.h:142
URLContext
Definition: url.h:35
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
ff_network_sleep_interruptible
int ff_network_sleep_interruptible(int64_t timeout, AVIOInterruptCB *int_cb)
Waits for up to 'timeout' microseconds.
Definition: network.c:103
getnameinfo
#define getnameinfo
Definition: network.h:219
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
url.h
int_cb
const AVIOInterruptCB int_cb
Definition: ffmpeg.c:306
ConnectionAttempt
Definition: network.c:353
ff_connect_parallel
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:414
ff_tls_deinit
void ff_tls_deinit(void)
Definition: network.c:51
ret
ret
Definition: filter_design.txt:187
addrinfo::ai_socktype
int ai_socktype
Definition: network.h:140
network.h
ff_listen
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:215
tls.h
IN_MULTICAST
#define IN_MULTICAST(a)
Definition: network.h:241
av_strdup
char * av_strdup(const char *s)
Duplicate a string.
Definition: mem.c:272
mem.h
av_free
#define av_free(p)
Definition: tableprint_vlc.h:33
POLLING_TIME
#define POLLING_TIME
Definition: network.h:249
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
h
h
Definition: vp9dsp_template.c:2038
AVERROR_EXIT
#define AVERROR_EXIT
Immediate exit was requested; the called function should not be restarted.
Definition: error.h:58
ff_socket
int ff_socket(int af, int type, int proto, void *logctx)
Definition: network.c:188
addrinfo
Definition: network.h:137
NEXT_ATTEMPT_DELAY_MS
#define NEXT_ATTEMPT_DELAY_MS
Definition: network.c:412
int
int
Definition: ffmpeg_filter.c:424
match_host_pattern
static int match_host_pattern(const char *pattern, const char *hostname)
Definition: network.c:538
start_connect_attempt
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:361
ff_network_wait_fd
int ff_network_wait_fd(int fd, int write)
Definition: network.c:74