|
FFmpeg
|
#include <errno.h>#include <stdatomic.h>#include <stdint.h>#include "config.h"#include "libavutil/error.h"#include "os_support.h"#include "avio.h"#include "url.h"#include <sys/types.h>#include <sys/socket.h>#include <netinet/in.h>#include <netinet/tcp.h>#include <netdb.h>Go to the source code of this file.
Data Structures | |
| struct | FFNetWakeup |
| A channel for waking a thread that is blocked in ff_network_wait_fd_wakeup(), from another thread. More... | |
| struct | sockaddr_storage |
| union | sockaddr_union |
| struct | addrinfo |
Macros | |
| #define | ff_neterrno() |
| #define | MSG_NOSIGNAL 0 |
| #define | EAI_AGAIN 2 |
| #define | EAI_BADFLAGS 3 |
| #define | EAI_FAIL 4 |
| #define | EAI_FAMILY 5 |
| #define | EAI_MEMORY 6 |
| #define | EAI_NODATA 7 |
| #define | EAI_NONAME 8 |
| #define | EAI_SERVICE 9 |
| #define | EAI_SOCKTYPE 10 |
| #define | AI_PASSIVE 1 |
| #define | AI_CANONNAME 2 |
| #define | AI_NUMERICHOST 4 |
| #define | NI_NOFQDN 1 |
| #define | NI_NUMERICHOST 2 |
| #define | NI_NAMERQD 4 |
| #define | NI_NUMERICSERV 8 |
| #define | NI_DGRAM 16 |
| #define | getaddrinfo ff_getaddrinfo |
| #define | freeaddrinfo ff_freeaddrinfo |
| #define | getnameinfo ff_getnameinfo |
| #define | gai_strerror ff_gai_strerror |
| #define | INADDR_LOOPBACK 0x7f000001 |
| #define | INET_ADDRSTRLEN 16 |
| #define | INET6_ADDRSTRLEN INET_ADDRSTRLEN |
| #define | IN_MULTICAST(a) |
| #define | IN6_IS_ADDR_MULTICAST(a) |
| #define | POLLING_TIME 100 |
Functions | |
| int | ff_socket_nonblock (int socket, int enable) |
| int | ff_network_init (void) |
| Initialize the network subsystem. | |
| void | ff_network_close (void) |
| int | ff_tls_init (void) |
| void | ff_tls_deinit (void) |
| int | ff_network_wait_fd (int fd, int write) |
| 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_wait_fd in a loop. | |
| int | ff_network_sleep_interruptible (int64_t timeout, AVIOInterruptCB *int_cb) |
| Waits for up to 'timeout' microseconds. | |
| int | ff_network_wakeup_open (FFNetWakeup *w) |
| Create a wakeup channel. | |
| 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 it: the signal is not consumed, so a signal sent before the wait starts is not lost. | |
| void | ff_network_wakeup_close (FFNetWakeup *w) |
| Close the channel. | |
| int | ff_network_wait_fd_wakeup (int fd, int write, int timeout_ms, const FFNetWakeup *w) |
| Like ff_network_wait_fd(), but also returns as soon as the wakeup channel is signaled, and with a caller chosen timeout. | |
| int | ff_getaddrinfo (const char *node, const char *service, const struct addrinfo *hints, struct addrinfo **res) |
| void | ff_freeaddrinfo (struct addrinfo *res) |
| int | ff_getnameinfo (const struct sockaddr *sa, int salen, char *host, int hostlen, char *serv, int servlen, int flags) |
| const char * | ff_gai_strerror (int ecode) |
| int | ff_is_multicast_address (struct sockaddr *addr) |
| 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_listen (int fd, const struct sockaddr *addr, socklen_t addrlen, void *logctx) |
| Bind to a file descriptor to an address without accepting connections. | |
| int | ff_accept (int fd, int timeout, URLContext *h) |
| Poll for a single connection on the passed file descriptor. | |
| 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_http_match_no_proxy (const char *no_proxy, const char *hostname) |
| int | ff_socket (int domain, int type, int protocol, void *logctx) |
| void | ff_log_net_error (void *ctx, int level, const char *prefix) |
| 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. | |
| void | ff_udp_get_last_recv_addr (URLContext *h, struct sockaddr_storage *addr, socklen_t *addr_len) |
| int | ff_udp_set_remote_addr (URLContext *h, const struct sockaddr *dest_addr, socklen_t dest_addr_len, int do_connect) |
| This function is identical to ff_udp_set_remote_url, except that it takes a sockaddr directly. | |
| #define ff_neterrno | ( | ) |
Definition at line 69 of file network.h.
Referenced by dtls_handshake(), ff_accept(), ff_connect_parallel(), ff_listen(), ff_listen_connect(), ff_log_net_error(), ff_network_wait_fd(), ff_network_wait_fd_wakeup(), ff_network_wakeup_open(), ff_network_wakeup_signal(), ff_poll_interrupt(), rtp_read(), rtp_write(), sctp_open(), sctp_read(), sctp_wait_fd(), sctp_write(), start_connect_attempt(), tcp_get_window_size(), tcp_open(), tcp_read(), tcp_write(), udp_join_multicast_group(), udp_open(), udp_read(), udp_set_multicast_sources(), udp_set_multicast_ttl(), udp_write(), unix_open(), unix_read(), and unix_write().
| #define MSG_NOSIGNAL 0 |
Definition at line 196 of file network.h.
Referenced by ff_sctp_send(), sctp_write(), tcp_write(), and unix_write().
| #define AI_PASSIVE 1 |
Definition at line 242 of file network.h.
Referenced by libsrt_setup(), tcp_open(), and udp_socket_create().
| #define AI_NUMERICHOST 4 |
Definition at line 250 of file network.h.
Referenced by ff_tls_parse_host(), ff_url_join(), get_sockaddr(), and tls_open().
| #define NI_NUMERICHOST 2 |
Definition at line 258 of file network.h.
Referenced by ff_connect_parallel(), and print_address_list().
| #define NI_NUMERICSERV 8 |
Definition at line 266 of file network.h.
Referenced by ff_connect_parallel(), print_address_list(), and udp_port().
| #define getaddrinfo ff_getaddrinfo |
Definition at line 280 of file network.h.
Referenced by customize_fd(), ff_ip_resolve_host(), ff_tls_parse_host(), ff_url_join(), get_sockaddr(), libsrt_setup(), sap_write_header(), sctp_open(), tcp_open(), and tls_open().
| #define freeaddrinfo ff_freeaddrinfo |
Definition at line 281 of file network.h.
Referenced by customize_fd(), ff_tls_parse_host(), ff_url_join(), get_sockaddr(), ip_parse_addr_list(), libsrt_setup(), sap_write_header(), sctp_open(), tcp_open(), tls_open(), udp_set_url(), and udp_socket_create().
| #define getnameinfo ff_getnameinfo |
Definition at line 282 of file network.h.
Referenced by ff_connect_parallel(), print_address_list(), and udp_port().
| #define gai_strerror ff_gai_strerror |
Definition at line 288 of file network.h.
Referenced by customize_fd(), ff_ip_resolve_host(), get_sockaddr(), libsrt_setup(), sctp_open(), tcp_open(), and udp_port().
| #define INADDR_LOOPBACK 0x7f000001 |
Definition at line 292 of file network.h.
Referenced by ff_network_wakeup_open().
| #define INET6_ADDRSTRLEN INET_ADDRSTRLEN |
| #define IN_MULTICAST | ( | a | ) |
Definition at line 304 of file network.h.
Referenced by ff_is_multicast_address().
| #define IN6_IS_ADDR_MULTICAST | ( | a | ) |
Definition at line 307 of file network.h.
Referenced by ff_is_multicast_address().
| #define POLLING_TIME 100 |
Definition at line 312 of file network.h.
Referenced by ff_network_sleep_interruptible(), ff_network_wait_fd(), ff_poll_interrupt(), librist_read(), libsrt_network_wait_fd(), rtp_read(), and zmq_proto_wait().
| int ff_socket_nonblock | ( | int | socket, |
| int | enable ) |
Referenced by ff_accept(), ff_listen_connect(), start_connect_attempt(), udp_connect(), and udp_open().
| int ff_network_init | ( | void | ) |
Initialize the network subsystem.
On Windows, this calls WSAStartup().
Definition at line 66 of file network.c.
Referenced by avformat_network_init(), rtsp_listen(), sap_read_header(), sap_write_header(), and url_alloc_for_protocol().
| void ff_network_close | ( | void | ) |
Definition at line 239 of file network.c.
Referenced by avformat_network_deinit(), ffurl_closep(), rtsp_listen(), rtsp_read_close(), rtsp_write_close(), sap_read_close(), sap_write_close(), and url_alloc_for_protocol().
| int ff_tls_init | ( | void | ) |
Definition at line 42 of file network.c.
Referenced by avformat_network_init().
| void ff_tls_deinit | ( | void | ) |
Definition at line 52 of file network.c.
Referenced by avformat_network_deinit().
| int ff_network_wait_fd | ( | int | fd, |
| int | write ) |
Definition at line 77 of file network.c.
Referenced by ff_network_wait_fd_timeout(), rtp_write(), udp_read(), udp_write(), unix_read(), and unix_write().
| 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_wait_fd in a loop.
| fd | Socket descriptor |
| write | Set 1 to wait for socket able to be read, 0 to be written |
| timeout | Timeout interval, in microseconds. Actual precision is 100000 mcs, due to ff_network_wait_fd usage |
| int_cb | Interrupt callback, is checked before each ff_network_wait_fd call |
Definition at line 86 of file network.c.
Referenced by amqp_proto_read(), amqp_proto_write(), tcp_read(), and tcp_write().
| int ff_network_sleep_interruptible | ( | int64_t | timeout, |
| AVIOInterruptCB * | int_cb ) |
Waits for up to 'timeout' microseconds.
If the usert's int_cb is set and triggered, return before that.
| timeout | Timeout in microseconds. Maybe have lower actual precision. |
| int_cb | Interrupt callback, is checked regularly. |
Definition at line 221 of file network.c.
Referenced by http_open_cnx(), and http_read_stream().
| int ff_network_wakeup_open | ( | FFNetWakeup * | w | ) |
Create a wakeup channel.
On Windows ff_network_init() must have been called first.
Definition at line 106 of file network.c.
Referenced by udp_open().
| 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 it: the signal is not consumed, so a signal sent before the wait starts is not lost.
Only the first call has an effect; the function may be called any number of times, from any thread.
Definition at line 162 of file network.c.
Referenced by udp_close().
| void ff_network_wakeup_close | ( | FFNetWakeup * | w | ) |
Close the channel.
Call it after the waiting thread has been joined and no thread can signal any more.
Definition at line 185 of file network.c.
Referenced by udp_close(), and udp_open().
| int ff_network_wait_fd_wakeup | ( | int | fd, |
| int | write, | ||
| int | timeout_ms, | ||
| const FFNetWakeup * | w ) |
Like ff_network_wait_fd(), but also returns as soon as the wakeup channel is signaled, and with a caller chosen timeout.
| fd | Socket descriptor |
| write | Set 1 to wait for the socket to be writable, 0 for readable |
| timeout_ms | Timeout in milliseconds, or -1 to wait indefinitely |
| w | Wakeup channel to watch, must have been opened |
| int ff_getaddrinfo | ( | const char * | node, |
| const char * | service, | ||
| const struct addrinfo * | hints, | ||
| struct addrinfo ** | res ) |
| void ff_freeaddrinfo | ( | struct addrinfo * | res | ) |
| int ff_getnameinfo | ( | const struct sockaddr * | sa, |
| int | salen, | ||
| char * | host, | ||
| int | hostlen, | ||
| char * | serv, | ||
| int | servlen, | ||
| int | flags ) |
| const char * ff_gai_strerror | ( | int | ecode | ) |
| int ff_is_multicast_address | ( | struct sockaddr * | addr | ) |
Definition at line 268 of file network.c.
Referenced by ff_udp_set_remote_addr(), and ff_udp_set_remote_url().
| 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.
| fd | First argument of bind(). |
| addr | Second argument of bind(). |
| addrlen | Third argument of bind(). |
| timeout | Polling timeout in milliseconds. |
| h | URLContext providing interrupt check callback and logging context. |
Definition at line 369 of file network.c.
Referenced by sctp_open(), tcp_open(), and unix_open().
| 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.
| fd | First argument of bind(). |
| addr | Second argument of bind(). |
| addrlen | Third argument of bind(). |
Definition at line 333 of file network.c.
Referenced by ff_listen_bind(), and tcp_open().
| int ff_accept | ( | int | fd, |
| int | timeout, | ||
| URLContext * | h ) |
Poll for a single connection on the passed file descriptor.
| fd | The listening socket file descriptor. |
| timeout | Polling timeout in milliseconds. |
| h | URLContext providing interrupt check callback and logging context. |
Definition at line 351 of file network.c.
Referenced by ff_listen_bind(), and tcp_accept().
| 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.
| fd | First argument of connect(), will be set as non-blocking. |
| addr | Second argument of connect(). |
| addrlen | Third argument of connect(). |
| timeout | Polling timeout in milliseconds. |
| h | URLContext providing interrupt check callback and logging context. |
| will_try_next | Whether the caller will try to connect to another address for the same host name, affecting the form of logged errors. |
Definition at line 381 of file network.c.
Referenced by sctp_open(), and unix_open().
| int ff_http_match_no_proxy | ( | const char * | no_proxy, |
| const char * | hostname ) |
Definition at line 676 of file network.c.
Referenced by ff_tls_open_underlying(), http_open_cnx_internal(), and test().
| int ff_socket | ( | int | domain, |
| int | type, | ||
| int | protocol, | ||
| void * | logctx ) |
Definition at line 306 of file network.c.
Referenced by ff_network_wakeup_open(), sctp_open(), start_connect_attempt(), tcp_open(), udp_socket_create(), and unix_open().
| void ff_log_net_error | ( | void * | ctx, |
| int | level, | ||
| const char * | prefix ) |
Definition at line 706 of file network.c.
Referenced by customize_fd(), ff_udp_set_remote_addr(), ff_udp_set_remote_url(), udp_join_multicast_group(), udp_leave_multicast_group(), udp_open(), udp_set_multicast_sources(), udp_set_multicast_ttl(), and udp_socket_create().
| 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.
| addrs | The list of addresses to try to connect to. This list will be mutated internally, but the list head will remain as such, so this doesn't affect the caller freeing the list afterwards. |
| timeout_ms_per_address | The number of milliseconds to wait for each connection attempt. Since multiple addresses are tried, some of them in parallel, the total run time will at most be timeout_ms_per_address*ceil(nb_addrs/parallel) + (parallel - 1) * NEXT_ATTEMPT_DELAY_MS. |
| parallel | The maximum number of connections to attempt in parallel. This is limited to an internal maximum capacity. |
| h | URLContext providing interrupt check callback and logging context. |
| fd | If successful, the connected socket is returned here. |
| customize_fd | Function that will be called for each socket created, to allow the caller to set socket options before calling connect() on it, may be NULL. |
| customize_ctx | Context parameter passed to customize_fd. |
Definition at line 531 of file network.c.
Referenced by tcp_open().
| void ff_udp_get_last_recv_addr | ( | URLContext * | h, |
| struct sockaddr_storage * | addr, | ||
| socklen_t * | addr_len ) |
Definition at line 510 of file udp.c.
Referenced by gnutls_url_pull(), mbedtls_recv(), tls_handshake_loop(), and url_bio_bread().
| int ff_udp_set_remote_addr | ( | URLContext * | h, |
| const struct sockaddr * | dest_addr, | ||
| socklen_t | dest_addr_len, | ||
| int | do_connect ) |
This function is identical to ff_udp_set_remote_url, except that it takes a sockaddr directly.
Definition at line 472 of file udp.c.
Referenced by gnutls_url_pull(), mbedtls_recv(), tls_handshake_loop(), and url_bio_bread().