33 #if CONFIG_TLS_PROTOCOL
48 #if CONFIG_TLS_PROTOCOL
63 if (WSAStartup(
MAKEWORD(1,1), &wsaData))
71 int ev = write ? POLLOUT : POLLIN;
72 struct pollfd p = { .fd = fd, .events = ev, .revents = 0 };
75 return ret < 0 ?
ff_neterrno() : p.revents & (ev | POLLERR | POLLHUP) ? 0 :
AVERROR(EAGAIN);
81 int64_t wait_start = 0;
126 int err = WSAGetLastError();
132 case WSAEPROTONOSUPPORT:
133 return AVERROR(EPROTONOSUPPORT);
136 case WSAECONNREFUSED:
147 if (addr->sa_family == AF_INET) {
148 return IN_MULTICAST(ntohl(((
struct sockaddr_in *)addr)->sin_addr.s_addr));
150 #if HAVE_STRUCT_SOCKADDR_IN6
151 if (addr->sa_family == AF_INET6) {
176 }
while (timeout <= 0 || runs-- > 0);
188 fd = socket(af, type | SOCK_CLOEXEC, proto);
189 if (fd == -1 && errno == EINVAL)
192 fd = socket(af, type, proto);
195 if (fcntl(fd, F_SETFD, FD_CLOEXEC) == -1)
202 if (setsockopt(fd, SOL_SOCKET, SO_NOSIGPIPE, &(
int){1},
sizeof(
int))) {
215 if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &reuse,
sizeof(reuse))) {
218 ret = bind(fd, addr, addrlen);
231 struct pollfd lp = { fd, POLLIN, 0 };
250 if ((ret =
ff_listen(fd, addr, addrlen)) < 0)
252 if ((ret =
ff_accept(fd, timeout, h)) < 0)
262 struct pollfd p = {fd, POLLOUT, 0};
269 while ((ret = connect(fd, addr, addrlen))) {
281 optlen =
sizeof(ret);
282 if (getsockopt (fd, SOL_SOCKET, SO_ERROR, &ret, &optlen))
290 "Connection to %s failed (%s), trying next address\n",
337 char hostbuf[100], portbuf[20];
341 hostbuf,
sizeof(hostbuf), portbuf,
sizeof(portbuf),
357 struct addrinfo **ptr,
int timeout_ms,
382 closesocket(attempt->
fd);
391 closesocket(attempt->
fd);
401 #define NEXT_ATTEMPT_DELAY_MS 200
408 struct pollfd pfd[3];
409 int nb_attempts = 0, i, j;
413 char errbuf[100], hostbuf[100], portbuf[20];
425 while (nb_attempts > 0 || addrs) {
427 if (nb_attempts < parallel && addrs) {
429 hostbuf,
sizeof(hostbuf), portbuf,
sizeof(portbuf),
434 timeout_ms_per_address, h,
443 for (i = 0; i < nb_attempts; i++)
444 closesocket(attempts[i].fd);
445 *fd = attempts[nb_attempts].
fd;
448 pfd[nb_attempts].fd = attempts[nb_attempts].
fd;
449 pfd[nb_attempts].events = POLLOUT;
459 if (nb_attempts < parallel && addrs)
460 next_deadline_us =
FFMIN(next_deadline_us, next_attempt_us);
464 if (last_err < 0 && last_err !=
AVERROR(ETIMEDOUT))
468 for (i = 0; i < nb_attempts; i++) {
470 if (pfd[i].revents) {
473 optlen =
sizeof(last_err);
474 if (getsockopt(attempts[i].fd, SOL_SOCKET, SO_ERROR, &last_err, &optlen))
476 else if (last_err != 0)
481 for (j = 0; j < nb_attempts; j++)
483 closesocket(attempts[j].fd);
484 *fd = attempts[i].
fd;
486 hostbuf,
sizeof(hostbuf), portbuf,
sizeof(portbuf),
501 hostbuf,
sizeof(hostbuf), portbuf,
sizeof(portbuf),
505 "failed: %s\n", hostbuf, portbuf, errbuf);
506 closesocket(attempts[i].fd);
507 memmove(&attempts[i], &attempts[i + 1],
508 (nb_attempts - i - 1) *
sizeof(*attempts));
509 memmove(&pfd[i], &pfd[i + 1],
510 (nb_attempts - i - 1) *
sizeof(*pfd));
515 for (i = 0; i < nb_attempts; i++)
516 closesocket(attempts[i].fd);
518 last_err =
AVERROR(ECONNREFUSED);
530 if (!strcmp(pattern,
"*"))
533 if (pattern[0] ==
'*')
535 if (pattern[0] ==
'.')
537 len_p = strlen(pattern);
538 len_h = strlen(hostname);
542 if (!strcmp(pattern, &hostname[len_h - len_p])) {
545 if (hostname[len_h - len_p - 1] ==
'.')
564 char *sep, *next =
NULL;
565 start += strspn(start,
" ,");
566 sep = start + strcspn(start,
" ,");
585 av_log(ctx, level,
"%s: %s\n", prefix, errbuf);
#define AV_LOG_WARNING
Something somehow does not look correct.
static void customize_fd(void *ctx, int fd)
Memory handling functions.
#define NEXT_ATTEMPT_DELAY_MS
static int match_host_pattern(const char *pattern, const char *hostname)
AVIOInterruptCB interrupt_callback
Convenience header that includes libavutil's core.
void ff_network_close(void)
static int ff_poll_interrupt(struct pollfd *p, nfds_t nfds, int timeout, AVIOInterruptCB *cb)
int av_usleep(unsigned usec)
Sleep for a period of time.
int ff_socket(int af, int type, int proto)
#define IN6_IS_ADDR_MULTICAST(a)
#define av_assert0(cond)
assert() equivalent, that is always enabled.
static double cb(void *priv, double x, double y)
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_network_init(void)
int ff_openssl_init(void)
int ff_listen(int fd, const struct sockaddr *addr, socklen_t addrlen)
Bind to a file descriptor to an address without accepting connections.
void ff_gnutls_init(void)
#define AV_LOG_VERBOSE
Detailed information.
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.
static void print_address_list(void *ctx, const struct addrinfo *addr, const char *title)
Callback for checking whether to abort blocking functions.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
int ff_accept(int fd, int timeout, URLContext *h)
Poll for a single connection on the passed file descriptor.
const AVIOInterruptCB int_cb
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
simple assert() macros that are a bit more flexible than ISO C assert().
int ff_is_multicast_address(struct sockaddr *addr)
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...
static int start_connect_attempt(struct ConnectionAttempt *attempt, struct addrinfo **ptr, int timeout_ms, URLContext *h, void(*customize_fd)(void *, int), void *customize_ctx)
int ff_network_sleep_interruptible(int64_t timeout, AVIOInterruptCB *int_cb)
Waits for up to 'timeout' microseconds.
int ff_connect_parallel(struct addrinfo *addrs, int timeout_ms_per_address, int parallel, URLContext *h, int *fd, void(*customize_fd)(void *, int), void *customize_ctx)
Connect to any of the given addrinfo addresses, with multiple attempts running in parallel...
int ff_http_match_no_proxy(const char *no_proxy, const char *hostname)
int ff_socket_nonblock(int socket, int enable)
#define AVERROR_EXIT
Immediate exit was requested; the called function should not be restarted.
#define FF_ARRAY_ELEMS(a)
char * av_strdup(const char *s)
Duplicate a string.
int ff_check_interrupt(AVIOInterruptCB *cb)
Check if the user has requested to interrupt a blocking function associated with cb.
void ff_gnutls_deinit(void)
int64_t av_gettime_relative(void)
Get the current time in microseconds since some unspecified starting point.
int av_strerror(int errnum, char *errbuf, size_t errbuf_size)
Put a description of the AVERROR code errnum in errbuf.
common internal api header.
struct addrinfo * ai_next
char * filename
specified URL
int ff_network_wait_fd(int fd, int write)
void ff_openssl_deinit(void)
unbuffered private I/O API
struct sockaddr * ai_addr
static void interleave_addrinfo(struct addrinfo *base)
void ff_log_net_error(void *ctx, int level, const char *prefix)