@@ -23,12 +23,12 @@ use windows_sys::Win32::Foundation::{SetHandleInformation, HANDLE, HANDLE_FLAG_I
23
23
use windows_sys:: Win32 :: Networking :: WinSock :: {
24
24
self , tcp_keepalive, FIONBIO , IN6_ADDR , IN6_ADDR_0 , INVALID_SOCKET , IN_ADDR , IN_ADDR_0 ,
25
25
POLLERR , POLLHUP , POLLRDNORM , POLLWRNORM , SD_BOTH , SD_RECEIVE , SD_SEND , SIO_KEEPALIVE_VALS ,
26
- SOCKET_ERROR , WSABUF , WSAEMSGSIZE , WSAESHUTDOWN , WSAPOLLFD , WSAPROTOCOL_INFOW ,
27
- WSA_FLAG_NO_HANDLE_INHERIT , WSA_FLAG_OVERLAPPED ,
26
+ SOCKET_ERROR , SO_PROTOCOL_INFOW , WSABUF , WSAEMSGSIZE , WSAESHUTDOWN , WSAPOLLFD ,
27
+ WSAPROTOCOL_INFOW , WSA_FLAG_NO_HANDLE_INHERIT , WSA_FLAG_OVERLAPPED ,
28
28
} ;
29
29
use windows_sys:: Win32 :: System :: Threading :: INFINITE ;
30
30
31
- use crate :: { MsgHdr , RecvFlags , SockAddr , TcpKeepalive , Type } ;
31
+ use crate :: { MsgHdr , Protocol , RecvFlags , SockAddr , TcpKeepalive , Type } ;
32
32
33
33
#[ allow( non_camel_case_types) ]
34
34
pub ( crate ) type c_int = std:: os:: raw:: c_int ;
@@ -920,6 +920,19 @@ impl crate::Socket {
920
920
Ok ( ( ) )
921
921
}
922
922
}
923
+
924
+ /// Returns the [`Protocol`] of this socket by checking the `SO_PROTOCOL_INFOW`
925
+ /// option on this socket.
926
+ #[ cfg( feature = "all" ) ]
927
+ pub fn protocol ( & self ) -> io:: Result < Option < Protocol > > {
928
+ let info = unsafe {
929
+ getsockopt :: < WSAPROTOCOL_INFOW > ( self . as_raw ( ) , SOL_SOCKET , SO_PROTOCOL_INFOW ) ?
930
+ } ;
931
+ match info. iProtocol {
932
+ 0 => Ok ( None ) ,
933
+ p => Ok ( Some ( Protocol :: from ( p) ) ) ,
934
+ }
935
+ }
923
936
}
924
937
925
938
#[ cfg_attr( docsrs, doc( cfg( windows) ) ) ]
0 commit comments