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 | 141 | optlen = sizeof(ret); |
| 142 | 142 | getsockopt (fd, SOL_SOCKET, SO_ERROR, &ret, &optlen); |
| 143 | 143 | if (ret != 0) { |
| 144 | + char errbuf[100]; | |
| 145 | + ret = AVERROR(ret); | |
| 146 | + av_strerror(ret, errbuf, sizeof(errbuf)); | |
| 144 | 147 | av_log(h, AV_LOG_ERROR, |
| 145 | 148 | "TCP connection to %s:%d failed: %s\n", |
| 146 | − hostname, port, strerror(ret)); | |
| 147 | − ret = AVERROR(ret); | |
| 149 | + hostname, port, errbuf); | |
| 148 | 150 | goto fail; |
| 149 | 151 | } |
| 150 | 152 | } |
| @@ -57,13 +57,20 @@ typedef struct { · 56 unmodified lines | ||
| 57 | 57 | #define UDP_TX_BUF_SIZE 32768 |
| 58 | 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 | 67 | static int udp_set_multicast_ttl(int sockfd, int mcastTTL, |
| 61 | 68 | struct sockaddr *addr) |
| 62 | 69 | { |
| 63 | 70 | #ifdef IP_MULTICAST_TTL |
| 64 | 71 | if (addr->sa_family == AF_INET) { |
| 65 | 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 | 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 | 78 | #if defined(IPPROTO_IPV6) && defined(IPV6_MULTICAST_HOPS) |
| 72 | 79 | if (addr->sa_family == AF_INET6) { |
| 73 | 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 | 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 | 95 | mreq.imr_multiaddr.s_addr = ((struct sockaddr_in *)addr)->sin_addr.s_addr; |
| 89 | 96 | mreq.imr_interface.s_addr= INADDR_ANY; |
| 90 | 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 | 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 | 107 | memcpy(&mreq6.ipv6mr_multiaddr, &(((struct sockaddr_in6 *)addr)->sin6_addr), sizeof(struct in6_addr)); |
| 101 | 108 | mreq6.ipv6mr_interface= 0; |
| 102 | 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 | 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 | 124 | mreq.imr_multiaddr.s_addr = ((struct sockaddr_in *)addr)->sin_addr.s_addr; |
| 118 | 125 | mreq.imr_interface.s_addr= INADDR_ANY; |
| 119 | 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 | 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 | 136 | memcpy(&mreq6.ipv6mr_multiaddr, &(((struct sockaddr_in6 *)addr)->sin6_addr), sizeof(struct in6_addr)); |
| 130 | 137 | mreq6.ipv6mr_interface= 0; |
| 131 | 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 | 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 | 201 | for (res = res0; res; res=res->ai_next) { |
| 195 | 202 | udp_fd = socket(res->ai_family, SOCK_DGRAM, 0); |
| 196 | 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 | 207 | if (udp_fd < 0) |
| @@ -268,7 +275,7 @@ int ff_udp_set_remote_url(URLContext *h, const char *uri) · 67 unmodified lines | ||
| 268 | 275 | if (connect(s->udp_fd, (struct sockaddr *) &s->dest_addr, |
| 269 | 276 | s->dest_addr_len)) { |
| 270 | 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 | 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 | 398 | * bind failed */ |
| 392 | 399 | /* the bind is needed to give a port to the socket now */ |
| 393 | 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 | 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 | 423 | /* limit the tx buf size to limit latency */ |
| 417 | 424 | tmp = s->buffer_size; |
| 418 | 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 | 427 | goto fail; |
| 421 | 428 | } |
| 422 | 429 | } else { |
| @@ -424,14 +431,14 @@ static int udp_open(URLContext *h, const char *uri, int flags) · 1 unmodified line | ||
| 424 | 431 | * avoid losing data on OSes that set this too low by default. */ |
| 425 | 432 | tmp = s->buffer_size; |
| 426 | 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 | 436 | /* make the socket non-blocking */ |
| 430 | 437 | ff_socket_nonblock(udp_fd, 1); |
| 431 | 438 | } |
| 432 | 439 | if (s->is_connected) { |
| 433 | 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 | 442 | goto fail; |
| 436 | 443 | } |
| 437 | 444 | } |