Skip to content

Commit

Permalink
Fix protocol if "all" is not enabled.
Browse files Browse the repository at this point in the history
  • Loading branch information
Berrysoft authored and Thomasdezeeuw committed Sep 11, 2023
1 parent 39050f6 commit 109fb6a
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/sys/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ use windows_sys::Win32::Foundation::{SetHandleInformation, HANDLE, HANDLE_FLAG_I
use windows_sys::Win32::Networking::WinSock::{
self, tcp_keepalive, FIONBIO, IN6_ADDR, IN6_ADDR_0, INVALID_SOCKET, IN_ADDR, IN_ADDR_0,
POLLERR, POLLHUP, POLLRDNORM, POLLWRNORM, SD_BOTH, SD_RECEIVE, SD_SEND, SIO_KEEPALIVE_VALS,
SOCKET_ERROR, SO_PROTOCOL_INFOW, WSABUF, WSAEMSGSIZE, WSAESHUTDOWN, WSAPOLLFD,
WSAPROTOCOL_INFOW, WSA_FLAG_NO_HANDLE_INHERIT, WSA_FLAG_OVERLAPPED,
SOCKET_ERROR, WSABUF, WSAEMSGSIZE, WSAESHUTDOWN, WSAPOLLFD, WSAPROTOCOL_INFOW,
WSA_FLAG_NO_HANDLE_INHERIT, WSA_FLAG_OVERLAPPED,
};
use windows_sys::Win32::System::Threading::INFINITE;

use crate::{MsgHdr, Protocol, RecvFlags, SockAddr, TcpKeepalive, Type};
use crate::{MsgHdr, RecvFlags, SockAddr, TcpKeepalive, Type};

#[allow(non_camel_case_types)]
pub(crate) type c_int = std::os::raw::c_int;
Expand Down Expand Up @@ -924,13 +924,15 @@ impl crate::Socket {
/// Returns the [`Protocol`] of this socket by checking the `SO_PROTOCOL_INFOW`
/// option on this socket.
#[cfg(feature = "all")]
pub fn protocol(&self) -> io::Result<Option<Protocol>> {
pub fn protocol(&self) -> io::Result<Option<crate::Protocol>> {
use windows_sys::Win32::Networking::WinSock::SO_PROTOCOL_INFOW;

let info = unsafe {
getsockopt::<WSAPROTOCOL_INFOW>(self.as_raw(), SOL_SOCKET, SO_PROTOCOL_INFOW)?
};
match info.iProtocol {
0 => Ok(None),
p => Ok(Some(Protocol::from(p))),
p => Ok(Some(crate::Protocol::from(p))),
}
}
}
Expand Down

0 comments on commit 109fb6a

Please sign in to comment.