Message ID | 20240516093403.3763258-4-ffmpeg-devel@pileofstuff.org |
---|---|
State | New |
Headers | show |
Series | avformat/network: improve ff_neterrno() | expand |
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 |
Le 16 mai 2024 12:33:36 GMT+03:00, Andrew Sayers <ffmpeg-devel@pileofstuff.org> a écrit : >For example, WSAStartup()'s documentation says: > > "A call to the WSAGetLastError function is not needed and should not be used" >--- > libavformat/network.c | 5 ++++- > libavformat/network.h | 12 ++++++++++++ > 2 files changed, 16 insertions(+), 1 deletion(-) > >diff --git a/libavformat/network.c b/libavformat/network.c >index 5d0d05c5f1..351dc34bb6 100644 >--- a/libavformat/network.c >+++ b/libavformat/network.c >@@ -123,7 +123,10 @@ void ff_network_close(void) > #if HAVE_WINSOCK2_H > int ff_neterror(void) > { >- int err = WSAGetLastError(); >+ return ff_neterror2(WSAGetLastError()); >+} >+int ff_neterror2(int err) Err, please. Keep this to the Windows back-end. Nothing good is going to happen with a function that does nothing (on other platforms) and has a nondescript numbered name. >+{ > switch (err) { > case WSAEWOULDBLOCK: > return AVERROR(EAGAIN); >diff --git a/libavformat/network.h b/libavformat/network.h >index f338694212..7c8f81a050 100644 >--- a/libavformat/network.h >+++ b/libavformat/network.h >@@ -63,6 +63,12 @@ > * @note Error is based on WSAGetLastError() (Windows) or `errno` (otherwise) > */ > int ff_neterror(void); >+/* >+ * @brief ff_neterror()-style AVERROR >+ * @param err error code (usually an errno or Windows Sockets Error Code) >+ * @note Windows Sockets Error Codes are only supported in Windows >+ */ >+int ff_neterror2(int err); > #else > #include <sys/types.h> > #include <sys/socket.h> >@@ -76,6 +82,12 @@ int ff_neterror(void); > * @note Error is based on WSAGetLastError() (Windows) or `errno` (otherwise) > */ > #define ff_neterror() AVERROR(errno) >+/* >+ * @brief ff_neterror()-style AVERROR >+ * @param err error code (usually an errno or Windows Sockets Error Code) >+ * @note Windows Sockets Error Codes are only supported in Windows >+ */ >+#define ff_neterror2(ERRNO) AVERROR(ERRNO) > #endif /* HAVE_WINSOCK2_H */ > > #if HAVE_ARPA_INET_H
On Thu, May 16, 2024 at 12:59:05PM +0100, Andrew Sayers wrote: > On Thu, May 16, 2024 at 01:42:23PM +0300, Rémi Denis-Courmont wrote: > > Err, please. Keep this to the Windows back-end. Nothing good is going to happen with a function that does nothing (on other platforms) and has a nondescript numbered name. > > I have no strong opinion either way, and it feels rather bikesheddable. > Here's a version with the offending part moved to its own patch - > I'm happy for whoever applies this to decide whether they want to > keep or chuck patch 4/6 :) Ping?
diff --git a/libavformat/network.c b/libavformat/network.c index 5d0d05c5f1..351dc34bb6 100644 --- a/libavformat/network.c +++ b/libavformat/network.c @@ -123,7 +123,10 @@ void ff_network_close(void) #if HAVE_WINSOCK2_H int ff_neterror(void) { - int err = WSAGetLastError(); + return ff_neterror2(WSAGetLastError()); +} +int ff_neterror2(int err) +{ switch (err) { case WSAEWOULDBLOCK: return AVERROR(EAGAIN); diff --git a/libavformat/network.h b/libavformat/network.h index f338694212..7c8f81a050 100644 --- a/libavformat/network.h +++ b/libavformat/network.h @@ -63,6 +63,12 @@ * @note Error is based on WSAGetLastError() (Windows) or `errno` (otherwise) */ int ff_neterror(void); +/* + * @brief ff_neterror()-style AVERROR + * @param err error code (usually an errno or Windows Sockets Error Code) + * @note Windows Sockets Error Codes are only supported in Windows + */ +int ff_neterror2(int err); #else #include <sys/types.h> #include <sys/socket.h> @@ -76,6 +82,12 @@ int ff_neterror(void); * @note Error is based on WSAGetLastError() (Windows) or `errno` (otherwise) */ #define ff_neterror() AVERROR(errno) +/* + * @brief ff_neterror()-style AVERROR + * @param err error code (usually an errno or Windows Sockets Error Code) + * @note Windows Sockets Error Codes are only supported in Windows + */ +#define ff_neterror2(ERRNO) AVERROR(ERRNO) #endif /* HAVE_WINSOCK2_H */ #if HAVE_ARPA_INET_H