int ff_listen_connect(int fd, const struct sockaddr *addr,

                      socklen_t addrlen, int timeout, URLContext *h)

{

    struct pollfd p = {fd, POLLOUT, 0};

    int ret;

    socklen_t optlen;



    ff_socket_nonblock(fd, 1);



    while ((ret = connect(fd, addr, addrlen))) {

        ret = ff_neterrno();

        switch (ret) {

        case AVERROR(EINTR):

            if (ff_check_interrupt(&h->interrupt_callback))

                return AVERROR_EXIT;

            continue;

        case AVERROR(EINPROGRESS):

        case AVERROR(EAGAIN):

            while (timeout--) {

                if (ff_check_interrupt(&h->interrupt_callback))

                    return AVERROR_EXIT;

                ret = poll(&p, 1, 100);

                if (ret > 0)

                    break;

            }

            if (ret <= 0)

                return AVERROR(ETIMEDOUT);

            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,

                       "Connection to %s failed: %s\n",

                       h->filename, errbuf);

            }

        default:

            return ret;

        }

    }

    return ret;

}

int ff_listen_connect(int fd, const struct sockaddr *addr,

                      socklen_t addrlen, int timeout, URLContext *h)

{

    struct pollfd p = {fd, POLLOUT, 0};

    int ret;

    socklen_t optlen;



    ff_socket_nonblock(fd, 1);



    while ((ret = connect(fd, addr, addrlen))) {

        ret = ff_neterrno();

        switch (ret) {

        case AVERROR(EINTR):

            if (ff_check_interrupt(&h->interrupt_callback))

                return AVERROR_EXIT;

            continue;

        case AVERROR(EINPROGRESS):

        case AVERROR(EAGAIN):

            while (timeout--) {

                if (ff_check_interrupt(&h->interrupt_callback))

                    return AVERROR_EXIT;

                ret = poll(&p, 1, 100);

                if (ret > 0)

                    break;

            }

            if (ret <= 0)

                return AVERROR(ETIMEDOUT);

            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,

                       "Connection to %s failed: %s\n",

                       h->filename, errbuf);

            }

        default:

            return ret;

        }

    }

    return ret;

}

int FUNC_0(int VAR_0, const struct sockaddr *VAR_1,

                      socklen_t VAR_2, int VAR_3, URLContext *VAR_4)

{

    struct pollfd VAR_5 = {VAR_0, POLLOUT, 0};

    int VAR_6;

    socklen_t optlen;



    ff_socket_nonblock(VAR_0, 1);



    while ((VAR_6 = connect(VAR_0, VAR_1, VAR_2))) {

        VAR_6 = ff_neterrno();

        switch (VAR_6) {

        case AVERROR(EINTR):

            if (ff_check_interrupt(&VAR_4->interrupt_callback))

                return AVERROR_EXIT;

            continue;

        case AVERROR(EINPROGRESS):

        case AVERROR(EAGAIN):

            while (VAR_3--) {

                if (ff_check_interrupt(&VAR_4->interrupt_callback))

                    return AVERROR_EXIT;

                VAR_6 = poll(&VAR_5, 1, 100);

                if (VAR_6 > 0)

                    break;

            }

            if (VAR_6 <= 0)

                return AVERROR(ETIMEDOUT);

            optlen = sizeof(VAR_6);

            if (getsockopt (VAR_0, SOL_SOCKET, SO_ERROR, &VAR_6, &optlen))

                VAR_6 = AVUNERROR(ff_neterrno());

            if (VAR_6 != 0) {

                char VAR_7[100];

                VAR_6 = AVERROR(VAR_6);

                av_strerror(VAR_6, VAR_7, sizeof(VAR_7));

                av_log(VAR_4, AV_LOG_ERROR,

                       "Connection to %s failed: %s\n",

                       VAR_4->filename, VAR_7);

            }

        default:

            return VAR_6;

        }

    }

    return VAR_6;

}

int FUNC_0(int VAR_0, const struct sockaddr *VAR_1,
socklen_t VAR_2, int VAR_3, URLContext *VAR_4)
{ struct pollfd VAR_5 = {VAR_0, POLLOUT, 0}; int VAR_6; socklen_t optlen; ff_socket_nonblock(VAR_0, 1); while ((VAR_6 = connect(VAR_0, VAR_1, VAR_2))) { VAR_6 = ff_neterrno(); switch (VAR_6) { case AVERROR(EINTR):
if (ff_check_interrupt(&VAR_4->interrupt_callback))
return AVERROR_EXIT; continue; case AVERROR(EINPROGRESS):
case AVERROR(EAGAIN):
while (VAR_3--) { if (ff_check_interrupt(&VAR_4->interrupt_callback))
return AVERROR_EXIT; VAR_6 = poll(&VAR_5, 1, 100); if (VAR_6 > 0)
break; } if (VAR_6 <= 0)
return AVERROR(ETIMEDOUT); optlen = sizeof(VAR_6); if (getsockopt (VAR_0, SOL_SOCKET, SO_ERROR, &VAR_6, &optlen))
VAR_6 = AVUNERROR(ff_neterrno()); if (VAR_6 != 0) { char VAR_7[100]; VAR_6 = AVERROR(VAR_6); av_strerror(VAR_6, VAR_7, sizeof(VAR_7)); av_log(VAR_4, AV_LOG_ERROR,
"Connection to %s failed: %s\n",
VAR_4->filename, VAR_7); } default:
return VAR_6; } } return VAR_6; }