Go to the documentation of this file.
22 #include "config_components.h"
24 #if CONFIG_TLS_PROTOCOL && CONFIG_OPENSSL
25 #include <openssl/opensslv.h>
38 #if CONFIG_TLS_PROTOCOL
39 #if CONFIG_OPENSSL && OPENSSL_VERSION_NUMBER < 0x10100000L
53 #if CONFIG_TLS_PROTOCOL
54 #if CONFIG_OPENSSL && OPENSSL_VERSION_NUMBER < 0x10100000L
68 if (WSAStartup(MAKEWORD(1,1), &wsaData))
76 int ev = write ? POLLOUT : POLLIN;
77 struct pollfd p = { .fd = fd, .events = ev, .revents = 0 };
86 int64_t wait_start = 0;
131 int err = WSAGetLastError();
137 case WSAEPROTONOSUPPORT:
138 return AVERROR(EPROTONOSUPPORT);
141 case WSAECONNREFUSED:
152 if (addr->sa_family == AF_INET) {
153 return IN_MULTICAST(ntohl(((
struct sockaddr_in *)addr)->sin_addr.s_addr));
155 #if HAVE_STRUCT_SOCKADDR_IN6
156 if (addr->sa_family == AF_INET6) {
181 }
while (timeout <= 0 || runs-- > 0);
193 fd = socket(af,
type | SOCK_CLOEXEC, proto);
194 if (fd == -1 && errno == EINVAL)
197 fd = socket(af,
type, proto);
200 if (fcntl(fd, F_SETFD, FD_CLOEXEC) == -1)
207 if (setsockopt(fd, SOL_SOCKET, SO_NOSIGPIPE, &(
int){1},
sizeof(
int))) {
216 socklen_t addrlen,
void *logctx)
220 if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &reuse,
sizeof(reuse))) {
223 ret = bind(fd, addr, addrlen);
236 struct pollfd lp = { fd, POLLIN, 0 };
267 struct pollfd p = {fd, POLLOUT, 0};
274 while ((
ret = connect(fd, addr, addrlen))) {
286 optlen =
sizeof(
ret);
287 if (getsockopt (fd, SOL_SOCKET, SO_ERROR, &
ret, &optlen))
295 "Connection to %s failed (%s), trying next address\n",
296 h->filename, errbuf);
299 h->filename, errbuf);
318 if (cur ==
base->ai_next) {
322 next = &
base->ai_next;
342 char hostbuf[100], portbuf[20];
346 hostbuf,
sizeof(hostbuf), portbuf,
sizeof(portbuf),
362 struct addrinfo **ptr,
int timeout_ms,
364 int (*
customize_fd)(
void *,
int,
int),
void *customize_ctx)
382 closesocket(attempt->
fd);
393 closesocket(attempt->
fd);
402 closesocket(attempt->
fd);
412 #define NEXT_ATTEMPT_DELAY_MS 200
416 int (*
customize_fd)(
void *,
int,
int),
void *customize_ctx)
419 struct pollfd pfd[3];
420 int nb_attempts = 0,
i, j;
424 char errbuf[100], hostbuf[100], portbuf[20];
436 while (nb_attempts > 0 || addrs) {
438 if (nb_attempts < parallel && addrs) {
440 hostbuf,
sizeof(hostbuf), portbuf,
sizeof(portbuf),
445 timeout_ms_per_address,
h,
454 for (
i = 0;
i < nb_attempts;
i++)
455 closesocket(attempts[
i].fd);
456 *fd = attempts[nb_attempts].
fd;
459 pfd[nb_attempts].fd = attempts[nb_attempts].
fd;
460 pfd[nb_attempts].events = POLLOUT;
470 if (nb_attempts < parallel && addrs)
471 next_deadline_us =
FFMIN(next_deadline_us, next_attempt_us);
474 &
h->interrupt_callback);
475 if (last_err < 0 && last_err !=
AVERROR(ETIMEDOUT))
479 for (
i = 0;
i < nb_attempts;
i++) {
481 if (pfd[
i].revents) {
484 optlen =
sizeof(last_err);
485 if (getsockopt(attempts[
i].fd, SOL_SOCKET, SO_ERROR, &last_err, &optlen))
487 else if (last_err != 0)
492 for (j = 0; j < nb_attempts; j++)
494 closesocket(attempts[j].fd);
495 *fd = attempts[
i].
fd;
497 hostbuf,
sizeof(hostbuf), portbuf,
sizeof(portbuf),
512 hostbuf,
sizeof(hostbuf), portbuf,
sizeof(portbuf),
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));
526 for (
i = 0;
i < nb_attempts;
i++)
527 closesocket(attempts[
i].fd);
529 last_err =
AVERROR(ECONNREFUSED);
533 h->filename, errbuf);
541 if (!strcmp(pattern,
"*"))
544 if (pattern[0] ==
'*')
546 if (pattern[0] ==
'.')
548 len_p = strlen(pattern);
549 len_h = strlen(hostname);
553 if (!strcmp(pattern, &hostname[len_h - len_p])) {
556 if (hostname[len_h - len_p - 1] ==
'.')
575 char *sep, *next =
NULL;
576 start += strspn(start,
" ,");
577 sep = start + strcspn(start,
" ,");
int64_t av_gettime_relative(void)
Get the current time in microseconds since some unspecified starting point.
#define AV_LOG_WARNING
Something somehow does not look correct.
static void interleave_addrinfo(struct addrinfo *base)
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
static double cb(void *priv, double x, double y)
static int ff_poll_interrupt(struct pollfd *p, nfds_t nfds, int timeout, AVIOInterruptCB *cb)
void ff_gnutls_init(void)
void ff_log_net_error(void *ctx, int level, const char *prefix)
#define AV_LOG_VERBOSE
Detailed information.
static void print_address_list(void *ctx, const struct addrinfo *addr, const char *title)
void ff_network_close(void)
#define IN6_IS_ADDR_MULTICAST(a)
int ff_network_init(void)
Callback for checking whether to abort blocking functions.
void ff_gnutls_deinit(void)
void ff_openssl_deinit(void)
int av_strerror(int errnum, char *errbuf, size_t errbuf_size)
Put a description of the AVERROR code errnum in errbuf.
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
int ff_check_interrupt(AVIOInterruptCB *cb)
Check if the user has requested to interrupt a blocking function associated with cb.
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.
int ff_openssl_init(void)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define FF_ARRAY_ELEMS(a)
static int customize_fd(void *ctx, int fd, int family)
#define av_assert0(cond)
assert() equivalent, that is always enabled.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
int av_usleep(unsigned usec)
Sleep for a period of time.
int ff_http_match_no_proxy(const char *no_proxy, const char *hostname)
int ff_is_multicast_address(struct sockaddr *addr)
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.
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...
struct sockaddr * ai_addr
int ff_accept(int fd, int timeout, URLContext *h)
Poll for a single connection on the passed file descriptor.
int ff_socket_nonblock(int socket, int enable)
struct addrinfo * ai_next
#define i(width, name, range_min, range_max)
int ff_network_sleep_interruptible(int64_t timeout, AVIOInterruptCB *int_cb)
Waits for up to 'timeout' microseconds.
const AVIOInterruptCB int_cb
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.
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.
char * av_strdup(const char *s)
Duplicate a string.
#define AVERROR_EXIT
Immediate exit was requested; the called function should not be restarted.
int ff_socket(int af, int type, int proto, void *logctx)
#define NEXT_ATTEMPT_DELAY_MS
static int match_host_pattern(const char *pattern, const char *hostname)
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)
int ff_network_wait_fd(int fd, int write)