Skip to content

Commit

Permalink
Auto merge of #66835 - AviKozokin:master, r=alexcrichton
Browse files Browse the repository at this point in the history
std:win: avoid WSA_FLAG_NO_INHERIT flag and don't use SetHandleInformation on UWP

This flag is not supported on Windows 7 before SP1, and on windows server 2008 SP2. This breaks Socket creation & duplication.
This was fixed in a previous PR. cc #26658

This PR: cc #60260 reuses this flag to support UWP, and makes an attempt to handle the potential error.
This version still fails to create a socket, as the error returned by WSA on this case is WSAEINVAL (invalid argument). and not WSAEPROTOTYPE.

MSDN page for WSASocketW (that states the platform support for WSA_FLAG_NO_HANDLE_INHERIT): https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-wsasocketw

CC #26543
CC #26518
  • Loading branch information
bors committed Dec 6, 2019
2 parents 234c9f2 + fa8b549 commit 7b482cd
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/libstd/sys/windows/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ impl Socket {
c::WSA_FLAG_OVERLAPPED | c::WSA_FLAG_NO_HANDLE_INHERIT) {
c::INVALID_SOCKET => {
match c::WSAGetLastError() {
c::WSAEPROTOTYPE => {
c::WSAEPROTOTYPE | c::WSAEINVAL => {
match c::WSASocketW(fam, ty, 0, ptr::null_mut(), 0,
c::WSA_FLAG_OVERLAPPED) {
c::INVALID_SOCKET => Err(last_error()),
Expand Down Expand Up @@ -199,7 +199,7 @@ impl Socket {
c::WSA_FLAG_OVERLAPPED | c::WSA_FLAG_NO_HANDLE_INHERIT) {
c::INVALID_SOCKET => {
match c::WSAGetLastError() {
c::WSAEPROTOTYPE => {
c::WSAEPROTOTYPE | c::WSAEINVAL => {
match c::WSASocketW(info.iAddressFamily,
info.iSocketType,
info.iProtocol,
Expand Down

0 comments on commit 7b482cd

Please sign in to comment.