Martin Storsjö <[email protected]> writes:

> diff --git a/libavformat/tcp.c b/libavformat/tcp.c
> index 7e348f7..e7c6210 100644
> --- a/libavformat/tcp.c
> +++ b/libavformat/tcp.c
> @@ -141,10 +141,12 @@ static int tcp_open(URLContext *h, const char *uri, int 
> flags)
>          optlen = sizeof(ret);
>          getsockopt (fd, SOL_SOCKET, SO_ERROR, &ret, &optlen);
>          if (ret != 0) {
> +            char errbuf[100];
> +            ret = AVERROR(ret);
> +            av_strerror(ret, errbuf, sizeof(errbuf));
>              av_log(h, AV_LOG_ERROR,
>                     "TCP connection to %s:%d failed: %s\n",
> -                   hostname, port, strerror(ret));
> -            ret = AVERROR(ret);
> +                   hostname, port, errbuf);
>              goto fail;
>          }
>      }

This is all wrong.  getsockopt() indicates error by returning -1.  In
case of error, the value stored in 'ret', if any, appears to be
undefined (the spec does not mention anything).

> diff --git a/libavformat/udp.c b/libavformat/udp.c
> index 04433bc..77ab8c2 100644
> --- a/libavformat/udp.c
> +++ b/libavformat/udp.c
> @@ -57,13 +57,20 @@ typedef struct {
>  #define UDP_TX_BUF_SIZE 32768
>  #define UDP_MAX_PKT_SIZE 65536
>
> +static void log_net_error(void *ctx, int level, const char* prefix)
> +{
> +    char errbuf[100];
> +    av_strerror(ff_neterrno(), errbuf, sizeof(errbuf));
> +    av_log(ctx, level, "%s: %s\n", prefix, errbuf);
> +}
> +
>  static int udp_set_multicast_ttl(int sockfd, int mcastTTL,
>                                   struct sockaddr *addr)
>  {
>  #ifdef IP_MULTICAST_TTL
>      if (addr->sa_family == AF_INET) {
>          if (setsockopt(sockfd, IPPROTO_IP, IP_MULTICAST_TTL, &mcastTTL, 
> sizeof(mcastTTL)) < 0) {
> -            av_log(NULL, AV_LOG_ERROR, "setsockopt(IP_MULTICAST_TTL): %s\n", 
> strerror(errno));
> +            log_net_error(NULL, AV_LOG_ERROR, 
> "setsockopt(IP_MULTICAST_TTL)");
>              return -1;
>          }
>      }

This change and the other like it look OK.

> @@ -194,7 +201,7 @@ static int udp_socket_create(UDPContext *s, struct 
> sockaddr_storage *addr,
>      for (res = res0; res; res=res->ai_next) {
>          udp_fd = socket(res->ai_family, SOCK_DGRAM, 0);
>          if (udp_fd > 0) break;

socket() can legitimately return 0 if someone has closed stdin.

> -        av_log(NULL, AV_LOG_ERROR, "socket: %s\n", strerror(errno));
> +        log_net_error(NULL, AV_LOG_ERROR, "socket");
>      }

Your change looks OK, though.

>      if (udp_fd < 0)
> @@ -268,7 +275,7 @@ int ff_udp_set_remote_url(URLContext *h, const char *uri)
>                  if (connect(s->udp_fd, (struct sockaddr *) &s->dest_addr,
>                              s->dest_addr_len)) {
>                      s->is_connected = 0;
> -                    av_log(h, AV_LOG_ERROR, "connect: %s\n", 
> strerror(errno));
> +                    log_net_error(h, AV_LOG_ERROR, "connect");
>                      return AVERROR(EIO);
>                  }
>              }
> @@ -391,7 +398,7 @@ static int udp_open(URLContext *h, const char *uri, int 
> flags)
>       * bind failed */
>      /* the bind is needed to give a port to the socket now */
>      if (bind_ret < 0 && bind(udp_fd,(struct sockaddr *)&my_addr, len) < 0) {
> -        av_log(h, AV_LOG_ERROR, "bind failed: %s\n", strerror(errno));
> +        log_net_error(h, AV_LOG_ERROR, "bind failed");
>          goto fail;
>      }
>
> @@ -416,7 +423,7 @@ static int udp_open(URLContext *h, const char *uri, int 
> flags)
>          /* limit the tx buf size to limit latency */
>          tmp = s->buffer_size;
>          if (setsockopt(udp_fd, SOL_SOCKET, SO_SNDBUF, &tmp, sizeof(tmp)) < 
> 0) {
> -            av_log(h, AV_LOG_ERROR, "setsockopt(SO_SNDBUF): %s\n", 
> strerror(errno));
> +            log_net_error(h, AV_LOG_ERROR, "setsockopt(SO_SNDBUF)");
>              goto fail;
>          }
>      } else {
> @@ -424,14 +431,14 @@ static int udp_open(URLContext *h, const char *uri, int 
> flags)
>           * avoid losing data on OSes that set this too low by default. */
>          tmp = s->buffer_size;
>          if (setsockopt(udp_fd, SOL_SOCKET, SO_RCVBUF, &tmp, sizeof(tmp)) < 
> 0) {
> -            av_log(h, AV_LOG_WARNING, "setsockopt(SO_RECVBUF): %s\n", 
> strerror(errno));
> +            log_net_error(h, AV_LOG_WARNING, "setsockopt(SO_RECVBUF)");
>          }
>          /* make the socket non-blocking */
>          ff_socket_nonblock(udp_fd, 1);
>      }
>      if (s->is_connected) {
>          if (connect(udp_fd, (struct sockaddr *) &s->dest_addr, 
> s->dest_addr_len)) {
> -            av_log(h, AV_LOG_ERROR, "connect: %s\n", strerror(errno));
> +            log_net_error(h, AV_LOG_ERROR, "connect");
>              goto fail;
>          }
>      }

These look OK.

-- 
Måns Rullgård
[email protected]
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to