25 #include "libavutil/avutil.h"
26 #include "libavutil/mem.h"
27 #include "libavutil/time.h"
40 #include <openssl/ssl.h>
41 static int openssl_init;
43 #include <openssl/crypto.h>
45 static void openssl_lock(
int mode,
int type,
const char *file,
int line)
47 if (mode & CRYPTO_LOCK)
52 #if !defined(WIN32) && OPENSSL_VERSION_NUMBER < 0x10000000
53 static unsigned long openssl_thread_id(
void)
55 return (intptr_t) pthread_self();
61 #include <gnutls/gnutls.h>
62 #if HAVE_THREADS && GNUTLS_VERSION_NUMBER <= 0x020b00
65 GCRY_THREAD_OPTION_PTHREAD_IMPL;
75 SSL_load_error_strings();
77 if (!CRYPTO_get_locking_callback()) {
80 for (i = 0; i < CRYPTO_num_locks(); i++)
82 CRYPTO_set_locking_callback(openssl_lock);
83 #if !defined(WIN32) && OPENSSL_VERSION_NUMBER < 0x10000000
84 CRYPTO_set_id_callback(openssl_thread_id);
92 #if HAVE_THREADS && GNUTLS_VERSION_NUMBER < 0x020b00
93 if (gcry_control(GCRYCTL_ANY_INITIALIZATION_P) == 0)
94 gcry_control(GCRYCTL_SET_THREAD_CBS, &gcry_threads_pthread);
108 if (CRYPTO_get_locking_callback() == openssl_lock) {
110 CRYPTO_set_locking_callback(NULL);
111 for (i = 0; i < CRYPTO_num_locks(); i++)
119 gnutls_global_deinit();
132 if (!ff_network_inited_globally)
134 "network initialization. Please use "
135 "avformat_network_init(), this will "
136 "become mandatory later.\n");
138 if (WSAStartup(
MAKEWORD(1,1), &wsaData))
146 int ev = write ? POLLOUT : POLLIN;
147 struct pollfd p = { .fd = fd, .events = ev, .revents = 0 };
149 ret = poll(&p, 1, 100);
150 return ret < 0 ?
ff_neterrno() : p.revents & (ev | POLLERR | POLLHUP) ? 0 :
AVERROR(EAGAIN);
156 int64_t wait_start = 0;
183 int err = WSAGetLastError();
189 case WSAEPROTONOSUPPORT:
190 return AVERROR(EPROTONOSUPPORT);
193 case WSAECONNREFUSED:
204 if (addr->sa_family == AF_INET) {
205 return IN_MULTICAST(ntohl(((
struct sockaddr_in *)addr)->sin_addr.s_addr));
207 #if HAVE_STRUCT_SOCKADDR_IN6
208 if (addr->sa_family == AF_INET6) {
228 }
while (timeout <= 0 || runs-- > 0);
242 fd = socket(af, type | SOCK_CLOEXEC, proto);
243 if (fd == -1 && errno == EINVAL)
246 fd = socket(af, type, proto);
249 if (fcntl(fd, F_SETFD, FD_CLOEXEC) == -1)
258 socklen_t addrlen,
int timeout,
URLContext *h)
262 struct pollfd lp = { fd, POLLIN, 0 };
263 if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &reuse,
sizeof(reuse))) {
266 ret = bind(fd, addr, addrlen);
278 ret = accept(fd, NULL, NULL);
289 socklen_t addrlen,
int timeout,
URLContext *h,
292 struct pollfd p = {fd, POLLOUT, 0};
298 while ((ret = connect(fd, addr, addrlen))) {
310 optlen =
sizeof(
ret);
311 if (getsockopt (fd, SOL_SOCKET, SO_ERROR, &ret, &optlen))
319 "Connection to %s failed (%s), trying next address\n",
335 if (!strcmp(pattern,
"*"))
338 if (pattern[0] ==
'*')
340 if (pattern[0] ==
'.')
342 len_p = strlen(pattern);
343 len_h = strlen(hostname);
347 if (!strcmp(pattern, &hostname[len_h - len_p])) {
350 if (hostname[len_h - len_p - 1] ==
'.')
369 char *sep, *next = NULL;
370 start += strspn(start,
" ,");
371 sep = start + strcspn(start,
" ,");
static av_always_inline int pthread_mutex_destroy(pthread_mutex_t *mutex)
int avpriv_unlock_avformat(void)
#define AV_LOG_WARNING
Something somehow does not look correct.
char * av_strdup(const char *s) av_malloc_attrib
Duplicate the string s.
static int match_host_pattern(const char *pattern, const char *hostname)
AVIOInterruptCB interrupt_callback
os2threads to pthreads wrapper
void av_log(void *avcl, int level, const char *fmt,...) av_printf_format(3
Send the specified message to the log if the level is less than or equal to the current av_log_level...
void ff_network_close(void)
static int ff_poll_interrupt(struct pollfd *p, nfds_t nfds, int timeout, AVIOInterruptCB *cb)
int ff_socket(int af, int type, int proto)
int ff_network_inited_globally
#define IN6_IS_ADDR_MULTICAST(a)
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_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.
Callback for checking whether to abort blocking functions.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
const AVIOInterruptCB int_cb
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
int avpriv_lock_avformat(void)
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...
int64_t av_gettime(void)
Get the current time in microseconds.
void * av_malloc(size_t size) av_malloc_attrib 1(1)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
static av_always_inline int pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *attr)
int ff_http_match_no_proxy(const char *no_proxy, const char *hostname)
int ff_socket_nonblock(int socket, int enable)
int ff_check_interrupt(AVIOInterruptCB *cb)
Check if the user has requested to interrup a blocking function associated with cb.
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.
char * filename
specified URL
static av_always_inline int pthread_mutex_unlock(pthread_mutex_t *mutex)
w32threads to pthreads wrapper
int ff_network_wait_fd(int fd, int write)
unbuffered private I/O API
static av_always_inline int pthread_mutex_lock(pthread_mutex_t *mutex)