libavformat: Remove FF_NETERRNO()

Map EAGAIN and EINTR from ff_neterrno to the normal AVERROR()
error codes. Provide fallback definitions of other errno.h network
errors, mapping them to the corresponding winsock errors.

This eases catching these error codes in common code, without having
to distinguish between FF_NETERRNO(EAGAIN) and AVERROR(EAGAIN).

This fixes roundup issue 2614, unbreaking blocking network IO on
windows.

Signed-off-by: Ronald S. Bultje <rsbultje@gmail.com>
This commit is contained in:
Martin Storsjö 2011-02-19 19:14:11 +01:00 committed by Ronald S. Bultje
parent 8f935b9271
commit 28c4741a66
8 changed files with 51 additions and 40 deletions

View File

@ -692,8 +692,8 @@ static int http_server(void)
second to handle timeouts */
do {
ret = poll(poll_table, poll_entry - poll_table, delay);
if (ret < 0 && ff_neterrno() != FF_NETERROR(EAGAIN) &&
ff_neterrno() != FF_NETERROR(EINTR))
if (ret < 0 && ff_neterrno() != AVERROR(EAGAIN) &&
ff_neterrno() != AVERROR(EINTR))
return -1;
} while (ret < 0);
@ -916,8 +916,8 @@ static int handle_connection(HTTPContext *c)
read_loop:
len = recv(c->fd, c->buffer_ptr, 1, 0);
if (len < 0) {
if (ff_neterrno() != FF_NETERROR(EAGAIN) &&
ff_neterrno() != FF_NETERROR(EINTR))
if (ff_neterrno() != AVERROR(EAGAIN) &&
ff_neterrno() != AVERROR(EINTR))
return -1;
} else if (len == 0) {
return -1;
@ -952,8 +952,8 @@ static int handle_connection(HTTPContext *c)
return 0;
len = send(c->fd, c->buffer_ptr, c->buffer_end - c->buffer_ptr, 0);
if (len < 0) {
if (ff_neterrno() != FF_NETERROR(EAGAIN) &&
ff_neterrno() != FF_NETERROR(EINTR)) {
if (ff_neterrno() != AVERROR(EAGAIN) &&
ff_neterrno() != AVERROR(EINTR)) {
/* error : close connection */
av_freep(&c->pb_buffer);
return -1;
@ -1022,8 +1022,8 @@ static int handle_connection(HTTPContext *c)
return 0;
len = send(c->fd, c->buffer_ptr, c->buffer_end - c->buffer_ptr, 0);
if (len < 0) {
if (ff_neterrno() != FF_NETERROR(EAGAIN) &&
ff_neterrno() != FF_NETERROR(EINTR)) {
if (ff_neterrno() != AVERROR(EAGAIN) &&
ff_neterrno() != AVERROR(EINTR)) {
/* error : close connection */
av_freep(&c->pb_buffer);
return -1;
@ -1049,8 +1049,8 @@ static int handle_connection(HTTPContext *c)
len = send(c->fd, c->packet_buffer_ptr,
c->packet_buffer_end - c->packet_buffer_ptr, 0);
if (len < 0) {
if (ff_neterrno() != FF_NETERROR(EAGAIN) &&
ff_neterrno() != FF_NETERROR(EINTR)) {
if (ff_neterrno() != AVERROR(EAGAIN) &&
ff_neterrno() != AVERROR(EINTR)) {
/* error : close connection */
av_freep(&c->packet_buffer);
return -1;
@ -2550,8 +2550,8 @@ static int http_send_data(HTTPContext *c)
/* TCP data output */
len = send(c->fd, c->buffer_ptr, c->buffer_end - c->buffer_ptr, 0);
if (len < 0) {
if (ff_neterrno() != FF_NETERROR(EAGAIN) &&
ff_neterrno() != FF_NETERROR(EINTR))
if (ff_neterrno() != AVERROR(EAGAIN) &&
ff_neterrno() != AVERROR(EINTR))
/* error : close connection */
return -1;
else
@ -2624,8 +2624,8 @@ static int http_receive_data(HTTPContext *c)
len = recv(c->fd, c->buffer_ptr, 1, 0);
if (len < 0) {
if (ff_neterrno() != FF_NETERROR(EAGAIN) &&
ff_neterrno() != FF_NETERROR(EINTR))
if (ff_neterrno() != AVERROR(EAGAIN) &&
ff_neterrno() != AVERROR(EINTR))
/* error : close connection */
goto fail;
return 0;
@ -2651,8 +2651,8 @@ static int http_receive_data(HTTPContext *c)
len = recv(c->fd, c->buffer_ptr,
FFMIN(c->chunk_size, c->buffer_end - c->buffer_ptr), 0);
if (len < 0) {
if (ff_neterrno() != FF_NETERROR(EAGAIN) &&
ff_neterrno() != FF_NETERROR(EINTR))
if (ff_neterrno() != AVERROR(EAGAIN) &&
ff_neterrno() != AVERROR(EINTR))
/* error : close connection */
goto fail;
} else if (len == 0)

View File

@ -27,9 +27,21 @@
#include <winsock2.h>
#include <ws2tcpip.h>
#define ff_neterrno() (-WSAGetLastError())
#define FF_NETERROR(err) (-WSA##err)
#define WSAEAGAIN WSAEWOULDBLOCK
#define EPROTONOSUPPORT WSAEPROTONOSUPPORT
#define ETIMEDOUT WSAETIMEDOUT
#define ECONNREFUSED WSAECONNREFUSED
#define EINPROGRESS WSAEINPROGRESS
static inline int ff_neterrno() {
int err = WSAGetLastError();
switch (err) {
case WSAEWOULDBLOCK:
return AVERROR(EAGAIN);
case WSAEINTR:
return AVERROR(EINTR);
}
return -err;
}
#else
#include <sys/types.h>
#include <sys/socket.h>
@ -37,7 +49,6 @@
#include <netdb.h>
#define ff_neterrno() AVERROR(errno)
#define FF_NETERROR(err) AVERROR(err)
#endif
#if HAVE_ARPA_INET_H

View File

@ -231,8 +231,8 @@ static int rtp_read(URLContext *h, uint8_t *buf, int size)
len = recvfrom (s->rtp_fd, buf, size, 0,
(struct sockaddr *)&from, &from_len);
if (len < 0) {
if (ff_neterrno() == FF_NETERROR(EAGAIN) ||
ff_neterrno() == FF_NETERROR(EINTR))
if (ff_neterrno() == AVERROR(EAGAIN) ||
ff_neterrno() == AVERROR(EINTR))
continue;
return AVERROR(EIO);
}
@ -251,8 +251,8 @@ static int rtp_read(URLContext *h, uint8_t *buf, int size)
len = recvfrom (s->rtcp_fd, buf, size, 0,
(struct sockaddr *)&from, &from_len);
if (len < 0) {
if (ff_neterrno() == FF_NETERROR(EAGAIN) ||
ff_neterrno() == FF_NETERROR(EINTR))
if (ff_neterrno() == AVERROR(EAGAIN) ||
ff_neterrno() == AVERROR(EINTR))
continue;
return AVERROR(EIO);
}
@ -264,15 +264,15 @@ static int rtp_read(URLContext *h, uint8_t *buf, int size)
len = recvfrom (s->rtp_fd, buf, size, 0,
(struct sockaddr *)&from, &from_len);
if (len < 0) {
if (ff_neterrno() == FF_NETERROR(EAGAIN) ||
ff_neterrno() == FF_NETERROR(EINTR))
if (ff_neterrno() == AVERROR(EAGAIN) ||
ff_neterrno() == AVERROR(EINTR))
continue;
return AVERROR(EIO);
}
break;
}
} else if (n < 0) {
if (ff_neterrno() == FF_NETERROR(EINTR))
if (ff_neterrno() == AVERROR(EINTR))
continue;
return AVERROR(EIO);
}

View File

@ -1528,7 +1528,7 @@ redirect:
goto fail;
lower_transport_mask &= ~(1 << lower_transport);
if (lower_transport_mask == 0 && err == 1) {
err = FF_NETERROR(EPROTONOSUPPORT);
err = AVERROR(EPROTONOSUPPORT);
goto fail;
}
} while (err);
@ -1615,7 +1615,7 @@ static int udp_read_packet(AVFormatContext *s, RTSPStream **prtsp_st,
}
#endif
} else if (n == 0 && ++timeout_cnt >= MAX_TIMEOUTS) {
return FF_NETERROR(ETIMEDOUT);
return AVERROR(ETIMEDOUT);
} else if (n < 0 && errno != EINTR)
return AVERROR(errno);
}

View File

@ -311,7 +311,7 @@ retry:
ret = ff_rtsp_fetch_packet(s, pkt);
if (ret < 0) {
if (ret == FF_NETERROR(ETIMEDOUT) && !rt->packets) {
if (ret == AVERROR(ETIMEDOUT) && !rt->packets) {
if (rt->lower_transport == RTSP_LOWER_TRANSPORT_UDP &&
rt->lower_transport_mask & (1 << RTSP_LOWER_TRANSPORT_TCP)) {
RTSPMessageHeader reply1, *reply = &reply1;

View File

@ -240,7 +240,7 @@ static int sap_write_packet(AVFormatContext *s, AVPacket *pkt)
if (!sap->last_time || now - sap->last_time > 5000000) {
int ret = url_write(sap->ann_fd, sap->ann, sap->ann_size);
/* Don't abort even if we get "Destination unreachable" */
if (ret < 0 && ret != FF_NETERROR(ECONNREFUSED))
if (ret < 0 && ret != AVERROR(ECONNREFUSED))
return ret;
sap->last_time = now;
}

View File

@ -72,13 +72,13 @@ static int tcp_open(URLContext *h, const char *uri, int flags)
ret = connect(fd, cur_ai->ai_addr, cur_ai->ai_addrlen);
if (ret < 0) {
struct pollfd p = {fd, POLLOUT, 0};
if (ff_neterrno() == FF_NETERROR(EINTR)) {
if (ff_neterrno() == AVERROR(EINTR)) {
if (url_interrupt_cb())
goto fail1;
goto redo;
}
if (ff_neterrno() != FF_NETERROR(EINPROGRESS) &&
ff_neterrno() != FF_NETERROR(EAGAIN))
if (ff_neterrno() != AVERROR(EINPROGRESS) &&
ff_neterrno() != AVERROR(EAGAIN))
goto fail;
/* wait until we are connected or until abort */
@ -136,7 +136,7 @@ static int tcp_wait_fd(int fd, int write)
int ret;
ret = poll(&p, 1, 100);
return ret < 0 ? ff_neterrno() : p.revents & ev ? 0 : FF_NETERROR(EAGAIN);
return ret < 0 ? ff_neterrno() : p.revents & ev ? 0 : AVERROR(EAGAIN);
}
static int tcp_read(URLContext *h, uint8_t *buf, int size)

View File

@ -455,7 +455,7 @@ static int udp_read(URLContext *h, uint8_t *buf, int size)
return AVERROR(EINTR);
ret = poll(&p, 1, 100);
if (ret < 0) {
if (ff_neterrno() == FF_NETERROR(EINTR))
if (ff_neterrno() == AVERROR(EINTR))
continue;
return AVERROR(EIO);
}
@ -463,8 +463,8 @@ static int udp_read(URLContext *h, uint8_t *buf, int size)
continue;
len = recv(s->udp_fd, buf, size, 0);
if (len < 0) {
if (ff_neterrno() != FF_NETERROR(EAGAIN) &&
ff_neterrno() != FF_NETERROR(EINTR))
if (ff_neterrno() != AVERROR(EAGAIN) &&
ff_neterrno() != AVERROR(EINTR))
return AVERROR(EIO);
} else {
break;
@ -486,8 +486,8 @@ static int udp_write(URLContext *h, const uint8_t *buf, int size)
} else
ret = send(s->udp_fd, buf, size, 0);
if (ret < 0) {
if (ff_neterrno() != FF_NETERROR(EINTR) &&
ff_neterrno() != FF_NETERROR(EAGAIN))
if (ff_neterrno() != AVERROR(EINTR) &&
ff_neterrno() != AVERROR(EAGAIN))
return ff_neterrno();
} else {
break;