diff mbox series

[FFmpeg-devel,v3,2/3] avformat/network: Return 0/AVERROR from ff_network_init()

Message ID 20240419190801.169291-2-ffmpeg-devel@pileofstuff.org
State New
Headers show
Series [FFmpeg-devel,v3,1/3] avformat/network: add ff_neterrno2() for cases where we already have an errno | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Andrew Sayers April 19, 2024, 7:08 p.m. UTC
---
 libavformat/avio.c    |  4 ++--
 libavformat/network.c |  7 +++----
 libavformat/rtsp.c    | 12 ++++++------
 libavformat/rtspdec.c |  4 ++--
 libavformat/sapdec.c  |  4 ++--
 libavformat/sapenc.c  |  4 ++--
 6 files changed, 17 insertions(+), 18 deletions(-)
diff mbox series

Patch

diff --git a/libavformat/avio.c b/libavformat/avio.c
index d109f3adff..f82edec779 100644
--- a/libavformat/avio.c
+++ b/libavformat/avio.c
@@ -123,8 +123,8 @@  static int url_alloc_for_protocol(URLContext **puc, const URLProtocol *up,
     int err;
 
 #if CONFIG_NETWORK
-    if (up->flags & URL_PROTOCOL_FLAG_NETWORK && !ff_network_init())
-        return AVERROR(EIO);
+    if (up->flags & URL_PROTOCOL_FLAG_NETWORK && (err=ff_network_init())<0)
+        return err;
 #endif
     if ((flags & AVIO_FLAG_READ) && !up->url_read) {
         av_log(NULL, AV_LOG_ERROR,
diff --git a/libavformat/network.c b/libavformat/network.c
index fb70f9cafc..134869a63f 100644
--- a/libavformat/network.c
+++ b/libavformat/network.c
@@ -59,11 +59,10 @@  int ff_network_init(void)
 {
 #if HAVE_WINSOCK2_H
     WSADATA wsaData;
-
-    if (WSAStartup(MAKEWORD(1,1), &wsaData))
-        return 0;
+    return ff_neterrno2(WSAStartup(MAKEWORD(1,1), &wsaData));
+#else
+    return 0;
 #endif
-    return 1;
 }
 
 int ff_network_wait_fd(int fd, int write)
diff --git a/libavformat/rtsp.c b/libavformat/rtsp.c
index b0c61ee00a..3db4ed11c2 100644
--- a/libavformat/rtsp.c
+++ b/libavformat/rtsp.c
@@ -1740,8 +1740,8 @@  int ff_rtsp_connect(AVFormatContext *s)
         return AVERROR(EINVAL);
     }
 
-    if (!ff_network_init())
-        return AVERROR(EIO);
+    if ((err = ff_network_init())<0)
+        return err;
 
     if (s->max_delay < 0) /* Not set by the caller */
         s->max_delay = s->iformat ? DEFAULT_REORDERING_DELAY : 0;
@@ -2395,8 +2395,8 @@  static int sdp_read_header(AVFormatContext *s)
     char url[MAX_URL_SIZE];
     AVBPrint bp;
 
-    if (!ff_network_init())
-        return AVERROR(EIO);
+    if ((err = ff_network_init())<0)
+        return err;
 
     if (s->max_delay < 0) /* Not set by the caller */
         s->max_delay = DEFAULT_REORDERING_DELAY;
@@ -2522,8 +2522,8 @@  static int rtp_read_header(AVFormatContext *s)
     AVBPrint sdp;
     AVDictionary *opts = NULL;
 
-    if (!ff_network_init())
-        return AVERROR(EIO);
+    if ((ret = ff_network_init())<0)
+        return ret;
 
     opts = map_to_opts(rt);
     ret = ffurl_open_whitelist(&in, s->url, AVIO_FLAG_READ,
diff --git a/libavformat/rtspdec.c b/libavformat/rtspdec.c
index 10078ce2fa..3b0829694e 100644
--- a/libavformat/rtspdec.c
+++ b/libavformat/rtspdec.c
@@ -663,8 +663,8 @@  static int rtsp_listen(AVFormatContext *s)
     int ret;
     enum RTSPMethod methodcode;
 
-    if (!ff_network_init())
-        return AVERROR(EIO);
+    if ((ret = ff_network_init())<0)
+        return ret;
 
     /* extract hostname and port */
     av_url_split(proto, sizeof(proto), auth, sizeof(auth), host, sizeof(host),
diff --git a/libavformat/sapdec.c b/libavformat/sapdec.c
index 357c0dd514..719c26c6b8 100644
--- a/libavformat/sapdec.c
+++ b/libavformat/sapdec.c
@@ -70,8 +70,8 @@  static int sap_read_header(AVFormatContext *s)
     int port;
     int ret, i;
 
-    if (!ff_network_init())
-        return AVERROR(EIO);
+    if ((ret = ff_network_init())<0)
+        return ret;
 
     av_url_split(NULL, 0, NULL, 0, host, sizeof(host), &port,
                  path, sizeof(path), s->url);
diff --git a/libavformat/sapenc.c b/libavformat/sapenc.c
index 87a834a8d8..3305122524 100644
--- a/libavformat/sapenc.c
+++ b/libavformat/sapenc.c
@@ -80,8 +80,8 @@  static int sap_write_header(AVFormatContext *s)
     int udp_fd;
     AVDictionaryEntry* title = av_dict_get(s->metadata, "title", NULL, 0);
 
-    if (!ff_network_init())
-        return AVERROR(EIO);
+    if ((ret = ff_network_init())<0)
+        return ret;
 
     /* extract hostname and port */
     av_url_split(NULL, 0, NULL, 0, host, sizeof(host), &base_port,