[FFmpeg-devel] [PATCH] Use ff_neterrno instead of errno in tcp.c

Martin Storsjö martin
Tue Jul 14 15:25:45 CEST 2009


On Tue, 14 Jul 2009, M?ns Rullg?rd wrote:

> Martin Storsj? <martin at martin.st> writes:
> 
> > They're not fully compatible. The winsock headers define the official 
> > winsock error codes, which are in the range 10000->, e.g. WSAEINTR = 
> > 10004. Errno.h defines the normal ones in the range 1->, e.g. EINTR = 4.
> >
> > So for a caller checking the return value against AVERROR(E*), it won't 
> > match the expected values - callers on windows that want to check for 
> > different errors would need to check AVERROR(WSAE*) additionally.
> >
> > But as M?ns points out, this doesn't make things any worse at least, and 
> > doesn't affect other OSes. (Earlier it probably would have returned 0, 
> > since errno didn't know about the socket errors.)
> >
> > Would it be better to define some inverse of FF_NETERROR, that maps the 
> > values back to the expected range? E.g.
> >
> > #define FF_NET_UNERROR(x) ((x) - WSABASEERR)
> >
> > And then return AVERROR(FF_NET_UNERROR(ff_neterrno()))?
> 
> Simpler, just have ff_neterrno() return a sanitised code directly.

That's an option, too, yes. Then FF_NETERROR() could be changed to simply 
pass the original error code through.

> > But mapping them this way obfuscates the case when the error is a 
> > winsock-specific error code, where the original value would be more 
> > helpful than some mangled value mapping to nothing at all.
> 
> Are there such codes?

Yes, there's a bunch of winsock-specific errors, at least listed in the 
headers:

/* WinSock2 specific error codes */
#define WSAENOMORE      (WSABASEERR+102)
#define WSAECANCELLED   (WSABASEERR+103)
#define WSAEINVALIDPROCTABLE    (WSABASEERR+104)
#define WSAEINVALIDPROVIDER     (WSABASEERR+105)
#define WSAEPROVIDERFAILEDINIT  (WSABASEERR+106)
#define WSASYSCALLFAILURE       (WSABASEERR+107)
#define WSASERVICE_NOT_FOUND    (WSABASEERR+108)
#define WSATYPE_NOT_FOUND       (WSABASEERR+109)

And so on...

On the other hand, I don't really know if these actually can occur while 
just using the normal BSD sockets API.

Also, not all error codes map one to one to the normal errno codes. 
Instead of EAGAIN (11), WSAEWOULDBLOCK (base + 35) is returned, and 
there's no corresponding E*-code for 35 in the mingw errno.h at least. 
Currently this is solved by the following macros:

#define FF_NETERROR(err) WSA##err
#define WSAEAGAIN WSAEWOULDBLOCK


An even more sophisticated solution would be to check the error codes in 
ff_neterrno, map known ones back into their old values and leave the rest 
unmodified. But that feels like overkill...

Has someone more knowledgeable on winsock got anything to add?

// Martin



More information about the ffmpeg-devel mailing list