38 struct addrinfo hints = { 0 }, *ai, *cur_ai;
41 int listen_socket = 0;
46 int timeout = 100, listen_timeout = -1;
47 char hostname[1024],proto[1024],path[1024];
51 &port, path,
sizeof(path), uri);
52 if (strcmp(proto,
"tcp"))
54 if (port <= 0 || port >= 65536) {
63 timeout = strtol(buf,
NULL, 10);
66 listen_timeout = strtol(buf,
NULL, 10);
71 snprintf(portstr,
sizeof(portstr),
"%d", port);
80 "Failed to resolve hostname %s: %s\n",
89 fd = socket(cur_ai->ai_family, cur_ai->ai_socktype, cur_ai->ai_protocol);
96 struct pollfd lp = { fd, POLLIN, 0 };
97 setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &reuse,
sizeof(reuse));
98 ret = bind(fd, cur_ai->ai_addr, cur_ai->ai_addrlen);
108 ret = poll(&lp, 1, listen_timeout >= 0 ? listen_timeout : -1);
124 ret = connect(fd, cur_ai->ai_addr, cur_ai->ai_addrlen);
128 struct pollfd p = {fd, POLLOUT, 0};
137 if (ret !=
AVERROR(EINPROGRESS) &&
147 ret = poll(&p, 1, 100);
156 optlen =
sizeof(ret);
157 if (getsockopt (fd, SOL_SOCKET, SO_ERROR, &ret, &optlen))
164 "TCP connection to %s:%d failed: %s\n",
165 hostname, port, errbuf);
175 if (cur_ai->ai_next) {
177 cur_ai = cur_ai->ai_next;
199 ret = recv(s->
fd, buf, size, 0);
213 ret = send(s->
fd, buf, size, 0);
230 return shutdown(s->
fd, how);
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 int tcp_open(URLContext *h, const char *uri, int flags)
int is_streamed
true if streamed (no seek possible), default = false
AVIOInterruptCB interrupt_callback
URLProtocol ff_tcp_protocol
miscellaneous OS support macros and functions.
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)
struct TCPContext TCPContext
void av_log(void *avcl, int level, const char *fmt,...)
static int tcp_close(URLContext *h)
static int tcp_shutdown(URLContext *h, int flags)
#define AVIO_FLAG_NONBLOCK
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.
static int tcp_write(URLContext *h, const uint8_t *buf, int size)
int ff_network_wait_fd(int fd, int write)
unbuffered private I/O API
static int tcp_get_file_handle(URLContext *h)