X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavformat%2Fnetwork.h;h=e3fda4d5e2da1975a99e636caa5d6cd3671443f1;hb=cd8087444bb459c7c62e21913adfef5ec09675cc;hp=f83c796a95a557d3687a2324e0b6841123b5f063;hpb=4aefe010e30861eb8cbe04aa47223bf64d207dce;p=ffmpeg diff --git a/libavformat/network.h b/libavformat/network.h index f83c796a95a..7f467304a80 100644 --- a/libavformat/network.h +++ b/libavformat/network.h @@ -59,6 +59,7 @@ int ff_neterrno(void); #include #include #include +#include #include #define ff_neterrno() AVERROR(errno) @@ -74,7 +75,6 @@ int ff_neterrno(void); int ff_socket_nonblock(int socket, int enable); -extern int ff_network_inited_globally; int ff_network_init(void); void ff_network_close(void); @@ -87,15 +87,22 @@ int ff_network_wait_fd(int fd, int write); * 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 + * @param fd Socket descriptor + * @param write Set 1 to wait for socket able to be read, 0 to be written + * @param timeout Timeout interval, in microseconds. Actual precision is 100000 mcs, due to ff_network_wait_fd usage * @param int_cb Interrupt callback, is checked before each ff_network_wait_fd call * @return 0 if data can be read/written, AVERROR(ETIMEDOUT) if timeout expired, or negative error code */ int ff_network_wait_fd_timeout(int fd, int write, int64_t timeout, AVIOInterruptCB *int_cb); -int ff_inet_aton (const char * str, struct in_addr * add); +/** + * Waits for up to 'timeout' microseconds. If the usert's int_cb is set and + * triggered, return before that. + * @param timeout Timeout in microseconds. Maybe have lower actual precision. + * @param int_cb Interrupt callback, is checked regularly. + * @return AVERROR(ETIMEDOUT) if timeout expirted, AVERROR_EXIT if interrupted by int_cb + */ +int ff_network_sleep_interruptible(int64_t timeout, AVIOInterruptCB *int_cb); #if !HAVE_STRUCT_SOCKADDR_STORAGE struct sockaddr_storage { @@ -297,4 +304,34 @@ int ff_http_match_no_proxy(const char *no_proxy, const char *hostname); int ff_socket(int domain, int type, int protocol); +void ff_log_net_error(void *ctx, int level, const char* prefix); + +/** + * Connect to any of the given addrinfo addresses, with multiple attempts + * running in parallel. + * + * @param 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. + * @param 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. + * @param parallel The maximum number of connections to attempt in parallel. + * This is limited to an internal maximum capacity. + * @param h URLContext providing interrupt check + * callback and logging context. + * @param fd If successful, the connected socket is returned here. + * @param 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. + * @param customize_ctx Context parameter passed to customize_fd. + * @return 0 on success, AVERROR on failure. + */ +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); + #endif /* AVFORMAT_NETWORK_H */