changeset 2056:eeea52739ff3 libavformat

use ff_neterrno() and FF_NETERROR() for networking error handling
author alex
date Fri, 27 Apr 2007 00:35:54 +0000
parents 3d553a42427a
children 857fbfeb2fa0
files network.h rtpproto.c tcp.c udp.c
diffstat 4 files changed, 19 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/network.h	Thu Apr 26 23:44:56 2007 +0000
+++ b/network.h	Fri Apr 27 00:35:54 2007 +0000
@@ -29,6 +29,9 @@
 #endif
 #include <netdb.h>
 
+#define ff_neterrno() errno
+#define FF_NETERROR(err) err
+
 #if !defined(HAVE_INET_ATON)
 /* in os_support.c */
 int inet_aton (const char * str, struct in_addr * add);
--- a/rtpproto.c	Thu Apr 26 23:44:56 2007 +0000
+++ b/rtpproto.c	Fri Apr 27 00:35:54 2007 +0000
@@ -178,7 +178,8 @@
         len = recvfrom (s->rtp_fd, buf, size, 0,
                         (struct sockaddr *)&from, &from_len);
         if (len < 0) {
-            if (errno == EAGAIN || errno == EINTR)
+            if (ff_neterrno() == FF_NETERROR(EAGAIN) ||
+                ff_neterrno() == FF_NETERROR(EINTR))
                 continue;
             return AVERROR_IO;
         }
@@ -201,7 +202,8 @@
                 len = recvfrom (s->rtcp_fd, buf, size, 0,
                                 (struct sockaddr *)&from, &from_len);
                 if (len < 0) {
-                    if (errno == EAGAIN || errno == EINTR)
+                    if (ff_neterrno() == FF_NETERROR(EAGAIN) ||
+                        ff_neterrno() == FF_NETERROR(EINTR))
                         continue;
                     return AVERROR_IO;
                 }
@@ -213,7 +215,8 @@
                 len = recvfrom (s->rtp_fd, buf, size, 0,
                                 (struct sockaddr *)&from, &from_len);
                 if (len < 0) {
-                    if (errno == EAGAIN || errno == EINTR)
+                    if (ff_neterrno() == FF_NETERROR(EAGAIN) ||
+                        ff_neterrno() == FF_NETERROR(EINTR))
                         continue;
                     return AVERROR_IO;
                 }
--- a/tcp.c	Thu Apr 26 23:44:56 2007 +0000
+++ b/tcp.c	Fri Apr 27 00:35:54 2007 +0000
@@ -68,9 +68,9 @@
     ret = connect(fd, (struct sockaddr *)&dest_addr,
                   sizeof(dest_addr));
     if (ret < 0) {
-        if (errno == EINTR)
+        if (ff_neterrno() == FF_NETERROR(EINTR))
             goto redo;
-        if (errno != EINPROGRESS)
+        if (ff_neterrno() != FF_NETERROR(EINPROGRESS))
             goto fail;
 
         /* wait until we are connected or until abort */
@@ -126,7 +126,8 @@
         if (ret > 0 && FD_ISSET(s->fd, &rfds)) {
             len = recv(s->fd, buf, size, 0);
             if (len < 0) {
-                if (errno != EINTR && errno != EAGAIN)
+                if (ff_neterrno() != FF_NETERROR(EINTR) &&
+                    ff_neterrno() != FF_NETERROR(EAGAIN))
                     return AVERROR(errno);
             } else return len;
         } else if (ret < 0) {
@@ -155,7 +156,8 @@
         if (ret > 0 && FD_ISSET(s->fd, &wfds)) {
             len = send(s->fd, buf, size, 0);
             if (len < 0) {
-                if (errno != EINTR && errno != EAGAIN)
+                if (ff_neterrno() != FF_NETERROR(EINTR) &&
+                    ff_neterrno() != FF_NETERROR(EAGAIN))
                     return AVERROR(errno);
                 continue;
             }
--- a/udp.c	Thu Apr 26 23:44:56 2007 +0000
+++ b/udp.c	Fri Apr 27 00:35:54 2007 +0000
@@ -428,7 +428,8 @@
         len = recvfrom (s->udp_fd, buf, size, 0,
                         (struct sockaddr *)&from, &from_len);
         if (len < 0) {
-            if (errno != EAGAIN && errno != EINTR)
+            if (ff_neterrno() != FF_NETERROR(EAGAIN) &&
+                ff_neterrno() != FF_NETERROR(EINTR))
                 return AVERROR_IO;
         } else {
             break;
@@ -451,7 +452,8 @@
                       s->dest_addr_len);
 #endif
         if (ret < 0) {
-            if (errno != EINTR && errno != EAGAIN)
+            if (ff_neterrno() != FF_NETERROR(EINTR) &&
+                ff_neterrno() != FF_NETERROR(EAGAIN))
                 return AVERROR_IO;
         } else {
             break;