50 #define OFFSET(x) offsetof(TCPContext, x)
51 #define D AV_OPT_FLAG_DECODING_PARAM
52 #define E AV_OPT_FLAG_ENCODING_PARAM
54 {
"listen",
"Listen for incoming connections",
OFFSET(listen),
AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 2, .flags =
D|
E },
55 {
"timeout",
"set timeout (in microseconds) of socket I/O operations",
OFFSET(rw_timeout),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, .flags =
D|
E },
56 {
"listen_timeout",
"Connection awaiting timeout (in milliseconds)",
OFFSET(listen_timeout),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, .flags =
D|
E },
57 {
"send_buffer_size",
"Socket send buffer size (in bytes)",
OFFSET(send_buffer_size),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, .flags =
D|
E },
58 {
"recv_buffer_size",
"Socket receive buffer size (in bytes)",
OFFSET(recv_buffer_size),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, .flags =
D|
E },
59 {
"tcp_nodelay",
"Use TCP_NODELAY to disable nagle's algorithm",
OFFSET(tcp_nodelay),
AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, .flags =
D|
E },
61 {
"tcp_mss",
"Maximum segment size for outgoing TCP packets",
OFFSET(tcp_mss),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, .flags =
D|
E },
95 if (setsockopt (fd, IPPROTO_TCP, TCP_MAXSEG, &s->
tcp_mss, sizeof (s->
tcp_mss))) {
105 struct addrinfo hints = { 0 }, *ai, *cur_ai;
111 char hostname[1024],proto[1024],path[1024];
116 &port, path,
sizeof(path), uri);
117 if (strcmp(proto,
"tcp"))
119 if (port <= 0 || port >= 65536) {
123 p = strchr(uri,
'?');
127 s->
listen = strtol(buf, &endptr, 10);
145 snprintf(portstr,
sizeof(portstr),
"%d", port);
154 "Failed to resolve hostname %s: %s\n",
161 #if HAVE_STRUCT_SOCKADDR_IN6
163 if (cur_ai->ai_family == AF_INET6){
164 struct sockaddr_in6 * sockaddr_v6 = (
struct sockaddr_in6 *)cur_ai->ai_addr;
165 if (!sockaddr_v6->sin6_port){
166 sockaddr_v6->sin6_port = htons(port);
172 while (cur_ai && fd < 0) {
175 cur_ai->ai_protocol);
178 cur_ai = cur_ai->ai_next;
188 if ((ret =
ff_listen(fd, cur_ai->ai_addr, cur_ai->ai_addrlen)) < 0)
190 }
else if (s->
listen == 1) {
192 if ((ret =
ff_listen_bind(fd, cur_ai->ai_addr, cur_ai->ai_addrlen,
224 cc = (*c)->priv_data;
244 ret = recv(s->
fd, buf, size, 0);
277 return shutdown(s->
fd, how);
297 socklen_t avail_len =
sizeof(avail);
307 if (getsockopt(s->
fd, SOL_SOCKET, SO_RCVBUF, &avail, &avail_len)) {
325 .priv_data_class = &tcp_class,
void av_url_split(char *proto, int proto_size, char *authorization, int authorization_size, char *hostname, int hostname_size, int *port_ptr, char *path, int path_size, const char *url)
Split a URL string into components.
#define URL_PROTOCOL_FLAG_NETWORK
static const AVClass tcp_class
static int tcp_open(URLContext *h, const char *uri, int flags)
#define AV_LOG_WARNING
Something somehow does not look correct.
static void customize_fd(void *ctx, int fd)
#define LIBAVUTIL_VERSION_INT
int is_streamed
true if streamed (no seek possible), default = false
AVIOInterruptCB interrupt_callback
#define AVIO_FLAG_READ
read-only
const char * av_default_item_name(void *ptr)
Return the context name.
int64_t rw_timeout
maximum time to wait for (network) read/write operation completion, in mcs
#define AVIO_FLAG_WRITE
write-only
int ff_socket(int af, int type, int proto)
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
#define av_assert0(cond)
assert() equivalent, that is always enabled.
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.
miscellaneous OS support macros and functions.
int ff_listen(int fd, const struct sockaddr *addr, socklen_t addrlen)
Bind to a file descriptor to an address without accepting connections.
#define AVERROR_EOF
End of file.
int av_find_info_tag(char *arg, int arg_size, const char *tag1, const char *info)
Attempt to find a specific tag in a URL.
int ffurl_alloc(URLContext **puc, const char *filename, int flags, const AVIOInterruptCB *int_cb)
Create a URLContext for accessing to the resource indicated by url, but do not initiate the connectio...
static int tcp_read(URLContext *h, uint8_t *buf, int size)
#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.
simple assert() macros that are a bit more flexible than ISO C assert().
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 const AVOption options[]
static int tcp_close(URLContext *h)
static int tcp_shutdown(URLContext *h, int flags)
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...
static int tcp_get_window_size(URLContext *h)
const URLProtocol ff_tcp_protocol
int ffurl_closep(URLContext **hh)
Close the resource accessed by the URLContext h, and free the memory used by it.
#define AVIO_FLAG_NONBLOCK
Use non-blocking mode.
Describe the class of an AVClass context structure.
#define flags(name, subs,...)
char * filename
specified URL
static int tcp_write(URLContext *h, const uint8_t *buf, int size)
unbuffered private I/O API
static int tcp_get_file_handle(URLContext *h)
void ff_log_net_error(void *ctx, int level, const char *prefix)
static int tcp_accept(URLContext *s, URLContext **c)