static int tcp_write(URLContext *h, const uint8_t *buf, int size)

{

    TCPContext *s = h->priv_data;

    int ret, size1, fd_max, len;

    fd_set wfds;

    struct timeval tv;



    size1 = size;

    while (size > 0) {

        if (url_interrupt_cb())

            return AVERROR(EINTR);

        fd_max = s->fd;

        FD_ZERO(&wfds);

        FD_SET(s->fd, &wfds);

        tv.tv_sec = 0;

        tv.tv_usec = 100 * 1000;

        ret = select(fd_max + 1, NULL, &wfds, NULL, &tv);

        if (ret > 0 && FD_ISSET(s->fd, &wfds)) {

            len = send(s->fd, buf, size, 0);

            if (len < 0) {

                if (ff_neterrno() != FF_NETERROR(EINTR) &&

                    ff_neterrno() != FF_NETERROR(EAGAIN))

                    return ff_neterrno();

                continue;

            }

            size -= len;

            buf += len;

        } else if (ret < 0) {

            if (ff_neterrno() == FF_NETERROR(EINTR))

                continue;

            return -1;

        }

    }

    return size1 - size;

}

static int tcp_write(URLContext *h, const uint8_t *buf, int size)

{

    TCPContext *s = h->priv_data;

    int ret, size1, fd_max, len;

    fd_set wfds;

    struct timeval tv;



    size1 = size;

    while (size > 0) {

        if (url_interrupt_cb())

            return AVERROR(EINTR);

        fd_max = s->fd;

        FD_ZERO(&wfds);

        FD_SET(s->fd, &wfds);

        tv.tv_sec = 0;

        tv.tv_usec = 100 * 1000;

        ret = select(fd_max + 1, NULL, &wfds, NULL, &tv);

        if (ret > 0 && FD_ISSET(s->fd, &wfds)) {

            len = send(s->fd, buf, size, 0);

            if (len < 0) {

                if (ff_neterrno() != FF_NETERROR(EINTR) &&

                    ff_neterrno() != FF_NETERROR(EAGAIN))

                    return ff_neterrno();

                continue;

            }

            size -= len;

            buf += len;

        } else if (ret < 0) {

            if (ff_neterrno() == FF_NETERROR(EINTR))

                continue;

            return -1;

        }

    }

    return size1 - size;

}

static int FUNC_0(URLContext *VAR_0, const uint8_t *VAR_1, int VAR_2)

{

    TCPContext *s = VAR_0->priv_data;

    int VAR_3, VAR_4, VAR_5, VAR_6;

    fd_set wfds;

    struct timeval VAR_7;



    VAR_4 = VAR_2;

    while (VAR_2 > 0) {

        if (url_interrupt_cb())

            return AVERROR(EINTR);

        VAR_5 = s->fd;

        FD_ZERO(&wfds);

        FD_SET(s->fd, &wfds);

        VAR_7.tv_sec = 0;

        VAR_7.tv_usec = 100 * 1000;

        VAR_3 = select(VAR_5 + 1, NULL, &wfds, NULL, &VAR_7);

        if (VAR_3 > 0 && FD_ISSET(s->fd, &wfds)) {

            VAR_6 = send(s->fd, VAR_1, VAR_2, 0);

            if (VAR_6 < 0) {

                if (ff_neterrno() != FF_NETERROR(EINTR) &&

                    ff_neterrno() != FF_NETERROR(EAGAIN))

                    return ff_neterrno();

                continue;

            }

            VAR_2 -= VAR_6;

            VAR_1 += VAR_6;

        } else if (VAR_3 < 0) {

            if (ff_neterrno() == FF_NETERROR(EINTR))

                continue;

            return -1;

        }

    }

    return VAR_4 - VAR_2;

}

static int FUNC_0(URLContext *VAR_0, const uint8_t *VAR_1, int VAR_2)
{ TCPContext *s = VAR_0->priv_data; int VAR_3, VAR_4, VAR_5, VAR_6; fd_set wfds; struct timeval VAR_7; VAR_4 = VAR_2; while (VAR_2 > 0) { if (url_interrupt_cb())
return AVERROR(EINTR); VAR_5 = s->fd; FD_ZERO(&wfds); FD_SET(s->fd, &wfds); VAR_7.tv_sec = 0; VAR_7.tv_usec = 100 * 1000; VAR_3 = select(VAR_5 + 1, NULL, &wfds, NULL, &VAR_7); if (VAR_3 > 0 && FD_ISSET(s->fd, &wfds)) { VAR_6 = send(s->fd, VAR_1, VAR_2, 0); if (VAR_6 < 0) { if (ff_neterrno() != FF_NETERROR(EINTR) &&
ff_neterrno() != FF_NETERROR(EAGAIN))
return ff_neterrno(); continue; } VAR_2 -= VAR_6; VAR_1 += VAR_6; } else if (VAR_3 < 0) { if (ff_neterrno() == FF_NETERROR(EINTR))
continue; return -1; } } return VAR_4 - VAR_2; }