- }
- goto redo;
- }
- if (ret != AVERROR(EINPROGRESS) &&
- ret != AVERROR(EAGAIN))
- goto fail;
-
- /* wait until we are connected or until abort */
- while(timeout--) {
- if (ff_check_interrupt(&h->interrupt_callback)) {
- ret = AVERROR_EXIT;
- goto fail1;
- }
- ret = poll(&p, 1, 100);
- if (ret > 0)
- break;
- }
- if (ret <= 0) {
- ret = AVERROR(ETIMEDOUT);
- goto fail;
- }
- /* test error */
- optlen = sizeof(ret);
- if (getsockopt (fd, SOL_SOCKET, SO_ERROR, &ret, &optlen))
- ret = AVUNERROR(ff_neterrno());
- 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, errbuf);
- goto fail;