| 78 | }; |
| 79 | |
| 80 | static int customize_fd(void *ctx, int fd, int family) |
| 81 | { |
| 82 | TCPContext *s = ctx; |
| 83 | |
| 84 | if (s->local_addr || s->local_port) { |
| 85 | struct addrinfo hints = { 0 }, *ai, *cur_ai; |
| 86 | int ret; |
| 87 | |
| 88 | hints.ai_family = family; |
| 89 | hints.ai_socktype = SOCK_STREAM; |
| 90 | |
| 91 | ret = getaddrinfo(s->local_addr, s->local_port, &hints, &ai); |
| 92 | if (ret) { |
| 93 | av_log(ctx, AV_LOG_ERROR, |
| 94 | "Failed to getaddrinfo local addr: %s port: %s err: %s\n", |
| 95 | s->local_addr, s->local_port, gai_strerror(ret)); |
| 96 | return ret; |
| 97 | } |
| 98 | |
| 99 | cur_ai = ai; |
| 100 | while (cur_ai) { |
| 101 | ret = bind(fd, (struct sockaddr *)cur_ai->ai_addr, (int)cur_ai->ai_addrlen); |
| 102 | if (ret) |
| 103 | cur_ai = cur_ai->ai_next; |
| 104 | else |
| 105 | break; |
| 106 | } |
| 107 | freeaddrinfo(ai); |
| 108 | |
| 109 | if (ret) { |
| 110 | ff_log_net_error(ctx, AV_LOG_ERROR, "bind local failed"); |
| 111 | return ret; |
| 112 | } |
| 113 | } |
| 114 | /* Set the socket's send or receive buffer sizes, if specified. |
| 115 | If unspecified or setting fails, system default is used. */ |
| 116 | if (s->recv_buffer_size > 0) { |
| 117 | if (setsockopt (fd, SOL_SOCKET, SO_RCVBUF, &s->recv_buffer_size, sizeof (s->recv_buffer_size))) { |
| 118 | ff_log_net_error(ctx, AV_LOG_WARNING, "setsockopt(SO_RCVBUF)"); |
| 119 | } |
| 120 | } |
| 121 | if (s->send_buffer_size > 0) { |
| 122 | if (setsockopt (fd, SOL_SOCKET, SO_SNDBUF, &s->send_buffer_size, sizeof (s->send_buffer_size))) { |
| 123 | ff_log_net_error(ctx, AV_LOG_WARNING, "setsockopt(SO_SNDBUF)"); |
| 124 | } |
| 125 | } |
| 126 | if (s->tcp_nodelay > 0) { |
| 127 | if (setsockopt (fd, IPPROTO_TCP, TCP_NODELAY, &s->tcp_nodelay, sizeof (s->tcp_nodelay))) { |
| 128 | ff_log_net_error(ctx, AV_LOG_WARNING, "setsockopt(TCP_NODELAY)"); |
| 129 | } |
| 130 | } |
| 131 | if (s->tcp_keepalive > 0) { |
| 132 | if (setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &s->tcp_keepalive, sizeof(s->tcp_keepalive))) { |
| 133 | ff_log_net_error(ctx, AV_LOG_WARNING, "setsockopt(SO_KEEPALIVE)"); |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | #if !HAVE_WINSOCK2_H |
no test coverage detected