mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-04-14 00:58:38 +02:00
Merge commit '8c76bfacf663ff71cee5264a74d0f9c86addd325'
* commit '8c76bfacf663ff71cee5264a74d0f9c86addd325': tcp: Use ff_connect_parallel for RFC 8305 style connecting Merged-by: James Almer <jamrial@gmail.com>
This commit is contained in:
commit
ef71ef5f30
@ -70,6 +70,27 @@ static const AVClass tcp_class = {
|
|||||||
.version = LIBAVUTIL_VERSION_INT,
|
.version = LIBAVUTIL_VERSION_INT,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static void customize_fd(void *ctx, int fd)
|
||||||
|
{
|
||||||
|
TCPContext *s = ctx;
|
||||||
|
/* Set the socket's send or receive buffer sizes, if specified.
|
||||||
|
If unspecified or setting fails, system default is used. */
|
||||||
|
if (s->recv_buffer_size > 0) {
|
||||||
|
setsockopt (fd, SOL_SOCKET, SO_RCVBUF, &s->recv_buffer_size, sizeof (s->recv_buffer_size));
|
||||||
|
}
|
||||||
|
if (s->send_buffer_size > 0) {
|
||||||
|
setsockopt (fd, SOL_SOCKET, SO_SNDBUF, &s->send_buffer_size, sizeof (s->send_buffer_size));
|
||||||
|
}
|
||||||
|
if (s->tcp_nodelay > 0) {
|
||||||
|
setsockopt (fd, IPPROTO_TCP, TCP_NODELAY, &s->tcp_nodelay, sizeof (s->tcp_nodelay));
|
||||||
|
}
|
||||||
|
#if !HAVE_WINSOCK2_H
|
||||||
|
if (s->tcp_mss > 0) {
|
||||||
|
setsockopt (fd, IPPROTO_TCP, TCP_MAXSEG, &s->tcp_mss, sizeof (s->tcp_mss));
|
||||||
|
}
|
||||||
|
#endif /* !HAVE_WINSOCK2_H */
|
||||||
|
}
|
||||||
|
|
||||||
/* return non zero if error */
|
/* return non zero if error */
|
||||||
static int tcp_open(URLContext *h, const char *uri, int flags)
|
static int tcp_open(URLContext *h, const char *uri, int flags)
|
||||||
{
|
{
|
||||||
@ -129,7 +150,6 @@ static int tcp_open(URLContext *h, const char *uri, int flags)
|
|||||||
|
|
||||||
cur_ai = ai;
|
cur_ai = ai;
|
||||||
|
|
||||||
restart:
|
|
||||||
#if HAVE_STRUCT_SOCKADDR_IN6
|
#if HAVE_STRUCT_SOCKADDR_IN6
|
||||||
// workaround for IOS9 getaddrinfo in IPv6 only network use hardcode IPv4 address can not resolve port number.
|
// workaround for IOS9 getaddrinfo in IPv6 only network use hardcode IPv4 address can not resolve port number.
|
||||||
if (cur_ai->ai_family == AF_INET6){
|
if (cur_ai->ai_family == AF_INET6){
|
||||||
@ -140,38 +160,20 @@ static int tcp_open(URLContext *h, const char *uri, int flags)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
fd = ff_socket(cur_ai->ai_family,
|
if (s->listen > 0) {
|
||||||
cur_ai->ai_socktype,
|
while (cur_ai && fd < 0) {
|
||||||
cur_ai->ai_protocol);
|
fd = ff_socket(cur_ai->ai_family,
|
||||||
if (fd < 0) {
|
cur_ai->ai_socktype,
|
||||||
ret = ff_neterrno();
|
cur_ai->ai_protocol);
|
||||||
goto fail;
|
if (fd < 0) {
|
||||||
}
|
ret = ff_neterrno();
|
||||||
|
cur_ai = cur_ai->ai_next;
|
||||||
/* Set the socket's send or receive buffer sizes, if specified.
|
}
|
||||||
If unspecified or setting fails, system default is used. */
|
|
||||||
if (s->recv_buffer_size > 0) {
|
|
||||||
if (setsockopt (fd, SOL_SOCKET, SO_RCVBUF, &s->recv_buffer_size, sizeof (s->recv_buffer_size))) {
|
|
||||||
ff_log_net_error(h, AV_LOG_WARNING, "setsockopt(SO_RCVBUF)");
|
|
||||||
}
|
}
|
||||||
|
if (fd < 0)
|
||||||
|
goto fail1;
|
||||||
|
customize_fd(s, fd);
|
||||||
}
|
}
|
||||||
if (s->send_buffer_size > 0) {
|
|
||||||
if (setsockopt (fd, SOL_SOCKET, SO_SNDBUF, &s->send_buffer_size, sizeof (s->send_buffer_size))) {
|
|
||||||
ff_log_net_error(h, AV_LOG_WARNING, "setsockopt(SO_SNDBUF)");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (s->tcp_nodelay > 0) {
|
|
||||||
if (setsockopt (fd, IPPROTO_TCP, TCP_NODELAY, &s->tcp_nodelay, sizeof (s->tcp_nodelay))) {
|
|
||||||
ff_log_net_error(h, AV_LOG_WARNING, "setsockopt(TCP_NODELAY)");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#if !HAVE_WINSOCK2_H
|
|
||||||
if (s->tcp_mss > 0) {
|
|
||||||
if (setsockopt (fd, IPPROTO_TCP, TCP_MAXSEG, &s->tcp_mss, sizeof (s->tcp_mss))) {
|
|
||||||
ff_log_net_error(h, AV_LOG_WARNING, "setsockopt(TCP_MAXSEG)");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif /* !HAVE_WINSOCK2_H */
|
|
||||||
|
|
||||||
if (s->listen == 2) {
|
if (s->listen == 2) {
|
||||||
// multi-client
|
// multi-client
|
||||||
@ -185,14 +187,9 @@ static int tcp_open(URLContext *h, const char *uri, int flags)
|
|||||||
// Socket descriptor already closed here. Safe to overwrite to client one.
|
// Socket descriptor already closed here. Safe to overwrite to client one.
|
||||||
fd = ret;
|
fd = ret;
|
||||||
} else {
|
} else {
|
||||||
if ((ret = ff_listen_connect(fd, cur_ai->ai_addr, cur_ai->ai_addrlen,
|
ret = ff_connect_parallel(ai, s->open_timeout / 1000, 3, h, &fd, customize_fd, s);
|
||||||
s->open_timeout / 1000, h, !!cur_ai->ai_next)) < 0) {
|
if (ret < 0)
|
||||||
|
goto fail1;
|
||||||
if (ret == AVERROR_EXIT)
|
|
||||||
goto fail1;
|
|
||||||
else
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
h->is_streamed = 1;
|
h->is_streamed = 1;
|
||||||
@ -201,15 +198,6 @@ static int tcp_open(URLContext *h, const char *uri, int flags)
|
|||||||
freeaddrinfo(ai);
|
freeaddrinfo(ai);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
fail:
|
|
||||||
if (cur_ai->ai_next) {
|
|
||||||
/* Retry with the next sockaddr */
|
|
||||||
cur_ai = cur_ai->ai_next;
|
|
||||||
if (fd >= 0)
|
|
||||||
closesocket(fd);
|
|
||||||
ret = 0;
|
|
||||||
goto restart;
|
|
||||||
}
|
|
||||||
fail1:
|
fail1:
|
||||||
if (fd >= 0)
|
if (fd >= 0)
|
||||||
closesocket(fd);
|
closesocket(fd);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user