43 #define OFFSET(x) offsetof(TCPContext, x)
44 #define D AV_OPT_FLAG_DECODING_PARAM
45 #define E AV_OPT_FLAG_ENCODING_PARAM
47 {
"listen",
"Listen for incoming connections",
OFFSET(listen),
AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, .flags =
D|
E },
48 {
"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 },
49 {
"listen_timeout",
"Connection awaiting timeout (in milliseconds)",
OFFSET(listen_timeout),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, .flags =
D|
E },
63 struct addrinfo hints = { 0 }, *ai, *cur_ai;
69 char hostname[1024],proto[1024],path[1024];
74 &port, path,
sizeof(path), uri);
75 if (strcmp(proto,
"tcp"))
77 if (port <= 0 || port >= 65536) {
85 s->
listen = strtol(buf, &endptr, 10);
103 snprintf(portstr,
sizeof(portstr),
"%d", port);
112 "Failed to resolve hostname %s: %s\n",
122 cur_ai->ai_protocol);
129 if ((ret =
ff_listen_bind(fd, cur_ai->ai_addr, cur_ai->ai_addrlen,
151 if (cur_ai->ai_next) {
153 cur_ai = cur_ai->ai_next;
176 ret = recv(s->
fd, buf, size, 0);
207 return shutdown(s->
fd, how);
233 .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 LIBAVUTIL_VERSION_INT
int is_streamed
true if streamed (no seek possible), default = false
AVIOInterruptCB interrupt_callback
#define AVIO_FLAG_READ
read-only
int64_t rw_timeout
maximum time to wait for (network) read/write operation completion, in mcs
#define AVIO_FLAG_WRITE
write-only
URLProtocol ff_tcp_protocol
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...
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_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 av_find_info_tag(char *arg, int arg_size, const char *tag1, const char *info)
Attempt to find a specific tag in a URL.
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_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)
#define AVERROR_EXIT
Immediate exit was requested; the called function should not be restarted.
#define AVIO_FLAG_NONBLOCK
Use non-blocking mode.
Describe the class of an AVClass context structure.
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)