Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error UDP socket #26518

Closed
dev-priporov opened this issue Jun 23, 2015 · 6 comments
Closed

error UDP socket #26518

dev-priporov opened this issue Jun 23, 2015 · 6 comments

Comments

@dev-priporov
Copy link

I have that code:

fn main() {
    let socket = UdpSocket::bind("127.0.0.1:23451").ok().expect("fail bind");
    let mut buf = [0; 2];
    buf[0]=11;
    buf[1]=22;
    socket.send_to(&buf, "127.0.0.1:23451").ok().expect("fail send");
    println!("{:?}", buf);
}

and I start it in 2 different PC with OS win7 32 , and have 2 different error:
1)thread '' panicked at 'called Result::unwrap() on an Err value: Error { repr: Os(10022) }',
C:/bot/slave/stable-dist-rustc-win-32/build/src/libcore\result.rs:729
2)thread '' panicked at 'fail bind', C:/bot/slave/stable-dist-rustc-win-32/b
uild/src/libcore\option.rs:330
This errors com in after first string:

let socket = UdpSocket::bind("127.0.0.1:23451").ok().expect("fail bind");
@nagisa
Copy link
Member

nagisa commented Jun 23, 2015

@dev-priporov could you run your program with RUST_BACKTRACE environment variable set to 1?

10022 error code in Windows means invalid argument; I can’t tell you what’s the reason for 2nd variant, but at least it is not the standard library using unwrap somewhere incorrectly.

@dev-priporov
Copy link
Author

#[test]
fn foo(){
    let socket = UdpSocket::bind("127.0.0.1:5001").ok().expect("fail bind");;//.expect("fail bind");

}

$cargo test

result:

Compiling main v0.1.0 (file:///D:/Documents/Rust/udp/main)
Running target\debug\main-9041d3d24bce4adb.exe

running 1 test
test foo ... FAILED

failures:

---- foo stdout ----
thread 'foo' panicked at 'called Result::unwrap() on an Err value: Error { repr: Os(10022) }', C:/bot/slave/stable-dist-rustc-win-32/build/src/libcore\result.rs:729
failures:
foo
test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured

@dev-priporov
Copy link
Author

start main.exe with RUST_BACKTRACE=1

$D:\Documents\Rust\udp>main.exe
thread '

' panicked at 'fail bind', C:/bot/slave/stable-dist-rustc-win-32/b
uild/src/libcore\option.rs:330
stack backtrace:
1: 0x447e9f - main
2: 0x40a9bc - main
3: 0x40b3df - main
4: 0x447900 - main
5: 0x4623f8 - main
6: 0x40492f
7: 0x404560
8: 0x44aa7c - main
9: 0x406827 - main
10: 0x4013de
11: 0x77071174 - BaseThreadInitThunk
12: 0x7737b3f5 - RtlInitializeExceptionChain

@dev-priporov
Copy link
Author

up

@sfackler
Copy link
Member

sfackler commented Jul 1, 2015

Do you have SP1 installed? If not, it's most likely #26658.

@steveklabnik
Copy link
Member

Triage: it's been a long time, and with no response about SP1, I'm going to give this a close.

@dev-priporov if you're still seeing this today, please let me know and we can re-open.

bors added a commit that referenced this issue Dec 6, 2019
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants