Revision ebba2b3e libavformat/udp.c

View differences:

libavformat/udp.c
33 33
#include "internal.h"
34 34
#include "network.h"
35 35
#include "os_support.h"
36
#if HAVE_POLL_H
37
#include <poll.h>
38
#endif
39 36
#include <sys/time.h>
40 37

  
41 38
#ifndef IPV6_ADD_MEMBERSHIP
......
447 444
static int udp_read(URLContext *h, uint8_t *buf, int size)
448 445
{
449 446
    UDPContext *s = h->priv_data;
450
    struct pollfd p = {s->udp_fd, POLLIN, 0};
451
    int len;
452 447
    int ret;
453 448

  
454
    for(;;) {
455
        if (url_interrupt_cb())
456
            return AVERROR_EXIT;
457
        ret = poll(&p, 1, 100);
458
        if (ret < 0) {
459
            if (ff_neterrno() == AVERROR(EINTR))
460
                continue;
461
            return AVERROR(EIO);
462
        }
463
        if (!(ret == 1 && p.revents & POLLIN))
464
            continue;
465
        len = recv(s->udp_fd, buf, size, 0);
466
        if (len < 0) {
467
            if (ff_neterrno() != AVERROR(EAGAIN) &&
468
                ff_neterrno() != AVERROR(EINTR))
469
                return AVERROR(EIO);
470
        } else {
471
            break;
472
        }
449
    if (!(h->flags & URL_FLAG_NONBLOCK)) {
450
        ret = ff_network_wait_fd(s->udp_fd, 0);
451
        if (ret < 0)
452
            return ret;
473 453
    }
474
    return len;
454
    ret = recv(s->udp_fd, buf, size, 0);
455
    return ret < 0 ? ff_neterrno() : ret;
475 456
}
476 457

  
477 458
static int udp_write(URLContext *h, const uint8_t *buf, int size)
......
479 460
    UDPContext *s = h->priv_data;
480 461
    int ret;
481 462

  
482
    for(;;) {
483
        if (!s->is_connected) {
484
            ret = sendto (s->udp_fd, buf, size, 0,
485
                          (struct sockaddr *) &s->dest_addr,
486
                          s->dest_addr_len);
487
        } else
488
            ret = send(s->udp_fd, buf, size, 0);
489
        if (ret < 0) {
490
            if (ff_neterrno() != AVERROR(EINTR) &&
491
                ff_neterrno() != AVERROR(EAGAIN))
492
                return ff_neterrno();
493
        } else {
494
            break;
495
        }
463
    if (!(h->flags & URL_FLAG_NONBLOCK)) {
464
        ret = ff_network_wait_fd(s->udp_fd, 1);
465
        if (ret < 0)
466
            return ret;
496 467
    }
497
    return size;
468

  
469
    if (!s->is_connected) {
470
        ret = sendto (s->udp_fd, buf, size, 0,
471
                      (struct sockaddr *) &s->dest_addr,
472
                      s->dest_addr_len);
473
    } else
474
        ret = send(s->udp_fd, buf, size, 0);
475

  
476
    return ret < 0 ? ff_neterrno() : ret;
498 477
}
499 478

  
500 479
static int udp_close(URLContext *h)

Also available in: Unified diff