Revision c24a4034

View differences:

ffserver.c
692 692
           second to handle timeouts */
693 693
        do {
694 694
            ret = poll(poll_table, poll_entry - poll_table, delay);
695
            if (ret < 0 && ff_neterrno() != FF_NETERROR(EAGAIN) &&
696
                ff_neterrno() != FF_NETERROR(EINTR))
695
            if (ret < 0 && ff_neterrno() != AVERROR(EAGAIN) &&
696
                ff_neterrno() != AVERROR(EINTR))
697 697
                return -1;
698 698
        } while (ret < 0);
699 699

  
......
916 916
    read_loop:
917 917
        len = recv(c->fd, c->buffer_ptr, 1, 0);
918 918
        if (len < 0) {
919
            if (ff_neterrno() != FF_NETERROR(EAGAIN) &&
920
                ff_neterrno() != FF_NETERROR(EINTR))
919
            if (ff_neterrno() != AVERROR(EAGAIN) &&
920
                ff_neterrno() != AVERROR(EINTR))
921 921
                return -1;
922 922
        } else if (len == 0) {
923 923
            return -1;
......
952 952
            return 0;
953 953
        len = send(c->fd, c->buffer_ptr, c->buffer_end - c->buffer_ptr, 0);
954 954
        if (len < 0) {
955
            if (ff_neterrno() != FF_NETERROR(EAGAIN) &&
956
                ff_neterrno() != FF_NETERROR(EINTR)) {
955
            if (ff_neterrno() != AVERROR(EAGAIN) &&
956
                ff_neterrno() != AVERROR(EINTR)) {
957 957
                /* error : close connection */
958 958
                av_freep(&c->pb_buffer);
959 959
                return -1;
......
1022 1022
            return 0;
1023 1023
        len = send(c->fd, c->buffer_ptr, c->buffer_end - c->buffer_ptr, 0);
1024 1024
        if (len < 0) {
1025
            if (ff_neterrno() != FF_NETERROR(EAGAIN) &&
1026
                ff_neterrno() != FF_NETERROR(EINTR)) {
1025
            if (ff_neterrno() != AVERROR(EAGAIN) &&
1026
                ff_neterrno() != AVERROR(EINTR)) {
1027 1027
                /* error : close connection */
1028 1028
                av_freep(&c->pb_buffer);
1029 1029
                return -1;
......
1049 1049
        len = send(c->fd, c->packet_buffer_ptr,
1050 1050
                    c->packet_buffer_end - c->packet_buffer_ptr, 0);
1051 1051
        if (len < 0) {
1052
            if (ff_neterrno() != FF_NETERROR(EAGAIN) &&
1053
                ff_neterrno() != FF_NETERROR(EINTR)) {
1052
            if (ff_neterrno() != AVERROR(EAGAIN) &&
1053
                ff_neterrno() != AVERROR(EINTR)) {
1054 1054
                /* error : close connection */
1055 1055
                av_freep(&c->packet_buffer);
1056 1056
                return -1;
......
2550 2550
                /* TCP data output */
2551 2551
                len = send(c->fd, c->buffer_ptr, c->buffer_end - c->buffer_ptr, 0);
2552 2552
                if (len < 0) {
2553
                    if (ff_neterrno() != FF_NETERROR(EAGAIN) &&
2554
                        ff_neterrno() != FF_NETERROR(EINTR))
2553
                    if (ff_neterrno() != AVERROR(EAGAIN) &&
2554
                        ff_neterrno() != AVERROR(EINTR))
2555 2555
                        /* error : close connection */
2556 2556
                        return -1;
2557 2557
                    else
......
2624 2624
        len = recv(c->fd, c->buffer_ptr, 1, 0);
2625 2625

  
2626 2626
        if (len < 0) {
2627
            if (ff_neterrno() != FF_NETERROR(EAGAIN) &&
2628
                ff_neterrno() != FF_NETERROR(EINTR))
2627
            if (ff_neterrno() != AVERROR(EAGAIN) &&
2628
                ff_neterrno() != AVERROR(EINTR))
2629 2629
                /* error : close connection */
2630 2630
                goto fail;
2631 2631
            return 0;
......
2651 2651
        len = recv(c->fd, c->buffer_ptr,
2652 2652
                   FFMIN(c->chunk_size, c->buffer_end - c->buffer_ptr), 0);
2653 2653
        if (len < 0) {
2654
            if (ff_neterrno() != FF_NETERROR(EAGAIN) &&
2655
                ff_neterrno() != FF_NETERROR(EINTR))
2654
            if (ff_neterrno() != AVERROR(EAGAIN) &&
2655
                ff_neterrno() != AVERROR(EINTR))
2656 2656
                /* error : close connection */
2657 2657
                goto fail;
2658 2658
        } else if (len == 0)
libavformat/network.h
27 27
#include <winsock2.h>
28 28
#include <ws2tcpip.h>
29 29

  
30
#define ff_neterrno() (-WSAGetLastError())
31
#define FF_NETERROR(err) (-WSA##err)
32
#define WSAEAGAIN WSAEWOULDBLOCK
30
#define EPROTONOSUPPORT WSAEPROTONOSUPPORT
31
#define ETIMEDOUT       WSAETIMEDOUT
32
#define ECONNREFUSED    WSAECONNREFUSED
33
#define EINPROGRESS     WSAEINPROGRESS
34

  
35
static inline int ff_neterrno() {
36
    int err = WSAGetLastError();
37
    switch (err) {
38
    case WSAEWOULDBLOCK:
39
        return AVERROR(EAGAIN);
40
    case WSAEINTR:
41
        return AVERROR(EINTR);
42
    }
43
    return -err;
44
}
33 45
#else
34 46
#include <sys/types.h>
35 47
#include <sys/socket.h>
......
37 49
#include <netdb.h>
38 50

  
39 51
#define ff_neterrno() AVERROR(errno)
40
#define FF_NETERROR(err) AVERROR(err)
41 52
#endif
42 53

  
43 54
#if HAVE_ARPA_INET_H
libavformat/rtpproto.c
231 231
        len = recvfrom (s->rtp_fd, buf, size, 0,
232 232
                        (struct sockaddr *)&from, &from_len);
233 233
        if (len < 0) {
234
            if (ff_neterrno() == FF_NETERROR(EAGAIN) ||
235
                ff_neterrno() == FF_NETERROR(EINTR))
234
            if (ff_neterrno() == AVERROR(EAGAIN) ||
235
                ff_neterrno() == AVERROR(EINTR))
236 236
                continue;
237 237
            return AVERROR(EIO);
238 238
        }
......
251 251
                len = recvfrom (s->rtcp_fd, buf, size, 0,
252 252
                                (struct sockaddr *)&from, &from_len);
253 253
                if (len < 0) {
254
                    if (ff_neterrno() == FF_NETERROR(EAGAIN) ||
255
                        ff_neterrno() == FF_NETERROR(EINTR))
254
                    if (ff_neterrno() == AVERROR(EAGAIN) ||
255
                        ff_neterrno() == AVERROR(EINTR))
256 256
                        continue;
257 257
                    return AVERROR(EIO);
258 258
                }
......
264 264
                len = recvfrom (s->rtp_fd, buf, size, 0,
265 265
                                (struct sockaddr *)&from, &from_len);
266 266
                if (len < 0) {
267
                    if (ff_neterrno() == FF_NETERROR(EAGAIN) ||
268
                        ff_neterrno() == FF_NETERROR(EINTR))
267
                    if (ff_neterrno() == AVERROR(EAGAIN) ||
268
                        ff_neterrno() == AVERROR(EINTR))
269 269
                        continue;
270 270
                    return AVERROR(EIO);
271 271
                }
272 272
                break;
273 273
            }
274 274
        } else if (n < 0) {
275
            if (ff_neterrno() == FF_NETERROR(EINTR))
275
            if (ff_neterrno() == AVERROR(EINTR))
276 276
                continue;
277 277
            return AVERROR(EIO);
278 278
        }
libavformat/rtsp.c
1528 1528
            goto fail;
1529 1529
        lower_transport_mask &= ~(1 << lower_transport);
1530 1530
        if (lower_transport_mask == 0 && err == 1) {
1531
            err = FF_NETERROR(EPROTONOSUPPORT);
1531
            err = AVERROR(EPROTONOSUPPORT);
1532 1532
            goto fail;
1533 1533
        }
1534 1534
    } while (err);
......
1615 1615
            }
1616 1616
#endif
1617 1617
        } else if (n == 0 && ++timeout_cnt >= MAX_TIMEOUTS) {
1618
            return FF_NETERROR(ETIMEDOUT);
1618
            return AVERROR(ETIMEDOUT);
1619 1619
        } else if (n < 0 && errno != EINTR)
1620 1620
            return AVERROR(errno);
1621 1621
    }
libavformat/rtspdec.c
311 311

  
312 312
    ret = ff_rtsp_fetch_packet(s, pkt);
313 313
    if (ret < 0) {
314
        if (ret == FF_NETERROR(ETIMEDOUT) && !rt->packets) {
314
        if (ret == AVERROR(ETIMEDOUT) && !rt->packets) {
315 315
            if (rt->lower_transport == RTSP_LOWER_TRANSPORT_UDP &&
316 316
                rt->lower_transport_mask & (1 << RTSP_LOWER_TRANSPORT_TCP)) {
317 317
                RTSPMessageHeader reply1, *reply = &reply1;
libavformat/sapenc.c
240 240
    if (!sap->last_time || now - sap->last_time > 5000000) {
241 241
        int ret = url_write(sap->ann_fd, sap->ann, sap->ann_size);
242 242
        /* Don't abort even if we get "Destination unreachable" */
243
        if (ret < 0 && ret != FF_NETERROR(ECONNREFUSED))
243
        if (ret < 0 && ret != AVERROR(ECONNREFUSED))
244 244
            return ret;
245 245
        sap->last_time = now;
246 246
    }
libavformat/tcp.c
72 72
    ret = connect(fd, cur_ai->ai_addr, cur_ai->ai_addrlen);
73 73
    if (ret < 0) {
74 74
        struct pollfd p = {fd, POLLOUT, 0};
75
        if (ff_neterrno() == FF_NETERROR(EINTR)) {
75
        if (ff_neterrno() == AVERROR(EINTR)) {
76 76
            if (url_interrupt_cb())
77 77
                goto fail1;
78 78
            goto redo;
79 79
        }
80
        if (ff_neterrno() != FF_NETERROR(EINPROGRESS) &&
81
            ff_neterrno() != FF_NETERROR(EAGAIN))
80
        if (ff_neterrno() != AVERROR(EINPROGRESS) &&
81
            ff_neterrno() != AVERROR(EAGAIN))
82 82
            goto fail;
83 83

  
84 84
        /* wait until we are connected or until abort */
......
136 136
    int ret;
137 137

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

  
142 142
static int tcp_read(URLContext *h, uint8_t *buf, int size)
libavformat/udp.c
455 455
            return AVERROR(EINTR);
456 456
        ret = poll(&p, 1, 100);
457 457
        if (ret < 0) {
458
            if (ff_neterrno() == FF_NETERROR(EINTR))
458
            if (ff_neterrno() == AVERROR(EINTR))
459 459
                continue;
460 460
            return AVERROR(EIO);
461 461
        }
......
463 463
            continue;
464 464
        len = recv(s->udp_fd, buf, size, 0);
465 465
        if (len < 0) {
466
            if (ff_neterrno() != FF_NETERROR(EAGAIN) &&
467
                ff_neterrno() != FF_NETERROR(EINTR))
466
            if (ff_neterrno() != AVERROR(EAGAIN) &&
467
                ff_neterrno() != AVERROR(EINTR))
468 468
                return AVERROR(EIO);
469 469
        } else {
470 470
            break;
......
486 486
        } else
487 487
            ret = send(s->udp_fd, buf, size, 0);
488 488
        if (ret < 0) {
489
            if (ff_neterrno() != FF_NETERROR(EINTR) &&
490
                ff_neterrno() != FF_NETERROR(EAGAIN))
489
            if (ff_neterrno() != AVERROR(EINTR) &&
490
                ff_neterrno() != AVERROR(EAGAIN))
491 491
                return ff_neterrno();
492 492
        } else {
493 493
            break;

Also available in: Unified diff