summaryrefslogtreecommitdiff
path: root/libavformat
diff options
context:
space:
mode:
authorMartin Storsjö <martin@martin.st>2011-02-19 19:14:11 +0100
committerMichael Niedermayer <michaelni@gmx.at>2011-02-23 18:22:03 +0100
commitc24a40349693e50aa81ef68a4a522503ca504d50 (patch)
tree155a362ee2fcc37441f2b96981b9fa25a3892b20 /libavformat
parent8e35f5d4fad523c1a1f0a4d9e4b74e7f1c5b990d (diff)
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> (cherry picked from commit 28c4741a6617a4c1d2490cb13fc70ae4c9c472da)
Diffstat (limited to 'libavformat')
-rw-r--r--libavformat/network.h19
-rw-r--r--libavformat/rtpproto.c14
-rw-r--r--libavformat/rtsp.c4
-rw-r--r--libavformat/rtspdec.c2
-rw-r--r--libavformat/sapenc.c2
-rw-r--r--libavformat/tcp.c8
-rw-r--r--libavformat/udp.c10
7 files changed, 35 insertions, 24 deletions
diff --git a/libavformat/network.h b/libavformat/network.h
index d6aee93121..58a8e80e72 100644
--- a/libavformat/network.h
+++ b/libavformat/network.h
@@ -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
diff --git a/libavformat/rtpproto.c b/libavformat/rtpproto.c
index dd5bc71c0e..269b1b2726 100644
--- a/libavformat/rtpproto.c
+++ b/libavformat/rtpproto.c
@@ -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);
}
diff --git a/libavformat/rtsp.c b/libavformat/rtsp.c
index bc8cd67c81..62311cbb23 100644
--- a/libavformat/rtsp.c
+++ b/libavformat/rtsp.c
@@ -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);
}
diff --git a/libavformat/rtspdec.c b/libavformat/rtspdec.c
index e484347896..e79f873e1b 100644
--- a/libavformat/rtspdec.c
+++ b/libavformat/rtspdec.c
@@ -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;
diff --git a/libavformat/sapenc.c b/libavformat/sapenc.c
index 91c1f628c7..bd3483e296 100644
--- a/libavformat/sapenc.c
+++ b/libavformat/sapenc.c
@@ -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;
}
diff --git a/libavformat/tcp.c b/libavformat/tcp.c
index 29eb60abe9..b01f0b85bf 100644
--- a/libavformat/tcp.c
+++ b/libavformat/tcp.c
@@ -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)
diff --git a/libavformat/udp.c b/libavformat/udp.c
index 6c1b37b59d..0196573209 100644
--- a/libavformat/udp.c
+++ b/libavformat/udp.c
@@ -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;