Revision ebba2b3e

View differences:

libavformat/network.h
55 55
#include <arpa/inet.h>
56 56
#endif
57 57

  
58
#if HAVE_POLL_H
59
#include <poll.h>
60
#endif
61

  
58 62
int ff_socket_nonblock(int socket, int enable);
59 63

  
60 64
static inline int ff_network_init(void)
......
67 71
    return 1;
68 72
}
69 73

  
74
static inline int ff_network_wait_fd(int fd, int write)
75
{
76
    int ev = write ? POLLOUT : POLLIN;
77
    struct pollfd p = { .fd = fd, .events = ev, .revents = 0 };
78
    int ret;
79
    ret = poll(&p, 1, 100);
80
    return ret < 0 ? ff_neterrno() : p.revents & ev ? 0 : AVERROR(EAGAIN);
81
}
82

  
70 83
static inline void ff_network_close(void)
71 84
{
72 85
#if HAVE_WINSOCK2_H
libavformat/tcp.c
131 131
    return ret;
132 132
}
133 133

  
134
static int tcp_wait_fd(int fd, int write)
135
{
136
    int ev = write ? POLLOUT : POLLIN;
137
    struct pollfd p = { .fd = fd, .events = ev, .revents = 0 };
138
    int ret;
139

  
140
    ret = poll(&p, 1, 100);
141
    return ret < 0 ? ff_neterrno() : p.revents & ev ? 0 : AVERROR(EAGAIN);
142
}
143

  
144 134
static int tcp_read(URLContext *h, uint8_t *buf, int size)
145 135
{
146 136
    TCPContext *s = h->priv_data;
147 137
    int ret;
148 138

  
149 139
    if (!(h->flags & URL_FLAG_NONBLOCK)) {
150
        ret = tcp_wait_fd(s->fd, 0);
140
        ret = ff_network_wait_fd(s->fd, 0);
151 141
        if (ret < 0)
152 142
            return ret;
153 143
    }
......
161 151
    int ret;
162 152

  
163 153
    if (!(h->flags & URL_FLAG_NONBLOCK)) {
164
        ret = tcp_wait_fd(s->fd, 1);
154
        ret = ff_network_wait_fd(s->fd, 1);
165 155
        if (ret < 0)
166 156
            return ret;
167 157
    }
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