[FFmpeg-devel] [PATCH] avio: Check for FF_NETERROR(EAGAIN) in retry_transfer_wrapper

Måns Rullgård mans
Tue Feb 22 14:24:18 CET 2011


Martin Storsj? <martin at martin.st> writes:

> On Tue, 22 Feb 2011, Ronald S. Bultje wrote:
>
>> On Tue, Feb 22, 2011 at 3:15 AM, Martin Storsj? <martin at martin.st> wrote:
>> > On Mon, 21 Feb 2011, Nicolas George wrote:
>> >
>> >> Le tridi 3 vent?se, an CCXIX, Ronald S. Bultje a ?crit?:
>> >> > Can we map them to self-defined error codes on Windows? Made-up
>> >> > values, is what I mean.
>> >>
>> >> What about using the same values as currently, on a case-by-case basis:
>> >>
>> >> #ifndef ECONNREFUSED
>> >> #define ECONNREFUSED WSAECONNREFUSED
>> >> #endif
>> >>
>> >> ?
>> >
>> > That might be a good idea, but I'm not totally convinced. Do we want this
>> > in libavutil/error.h, or internally within lavf somewhere?
>> 
>> Internally, for now at least, definitely. I realize that error
>> reporting will be an issue to calling applications, but we'll have to
>> live with that. Let's be honest, half of our functions return simply
>> -1 anyway.
>
> Ok, new patch attached that achieves this, getting rid of FF_NETERRNO() 
> completely.
>
> // Martin
>
> From b2eeab27cb5093da3b88c0ab52f644b91fecaa14 Mon Sep 17 00:00:00 2001
> From: =?UTF-8?q?Martin=20Storsj=C3=B6?= <martin at martin.st>
> Date: Sat, 19 Feb 2011 19:14:11 +0100
> Subject: [PATCH] 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.
> ---
>  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(-)

Looks sane to me.

> diff --git a/libavformat/network.h b/libavformat/network.h
> index d6aee93..c575975 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
> +static inline int ff_neterrno() {
> +    int err = WSAGetLastError();
> +    switch (err) {
> +    case WSAEWOULDBLOCK:
> +        return AVERROR(EAGAIN);
> +    case WSAEINTR:
> +        return AVERROR(EINTR);
> +    }
> +    return -err;
> +}
> +
> +#define EPROTONOSUPPORT WSAEPROTONOSUPPORT
> +#define ETIMEDOUT WSAETIMEDOUT
> +#define ECONNREFUSED WSAECONNREFUSED
> +#define EINPROGRESS WSAEINPROGRESS

Are we certain these are never defined on Windows, or should they have
some ifdefs?  Also, a little vertical alignment wouldn't hurt.

-- 
M?ns Rullg?rd
mans at mansr.com



More information about the ffmpeg-devel mailing list