Revision 6e59474b libavformat/tcp.c

View differences:

libavformat/tcp.c
136 136
    int ret;
137 137

  
138 138
    ret = poll(&p, 1, 100);
139
    return ret < 0 ? ff_neterrno() : !!(p.revents & ev);
139
    return ret < 0 ? ff_neterrno() : p.revents & ev ? 0 : FF_NETERROR(EAGAIN);
140 140
}
141 141

  
142 142
static int tcp_read(URLContext *h, uint8_t *buf, int size)
143 143
{
144 144
    TCPContext *s = h->priv_data;
145
    int len, ret;
145
    int ret;
146 146

  
147
    for (;;) {
148
        if (url_interrupt_cb())
149
            return AVERROR(EINTR);
147
    if (!(h->flags & URL_FLAG_NONBLOCK)) {
150 148
        ret = tcp_wait_fd(s->fd, 0);
151
        if (ret > 0) {
152
            len = recv(s->fd, buf, size, 0);
153
            if (len < 0) {
154
                if (ff_neterrno() != FF_NETERROR(EINTR) &&
155
                    ff_neterrno() != FF_NETERROR(EAGAIN))
156
                    return ff_neterrno();
157
            } else return len;
158
        } else if (ret < 0) {
159
            if (ret == FF_NETERROR(EINTR))
160
                continue;
149
        if (ret < 0)
161 150
            return ret;
162
        }
163 151
    }
152
    ret = recv(s->fd, buf, size, 0);
153
    return ret < 0 ? ff_neterrno() : ret;
164 154
}
165 155

  
166 156
static int tcp_write(URLContext *h, const uint8_t *buf, int size)
167 157
{
168 158
    TCPContext *s = h->priv_data;
169
    int ret, size1, len;
159
    int ret;
170 160

  
171
    size1 = size;
172
    while (size > 0) {
173
        if (url_interrupt_cb())
174
            return AVERROR(EINTR);
161
    if (!(h->flags & URL_FLAG_NONBLOCK)) {
175 162
        ret = tcp_wait_fd(s->fd, 1);
176
        if (ret > 0) {
177
            len = send(s->fd, buf, size, 0);
178
            if (len < 0) {
179
                if (ff_neterrno() != FF_NETERROR(EINTR) &&
180
                    ff_neterrno() != FF_NETERROR(EAGAIN))
181
                    return ff_neterrno();
182
                continue;
183
            }
184
            size -= len;
185
            buf += len;
186
        } else if (ret < 0) {
187
            if (ret == FF_NETERROR(EINTR))
188
                continue;
163
        if (ret < 0)
189 164
            return ret;
190
        }
191 165
    }
192
    return size1 - size;
166
    ret = send(s->fd, buf, size, 0);
167
    return ret < 0 ? ff_neterrno() : ret;
193 168
}
194 169

  
195 170
static int tcp_close(URLContext *h)

Also available in: Unified diff