Also use ff_neterrno() instead of errno directly (which doesn't work on windows), for getting the error code.
Unified · Split
| @@ -141,10 +141,12 @@ static int tcp_open(URLContext *h, const char *uri, int flags) · 140 unmodified lines | |||
| 141 | optlen = sizeof(ret); | 141 | optlen = sizeof(ret); |
| 142 | getsockopt (fd, SOL_SOCKET, SO_ERROR, &ret, &optlen); | 142 | getsockopt (fd, SOL_SOCKET, SO_ERROR, &ret, &optlen); |
| 143 | if (ret != 0) { | 143 | if (ret != 0) { |
| 144 | char errbuf[100]; | ||
| 145 | ret = AVERROR(ret); | ||
| 146 | av_strerror(ret, errbuf, sizeof(errbuf)); | ||
| 144 | av_log(h, AV_LOG_ERROR, | 147 | av_log(h, AV_LOG_ERROR, |
| 145 | "TCP connection to %s:%d failed: %s\n", | 148 | "TCP connection to %s:%d failed: %s\n", |
| 146 | hostname, port, strerror(ret)); | 149 | hostname, port, errbuf); |
| 147 | ret = AVERROR(ret); | ||
| 148 | goto fail; | 150 | goto fail; |
| 149 | } | 151 | } |
| 150 | } | 152 | } |
| @@ -57,13 +57,20 @@ typedef struct { · 56 unmodified lines | |||
| 57 | #define UDP_TX_BUF_SIZE 32768 | 57 | #define UDP_TX_BUF_SIZE 32768 |
| 58 | #define UDP_MAX_PKT_SIZE 65536 | 58 | #define UDP_MAX_PKT_SIZE 65536 |
| 59 | 59 | ||
| 60 | static void log_net_error(void *ctx, int level, const char* prefix) | ||
| 61 | { | ||
| 62 | char errbuf[100]; | ||
| 63 | av_strerror(ff_neterrno(), errbuf, sizeof(errbuf)); | ||
| 64 | av_log(ctx, level, "%s: %s\n", prefix, errbuf); | ||
| 65 | } | ||
| 66 | |||
| 60 | static int udp_set_multicast_ttl(int sockfd, int mcastTTL, | 67 | static int udp_set_multicast_ttl(int sockfd, int mcastTTL, |
| 61 | struct sockaddr *addr) | 68 | struct sockaddr *addr) |
| 62 | { | 69 | { |
| 63 | #ifdef IP_MULTICAST_TTL | 70 | #ifdef IP_MULTICAST_TTL |
| 64 | if (addr->sa_family == AF_INET) { | 71 | if (addr->sa_family == AF_INET) { |
| 65 | if (setsockopt(sockfd, IPPROTO_IP, IP_MULTICAST_TTL, &mcastTTL, sizeof(mcastTTL)) < 0) { | 72 | if (setsockopt(sockfd, IPPROTO_IP, IP_MULTICAST_TTL, &mcastTTL, sizeof(mcastTTL)) < 0) { |
| 66 | av_log(NULL, AV_LOG_ERROR, "setsockopt(IP_MULTICAST_TTL): %s\n", strerror(errno)); | 73 | log_net_error(NULL, AV_LOG_ERROR, "setsockopt(IP_MULTICAST_TTL)"); |
| 67 | return -1; | 74 | return -1; |
| 68 | } | 75 | } |
| 69 | } | 76 | } |
| @@ -71,7 +78,7 @@ static int udp_set_multicast_ttl(int sockfd, int mcastTTL, · 1 unmodified line | |||
| 71 | #if defined(IPPROTO_IPV6) && defined(IPV6_MULTICAST_HOPS) | 78 | #if defined(IPPROTO_IPV6) && defined(IPV6_MULTICAST_HOPS) |
| 72 | if (addr->sa_family == AF_INET6) { | 79 | if (addr->sa_family == AF_INET6) { |
| 73 | if (setsockopt(sockfd, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, &mcastTTL, sizeof(mcastTTL)) < 0) { | 80 | if (setsockopt(sockfd, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, &mcastTTL, sizeof(mcastTTL)) < 0) { |
| 74 | av_log(NULL, AV_LOG_ERROR, "setsockopt(IPV6_MULTICAST_HOPS): %s\n", strerror(errno)); | 81 | log_net_error(NULL, AV_LOG_ERROR, "setsockopt(IPV6_MULTICAST_HOPS)"); |
| 75 | return -1; | 82 | return -1; |
| 76 | } | 83 | } |
| 77 | } | 84 | } |
| @@ -88,7 +95,7 @@ static int udp_join_multicast_group(int sockfd, struct sockaddr *addr) · 10 unmodified lines | |||
| 88 | mreq.imr_multiaddr.s_addr = ((struct sockaddr_in *)addr)->sin_addr.s_addr; | 95 | mreq.imr_multiaddr.s_addr = ((struct sockaddr_in *)addr)->sin_addr.s_addr; |
| 89 | mreq.imr_interface.s_addr= INADDR_ANY; | 96 | mreq.imr_interface.s_addr= INADDR_ANY; |
| 90 | if (setsockopt(sockfd, IPPROTO_IP, IP_ADD_MEMBERSHIP, (const void *)&mreq, sizeof(mreq)) < 0) { | 97 | if (setsockopt(sockfd, IPPROTO_IP, IP_ADD_MEMBERSHIP, (const void *)&mreq, sizeof(mreq)) < 0) { |
| 91 | av_log(NULL, AV_LOG_ERROR, "setsockopt(IP_ADD_MEMBERSHIP): %s\n", strerror(errno)); | 98 | log_net_error(NULL, AV_LOG_ERROR, "setsockopt(IP_ADD_MEMBERSHIP)"); |
| 92 | return -1; | 99 | return -1; |
| 93 | } | 100 | } |
| 94 | } | 101 | } |
| @@ -100,7 +107,7 @@ static int udp_join_multicast_group(int sockfd, struct sockaddr *addr) · 5 unmodified lines | |||
| 100 | memcpy(&mreq6.ipv6mr_multiaddr, &(((struct sockaddr_in6 *)addr)->sin6_addr), sizeof(struct in6_addr)); | 107 | memcpy(&mreq6.ipv6mr_multiaddr, &(((struct sockaddr_in6 *)addr)->sin6_addr), sizeof(struct in6_addr)); |
| 101 | mreq6.ipv6mr_interface= 0; | 108 | mreq6.ipv6mr_interface= 0; |
| 102 | if (setsockopt(sockfd, IPPROTO_IPV6, IPV6_ADD_MEMBERSHIP, &mreq6, sizeof(mreq6)) < 0) { | 109 | if (setsockopt(sockfd, IPPROTO_IPV6, IPV6_ADD_MEMBERSHIP, &mreq6, sizeof(mreq6)) < 0) { |
| 103 | av_log(NULL, AV_LOG_ERROR, "setsockopt(IPV6_ADD_MEMBERSHIP): %s\n", strerror(errno)); | 110 | log_net_error(NULL, AV_LOG_ERROR, "setsockopt(IPV6_ADD_MEMBERSHIP)"); |
| 104 | return -1; | 111 | return -1; |
| 105 | } | 112 | } |
| 106 | } | 113 | } |
| @@ -117,7 +124,7 @@ static int udp_leave_multicast_group(int sockfd, struct sockaddr *addr) · 10 unmodified lines | |||
| 117 | mreq.imr_multiaddr.s_addr = ((struct sockaddr_in *)addr)->sin_addr.s_addr; | 124 | mreq.imr_multiaddr.s_addr = ((struct sockaddr_in *)addr)->sin_addr.s_addr; |
| 118 | mreq.imr_interface.s_addr= INADDR_ANY; | 125 | mreq.imr_interface.s_addr= INADDR_ANY; |
| 119 | if (setsockopt(sockfd, IPPROTO_IP, IP_DROP_MEMBERSHIP, (const void *)&mreq, sizeof(mreq)) < 0) { | 126 | if (setsockopt(sockfd, IPPROTO_IP, IP_DROP_MEMBERSHIP, (const void *)&mreq, sizeof(mreq)) < 0) { |
| 120 | av_log(NULL, AV_LOG_ERROR, "setsockopt(IP_DROP_MEMBERSHIP): %s\n", strerror(errno)); | 127 | log_net_error(NULL, AV_LOG_ERROR, "setsockopt(IP_DROP_MEMBERSHIP)"); |
| 121 | return -1; | 128 | return -1; |
| 122 | } | 129 | } |
| 123 | } | 130 | } |
| @@ -129,7 +136,7 @@ static int udp_leave_multicast_group(int sockfd, struct sockaddr *addr) · 5 unmodified lines | |||
| 129 | memcpy(&mreq6.ipv6mr_multiaddr, &(((struct sockaddr_in6 *)addr)->sin6_addr), sizeof(struct in6_addr)); | 136 | memcpy(&mreq6.ipv6mr_multiaddr, &(((struct sockaddr_in6 *)addr)->sin6_addr), sizeof(struct in6_addr)); |
| 130 | mreq6.ipv6mr_interface= 0; | 137 | mreq6.ipv6mr_interface= 0; |
| 131 | if (setsockopt(sockfd, IPPROTO_IPV6, IPV6_DROP_MEMBERSHIP, &mreq6, sizeof(mreq6)) < 0) { | 138 | if (setsockopt(sockfd, IPPROTO_IPV6, IPV6_DROP_MEMBERSHIP, &mreq6, sizeof(mreq6)) < 0) { |
| 132 | av_log(NULL, AV_LOG_ERROR, "setsockopt(IPV6_DROP_MEMBERSHIP): %s\n", strerror(errno)); | 139 | log_net_error(NULL, AV_LOG_ERROR, "setsockopt(IPV6_DROP_MEMBERSHIP)"); |
| 133 | return -1; | 140 | return -1; |
| 134 | } | 141 | } |
| 135 | } | 142 | } |
| @@ -194,7 +201,7 @@ static int udp_socket_create(UDPContext *s, struct sockaddr_storage *addr, · 58 unmodified lines | |||
| 194 | for (res = res0; res; res=res->ai_next) { | 201 | for (res = res0; res; res=res->ai_next) { |
| 195 | udp_fd = socket(res->ai_family, SOCK_DGRAM, 0); | 202 | udp_fd = socket(res->ai_family, SOCK_DGRAM, 0); |
| 196 | if (udp_fd > 0) break; | 203 | if (udp_fd > 0) break; |
| 197 | av_log(NULL, AV_LOG_ERROR, "socket: %s\n", strerror(errno)); | 204 | log_net_error(NULL, AV_LOG_ERROR, "socket"); |
| 198 | } | 205 | } |
| 199 | 206 | ||
| 200 | if (udp_fd < 0) | 207 | if (udp_fd < 0) |
| @@ -268,7 +275,7 @@ int ff_udp_set_remote_url(URLContext *h, const char *uri) · 67 unmodified lines | |||
| 268 | if (connect(s->udp_fd, (struct sockaddr *) &s->dest_addr, | 275 | if (connect(s->udp_fd, (struct sockaddr *) &s->dest_addr, |
| 269 | s->dest_addr_len)) { | 276 | s->dest_addr_len)) { |
| 270 | s->is_connected = 0; | 277 | s->is_connected = 0; |
| 271 | av_log(h, AV_LOG_ERROR, "connect: %s\n", strerror(errno)); | 278 | log_net_error(h, AV_LOG_ERROR, "connect"); |
| 272 | return AVERROR(EIO); | 279 | return AVERROR(EIO); |
| 273 | } | 280 | } |
| 274 | } | 281 | } |
| @@ -391,7 +398,7 @@ static int udp_open(URLContext *h, const char *uri, int flags) · 116 unmodified lines | |||
| 391 | * bind failed */ | 398 | * bind failed */ |
| 392 | /* the bind is needed to give a port to the socket now */ | 399 | /* the bind is needed to give a port to the socket now */ |
| 393 | if (bind_ret < 0 && bind(udp_fd,(struct sockaddr *)&my_addr, len) < 0) { | 400 | if (bind_ret < 0 && bind(udp_fd,(struct sockaddr *)&my_addr, len) < 0) { |
| 394 | av_log(h, AV_LOG_ERROR, "bind failed: %s\n", strerror(errno)); | 401 | log_net_error(h, AV_LOG_ERROR, "bind failed"); |
| 395 | goto fail; | 402 | goto fail; |
| 396 | } | 403 | } |
| 397 | 404 | ||
| @@ -416,7 +423,7 @@ static int udp_open(URLContext *h, const char *uri, int flags) · 18 unmodified lines | |||
| 416 | /* limit the tx buf size to limit latency */ | 423 | /* limit the tx buf size to limit latency */ |
| 417 | tmp = s->buffer_size; | 424 | tmp = s->buffer_size; |
| 418 | if (setsockopt(udp_fd, SOL_SOCKET, SO_SNDBUF, &tmp, sizeof(tmp)) < 0) { | 425 | if (setsockopt(udp_fd, SOL_SOCKET, SO_SNDBUF, &tmp, sizeof(tmp)) < 0) { |
| 419 | av_log(h, AV_LOG_ERROR, "setsockopt(SO_SNDBUF): %s\n", strerror(errno)); | 426 | log_net_error(h, AV_LOG_ERROR, "setsockopt(SO_SNDBUF)"); |
| 420 | goto fail; | 427 | goto fail; |
| 421 | } | 428 | } |
| 422 | } else { | 429 | } else { |
| @@ -424,14 +431,14 @@ static int udp_open(URLContext *h, const char *uri, int flags) · 1 unmodified line | |||
| 424 | * avoid losing data on OSes that set this too low by default. */ | 431 | * avoid losing data on OSes that set this too low by default. */ |
| 425 | tmp = s->buffer_size; | 432 | tmp = s->buffer_size; |
| 426 | if (setsockopt(udp_fd, SOL_SOCKET, SO_RCVBUF, &tmp, sizeof(tmp)) < 0) { | 433 | if (setsockopt(udp_fd, SOL_SOCKET, SO_RCVBUF, &tmp, sizeof(tmp)) < 0) { |
| 427 | av_log(h, AV_LOG_WARNING, "setsockopt(SO_RECVBUF): %s\n", strerror(errno)); | 434 | log_net_error(h, AV_LOG_WARNING, "setsockopt(SO_RECVBUF)"); |
| 428 | } | 435 | } |
| 429 | /* make the socket non-blocking */ | 436 | /* make the socket non-blocking */ |
| 430 | ff_socket_nonblock(udp_fd, 1); | 437 | ff_socket_nonblock(udp_fd, 1); |
| 431 | } | 438 | } |
| 432 | if (s->is_connected) { | 439 | if (s->is_connected) { |
| 433 | if (connect(udp_fd, (struct sockaddr *) &s->dest_addr, s->dest_addr_len)) { | 440 | if (connect(udp_fd, (struct sockaddr *) &s->dest_addr, s->dest_addr_len)) { |
| 434 | av_log(h, AV_LOG_ERROR, "connect: %s\n", strerror(errno)); | 441 | log_net_error(h, AV_LOG_ERROR, "connect"); |
| 435 | goto fail; | 442 | goto fail; |
| 436 | } | 443 | } |
| 437 | } | 444 | } |