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

{

    TCPContext *s = h->priv_data;

    int ret, size1, fd_max;

    fd_set wfds;

    struct timeval tv;



    size1 = size;

    while (size > 0) {

        if (url_interrupt_cb())

            return -EINTR;

        fd_max = s->fd;

        FD_ZERO(&wfds);

        FD_SET(s->fd, &wfds);

        tv.tv_sec = 0;

        tv.tv_usec = 100 * 1000;

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

#ifdef __BEOS__

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

#else

        ret = write(s->fd, buf, size);

#endif

        if (ret < 0) {

            if (errno != EINTR && errno != EAGAIN) {

#ifdef __BEOS__

                return errno;

#else

                return -errno;

#endif

            }

            continue;

        }

        size -= ret;

        buf += ret;

    }

    return size1 - size;

}

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

{

    TCPContext *s = h->priv_data;

    int ret, size1, fd_max;

    fd_set wfds;

    struct timeval tv;



    size1 = size;

    while (size > 0) {

        if (url_interrupt_cb())

            return -EINTR;

        fd_max = s->fd;

        FD_ZERO(&wfds);

        FD_SET(s->fd, &wfds);

        tv.tv_sec = 0;

        tv.tv_usec = 100 * 1000;

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

#ifdef __BEOS__

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

#else

        ret = write(s->fd, buf, size);

#endif

        if (ret < 0) {

            if (errno != EINTR && errno != EAGAIN) {

#ifdef __BEOS__

                return errno;

#else

                return -errno;

#endif

            }

            continue;

        }

        size -= ret;

        buf += ret;

    }

    return size1 - size;

}

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

{

    TCPContext *s = VAR_0->priv_data;

    int VAR_3, VAR_4, VAR_5;

    fd_set wfds;

    struct timeval VAR_6;



    VAR_4 = VAR_2;

    while (VAR_2 > 0) {

        if (url_interrupt_cb())

            return -EINTR;

        VAR_5 = s->fd;

        FD_ZERO(&wfds);

        FD_SET(s->fd, &wfds);

        VAR_6.tv_sec = 0;

        VAR_6.tv_usec = 100 * 1000;

        select(VAR_5 + 1, NULL, &wfds, NULL, &VAR_6);

#ifdef __BEOS__

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

#else

        VAR_3 = write(s->fd, VAR_1, VAR_2);

#endif

        if (VAR_3 < 0) {

            if (errno != EINTR && errno != EAGAIN) {

#ifdef __BEOS__

                return errno;

#else

                return -errno;

#endif

            }

            continue;

        }

        VAR_2 -= VAR_3;

        VAR_1 += VAR_3;

    }

    return VAR_4 - VAR_2;

}

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