40 #define OFFSET(x) offsetof(TCPContext, x)
41 #define D AV_OPT_FLAG_DECODING_PARAM
42 #define E AV_OPT_FLAG_ENCODING_PARAM
45 {
"timeout",
"timeout of socket i/o operations",
OFFSET(rw_timeout),
AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX,
D|
E },
46 {
"listen_timeout",
"connection awaiting timeout",
OFFSET(listen_timeout),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX,
D|
E },
60 struct addrinfo hints = { 0 }, *ai, *cur_ai;
67 char hostname[1024],proto[1024],path[1024];
72 &port, path,
sizeof(path), uri);
73 if (strcmp(proto,
"tcp"))
75 if (port <= 0 || port >= 65536) {
93 snprintf(portstr,
sizeof(portstr),
"%d", port);
102 "Failed to resolve hostname %s: %s\n",
111 fd = socket(cur_ai->ai_family, cur_ai->ai_socktype, cur_ai->ai_protocol);
118 struct pollfd lp = { fd, POLLIN, 0 };
119 setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &reuse,
sizeof(reuse));
120 ret = bind(fd, cur_ai->ai_addr, cur_ai->ai_addrlen);
146 ret = connect(fd, cur_ai->ai_addr, cur_ai->ai_addrlen);
150 struct pollfd p = {fd, POLLOUT, 0};
151 int64_t wait_started;
160 if (ret !=
AVERROR(EINPROGRESS) &&
171 ret = poll(&p, 1, 100);
180 optlen =
sizeof(ret);
181 if (getsockopt (fd, SOL_SOCKET, SO_ERROR, &ret, &optlen))
188 "TCP connection to %s:%d failed: %s\n",
189 hostname, port, errbuf);
199 if (cur_ai->ai_next) {
201 cur_ai = cur_ai->ai_next;
223 ret = recv(s->
fd, buf, size, 0);
237 ret = send(s->
fd, buf, size, 0);
254 return shutdown(s->
fd, how);
279 .priv_data_class = &tcp_context_class,