Revision 3ce3b498

View differences:

libavformat/avio.c
206 206
    return ret;
207 207
}
208 208

  
209
int url_read(URLContext *h, unsigned char *buf, int size)
210
{
211
    int ret;
212
    if (h->flags & URL_WRONLY)
213
        return AVERROR(EIO);
214
    ret = h->prot->url_read(h, buf, size);
215
    return ret;
216
}
217

  
218
static inline int retry_transfer_wrapper(URLContext *h, unsigned char *buf, int size,
209
static inline int retry_transfer_wrapper(URLContext *h, unsigned char *buf, int size, int size_min,
219 210
                                         int (*transfer_func)(URLContext *h, unsigned char *buf, int size))
220 211
{
221 212
    int ret, len;
222 213
    int fast_retries = 5;
223 214

  
224 215
    len = 0;
225
    while (len < size) {
216
    while (len < size_min) {
217
        if (url_interrupt_cb())
218
            return AVERROR(EINTR);
226 219
        ret = transfer_func(h, buf+len, size-len);
220
        if (ret == AVERROR(EINTR))
221
            continue;
222
        if (h->flags & URL_FLAG_NONBLOCK)
223
            return ret;
227 224
        if (ret == AVERROR(EAGAIN)) {
228 225
            ret = 0;
229 226
            if (fast_retries)
......
239 236
    return len;
240 237
}
241 238

  
239
int url_read(URLContext *h, unsigned char *buf, int size)
240
{
241
    if (h->flags & URL_WRONLY)
242
        return AVERROR(EIO);
243
    return retry_transfer_wrapper(h, buf, size, 1, h->prot->url_read);
244
}
245

  
242 246
int url_read_complete(URLContext *h, unsigned char *buf, int size)
243 247
{
244
    return retry_transfer_wrapper(h, buf, size, url_read);
248
    if (h->flags & URL_WRONLY)
249
        return AVERROR(EIO);
250
    return retry_transfer_wrapper(h, buf, size, size, h->prot->url_read);
245 251
}
246 252

  
247 253
int url_write(URLContext *h, const unsigned char *buf, int size)
......
252 258
    if (h->max_packet_size && size > h->max_packet_size)
253 259
        return AVERROR(EIO);
254 260

  
255
    return retry_transfer_wrapper(h, buf, size, h->prot->url_write);
261
    return retry_transfer_wrapper(h, buf, size, size, h->prot->url_write);
256 262
}
257 263

  
258 264
int64_t url_seek(URLContext *h, int64_t pos, int whence)
libavformat/avio.h
151 151
/**
152 152
 * Read as many bytes as possible (up to size), calling the
153 153
 * read function multiple times if necessary.
154
 * Will also retry if the read function returns AVERROR(EAGAIN).
155 154
 * This makes special short-read handling in applications
156 155
 * unnecessary, if the return value is < size then it is
157 156
 * certain there was either an error or the end of file was reached.

Also available in: Unified diff