comparison tcp.c @ 6378:a5b3f5d68db6 libavformat

Print error messages in case of connection failure or name resolution failure in tcp.c.
author rbultje
date Sat, 14 Aug 2010 20:34:51 +0000
parents 4fc5e0e4e1cd
children 3e7384f85f1d
comparison
equal deleted inserted replaced
6377:7eafa931f4e4 6378:a5b3f5d68db6
52 52
53 memset(&hints, 0, sizeof(hints)); 53 memset(&hints, 0, sizeof(hints));
54 hints.ai_family = AF_UNSPEC; 54 hints.ai_family = AF_UNSPEC;
55 hints.ai_socktype = SOCK_STREAM; 55 hints.ai_socktype = SOCK_STREAM;
56 snprintf(portstr, sizeof(portstr), "%d", port); 56 snprintf(portstr, sizeof(portstr), "%d", port);
57 if (getaddrinfo(hostname, portstr, &hints, &ai)) 57 ret = getaddrinfo(hostname, portstr, &hints, &ai);
58 if (ret) {
59 av_log(NULL, AV_LOG_ERROR,
60 "Failed to resolve hostname %s: %s\n",
61 hostname, gai_strerror(ret));
58 return AVERROR(EIO); 62 return AVERROR(EIO);
63 }
59 64
60 cur_ai = ai; 65 cur_ai = ai;
61 66
62 restart: 67 restart:
63 fd = socket(cur_ai->ai_family, cur_ai->ai_socktype, cur_ai->ai_protocol); 68 fd = socket(cur_ai->ai_family, cur_ai->ai_socktype, cur_ai->ai_protocol);
91 } 96 }
92 97
93 /* test error */ 98 /* test error */
94 optlen = sizeof(ret); 99 optlen = sizeof(ret);
95 getsockopt (fd, SOL_SOCKET, SO_ERROR, &ret, &optlen); 100 getsockopt (fd, SOL_SOCKET, SO_ERROR, &ret, &optlen);
96 if (ret != 0) 101 if (ret != 0) {
102 av_log(NULL, AV_LOG_ERROR,
103 "TCP connection to %s:%d failed: %s\n",
104 hostname, port, strerror(ret));
97 goto fail; 105 goto fail;
106 }
98 } 107 }
99 s = av_malloc(sizeof(TCPContext)); 108 s = av_malloc(sizeof(TCPContext));
100 if (!s) { 109 if (!s) {
101 freeaddrinfo(ai); 110 freeaddrinfo(ai);
102 return AVERROR(ENOMEM); 111 return AVERROR(ENOMEM);