[FFmpeg-cvslog] libavformat: Remove FF_NETERRNO()
Martin Storsjö
git
Wed Feb 23 19:04:39 CET 2011
ffmpeg | branch: master | Martin Storsj? <martin at martin.st> | Sat Feb 19 19:14:11 2011 +0100| [c24a40349693e50aa81ef68a4a522503ca504d50] | committer: Michael Niedermayer
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 at gmail.com>
(cherry picked from commit 28c4741a6617a4c1d2490cb13fc70ae4c9c472da)
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=c24a40349693e50aa81ef68a4a522503ca504d50
---
ffserver.c | 32 ++++++++++++++++----------------
libavformat/network.h | 19 +++++++++++++++----
libavformat/rtpproto.c | 14 +++++++-------
libavformat/rtsp.c | 4 ++--
libavformat/rtspdec.c | 2 +-
libavformat/sapenc.c | 2 +-
libavformat/tcp.c | 8 ++++----
libavformat/udp.c | 10 +++++-----
8 files changed, 51 insertions(+), 40 deletions(-)
diff --git a/ffserver.c b/ffserver.c
index 7bda968..abc7cd9 100644
--- a/ffserver.c
+++ b/ffserver.c
@@ -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)
diff --git a/libavformat/network.h b/libavformat/network.h
index d6aee93..58a8e80 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 dd5bc71..269b1b2 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 bc8cd67..62311cb 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 e484347..e79f873 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 91c1f62..bd3483e 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 29eb60a..b01f0b8 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 6c1b37b..0196573 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;
More information about the ffmpeg-cvslog
mailing list