41 #define OFFSET(x) offsetof(TCPContext, x)
42 #define D AV_OPT_FLAG_DECODING_PARAM
43 #define E AV_OPT_FLAG_ENCODING_PARAM
46 {
"timeout",
"timeout of socket i/o operations",
OFFSET(rw_timeout),
AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX,
D|
E },
47 {
"listen_timeout",
"connection awaiting timeout",
OFFSET(listen_timeout),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX,
D|
E },
61 struct addrinfo hints = { 0 }, *ai, *cur_ai;
68 char hostname[1024],proto[1024],path[1024];
73 &port, path,
sizeof(path), uri);
74 if (strcmp(proto,
"tcp"))
76 if (port <= 0 || port >= 65536) {
94 snprintf(portstr,
sizeof(portstr),
"%d", port);
103 "Failed to resolve hostname %s: %s\n",
112 fd = socket(cur_ai->ai_family, cur_ai->ai_socktype, cur_ai->ai_protocol);
119 struct pollfd lp = { fd, POLLIN, 0 };
120 setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &reuse,
sizeof(reuse));
121 ret = bind(fd, cur_ai->ai_addr, cur_ai->ai_addrlen);
147 ret = connect(fd, cur_ai->ai_addr, cur_ai->ai_addrlen);
151 struct pollfd p = {fd, POLLOUT, 0};
152 int64_t wait_started;
161 if (ret !=
AVERROR(EINPROGRESS) &&
172 ret = poll(&p, 1, 100);
181 optlen =
sizeof(
ret);
182 if (getsockopt (fd, SOL_SOCKET, SO_ERROR, &ret, &optlen))
189 "TCP connection to %s:%d failed: %s\n",
190 hostname, port, errbuf);
200 if (cur_ai->ai_next) {
202 cur_ai = cur_ai->ai_next;
224 ret = recv(s->
fd, buf, size, 0);
238 ret = send(s->
fd, buf, size, 0);
255 return shutdown(s->
fd, how);
280 .priv_data_class = &tcp_context_class,