Skip to content

Commit

Permalink
Use the correct cvt for converting socket errors on Windows.
Browse files Browse the repository at this point in the history
`WSADuplicateSocketW` returns 0 on success, which differs from
handle-oriented functions which return 0 on error. Use `sys::net::cvt`
to handle its return value, which handles the socket convention of
returning 0 on success, rather than `sys::cvt`, which handles the
handle-oriented convention of returning 0 on failure.
  • Loading branch information
sunfishcode committed Jan 12, 2022
1 parent 53e072f commit 83aebf8
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion library/std/src/os/windows/io/socket.rs
Expand Up @@ -8,6 +8,7 @@ use crate::io;
use crate::marker::PhantomData;
use crate::mem;
use crate::mem::forget;
use crate::sys;
use crate::sys::c;
use crate::sys::cvt;

Expand Down Expand Up @@ -80,7 +81,7 @@ impl OwnedSocket {
let result = unsafe {
c::WSADuplicateSocketW(self.as_raw_socket(), c::GetCurrentProcessId(), &mut info)
};
cvt(result)?;
sys::net::cvt(result)?;
let socket = unsafe {
c::WSASocketW(
info.iAddressFamily,
Expand Down

0 comments on commit 83aebf8

Please sign in to comment.