Bug 5295 - socket errno codes broken in modern Windows environments
Summary: socket errno codes broken in modern Windows environments
Status: CLOSED FIXED
Alias: None
Product: ThinLinc
Classification: Unclassified
Component: Other (show other bugs)
Version: pre-1.0
Hardware: PC Unknown
: P2 Normal
Target Milestone: 4.4.0
Assignee: Peter Åstrand
URL:
Keywords: ossman_tester, prosaic
Depends on:
Blocks: 5287
  Show dependency treegraph
 
Reported: 2014-10-14 09:29 CEST by Pierre Ossman
Modified: 2015-06-01 16:30 CEST (History)
1 user (show)

See Also:
Acceptance Criteria:


Attachments

Description Pierre Ossman cendio 2014-10-14 09:29:28 CEST
Microsoft, in their infinite wisdom, decided to strike a major blow against portability in Visual Studio 2010 and onward. Previously BSD socket errno:s were left undefined and you could do things like:

#define ECONNREFUSED WSAECONNREFUSED

They've now decided to define all the BSD socket errors, but with incompatible numbers. So at best you'll now get a tonne of warnings about redefining constants, and at worst you'll get bad error handling because you're looking for the wrong value.

Mingw-w64 has copied this behaviour, which means that this most definitely affects us sooner or later.

References:

http://msdn.microsoft.com/en-us/library/ms737828%28VS.85%29.aspx
https://connect.microsoft.com/VisualStudio/feedback/details/509380/errno-h-socket-return-codes-now-inconsistent-with-wsagetlasterror
http://sourceforge.net/p/mingw-w64/mingw-w64/ci/892eb7bde78572a4d6cd48705a21ab6ffeb5639d/
http://bugs.python.org/issue10469
http://sourceforge.net/p/tcl/patches/617/
http://www.mail-archive.com/curl-library@cool.haxx.se/msg05164.html

We need to go over our components and make sure this doesn't break things.
Comment 1 Peter Åstrand cendio 2015-01-19 15:00:33 CET
We have three choices wrt which error codes to use on Windows:

1) Continue to use the WSA codes, ie ECONNREFUSED=10061. 

2) Try to use POSIX codes as much as possible, ie ECONNREFUSED=111. However, those will never be reported by functions such as WSAGetLastError(), and not recognized by FormatMessage. 

3) Try to use the new Microsoft definitions from errno.h, ie ECONNREFUSED=107. However, as far as I can tell, these are totally bogus and not valid neither in POSIX nor in the Windows API. 

The general consensus seems to be that the best solution is to stick with the old approach of using the WSA constants (solution 1) by undef-ing the new broken constants from Microsoft:

Python: http://bugs.python.org/issue10469
Curl: http://www.mail-archive.com/curl-library@cool.haxx.se/msg05381.html
reSIProcate: https://svn.resiprocate.org/rep/resiprocate/main/rutil/Socket.hxx
Comment 2 Peter Åstrand cendio 2015-01-21 11:01:16 CET
Fixed in 29822.
Comment 3 Peter Åstrand cendio 2015-01-21 15:55:49 CET
More in 29827.
Comment 4 Peter Åstrand cendio 2015-02-05 10:50:37 CET
We have decided to go for a more complete solution, with a new header file "winerrno.h" included in every project.
Comment 5 Peter Åstrand cendio 2015-02-05 10:54:23 CET
(In reply to comment #4)
> We have decided to go for a more complete solution, with a new header file
> "winerrno.h" included in every project.

tlclient fixed in 29918.
Comment 6 Peter Åstrand cendio 2015-02-05 10:55:48 CET
(In reply to comment #4)
> We have decided to go for a more complete solution, with a new header file
> "winerrno.h" included in every project.

OpenSSH fixed in 29920.
Comment 7 Peter Åstrand cendio 2015-02-05 13:10:22 CET
(In reply to comment #4)
> We have decided to go for a more complete solution, with a new header file
> "winerrno.h" included in every project.

pcsctun fixed in r29932. 

tlclient tweaked in r29931. 

PulseAudio fixed in r29930. 

sercd fixed in r29929. 

unfs3 fixed in r29926. 

TigerVNC fixed in r29923.
Comment 8 Pierre Ossman cendio 2015-04-24 15:03:27 CEST
The list of codes seems to be correct and complete. I also cannot find any old manual conversions in any code.

It would be nice to confirm that it is included everywhere needed, but I'm not sure how to achieve that. This is going to have be good enough. Closing.
Comment 9 Pierre Ossman cendio 2015-05-29 15:40:20 CEST
It also redefines not-socket error codes, like EINVAL, which breaks standard C APIs. Pulseaudio refuses to start because of this.
Comment 10 Pierre Ossman cendio 2015-05-29 16:58:38 CEST
(In reply to comment #9)
> It also redefines not-socket error codes, like EINVAL, which breaks standard C
> APIs. Pulseaudio refuses to start because of this.

Updated in 30343 and r30344.

Committed upstream for TigerVNC, and reported upstream for PulseAudio:

https://bugs.freedesktop.org/show_bug.cgi?id=90773

sercd and unfs3 are not fixed upstream.
Comment 11 Pierre Ossman cendio 2015-06-01 16:30:18 CEST
Will test this on bug 2344.

Note You need to log in before you can comment on or make changes to this bug.