mirror of
https://github.com/wez/wezterm.git
synced 2024-12-23 05:12:40 +03:00
filedescriptor: probe for pipes between wsl and win32
This is a port of something I found when developing some changes in watchman. When doing something like: `some win32 command | wsl something` That pipe doesn't look like a normal win32 pipe and we'd end up treating it like a socket, but it isn't really a socket either.
This commit is contained in:
parent
d39c16c406
commit
65cc7bb286
@ -19,9 +19,9 @@ use winapi::um::processthreadsapi::*;
|
||||
use winapi::um::winbase::{FILE_TYPE_CHAR, FILE_TYPE_DISK, FILE_TYPE_PIPE};
|
||||
use winapi::um::winnt::HANDLE;
|
||||
use winapi::um::winsock2::{
|
||||
accept, bind, closesocket, connect, getsockname, htonl, ioctlsocket, listen, recv, send,
|
||||
WSAPoll, WSASocketW, WSAStartup, INVALID_SOCKET, SOCKET, SOCK_STREAM, WSADATA,
|
||||
WSA_FLAG_NO_HANDLE_INHERIT,
|
||||
accept, bind, closesocket, connect, getsockname, getsockopt, htonl, ioctlsocket, listen, recv,
|
||||
send, WSAGetLastError, WSAPoll, WSASocketW, WSAStartup, INVALID_SOCKET, SOCKET, SOCK_STREAM,
|
||||
SOL_SOCKET, SO_ERROR, WSADATA, WSAENOTSOCK, WSA_FLAG_NO_HANDLE_INHERIT,
|
||||
};
|
||||
pub use winapi::um::winsock2::{POLLERR, POLLHUP, POLLIN, POLLOUT, WSAPOLLFD as pollfd};
|
||||
|
||||
@ -113,7 +113,24 @@ impl OwnedHandle {
|
||||
{
|
||||
HandleType::Pipe
|
||||
} else {
|
||||
HandleType::Socket
|
||||
// It's probably a socket, but it may be a special device used
|
||||
// when piping between WSL and native win32 apps.
|
||||
let mut err = 0;
|
||||
let mut errsize = std::mem::size_of_val(&err) as _;
|
||||
if unsafe {
|
||||
getsockopt(
|
||||
handle as _,
|
||||
SOL_SOCKET,
|
||||
SO_ERROR,
|
||||
&mut err as *mut _ as *mut i8,
|
||||
&mut errsize,
|
||||
) != 0
|
||||
&& WSAGetLastError() == WSAENOTSOCK
|
||||
} {
|
||||
HandleType::Pipe
|
||||
} else {
|
||||
HandleType::Socket
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => HandleType::Unknown,
|
||||
|
Loading…
Reference in New Issue
Block a user