-
Notifications
You must be signed in to change notification settings - Fork 8.4k
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
Does CreatePseudoConsole accept Socket handle? #9332
Comments
Well, this is my API so I should know the answer here 😅 Unfortunately, I don't really know what makes @miniksa usually does know more about these sorts of things. Any ideas? |
Nothing in particular is checking the type of the You could.... replace your |
Winsock IFS sockets created with |
Welp, there we go then. It just takes doing #262 to be able to deal with an |
Thanks guys for the comments. You guys are awesome. Is it possible for me to workaround this by making the socket blocking? |
I haven't experimented with using sockets with conpty. But you can get a synchronous-mode socket by calling |
Thanks Eryk. You’re amazing! It works actually. Socket with conpty works as long as the socket has no overlapped attribute.
My next question would be is it possible to WSARecv on a file handle? For example, I need to pass the stdhandle into libevent. Inside libevent it will use WSA apis to manipulate the handle. I think it doesn't work as WSA api would complains about the file socket not being a valid socket. I wonder if there’s some kind of bridge that can connect file handle & socket handle.
获取 Outlook for iOS<https://aka.ms/o0ukef>
|
What do you mean, specifically? Are you saying that you're doing |
Short story: Winsock socket operations, such as Very long story: I'll outline the problem and the context, as far as I know, but this doesn't include any simple way to wrap a non-socket file for use with socket functions... A socket is a handle for a file object opened on the "Afd" device (created by the "Ancillary Function Driver"), which is associated with Winsock protocol and connection state. (The latter is the reason for A file object is created when a device object is opened. The driver for the device is sent an You're probably used to accessing files on a volume device (e.g. "C:\Windows\explorer.exe" might be "\Device\HarddiskVolume2\Windows\explorer.exe"). For a volume device that's mounted by a filesystem, the system uses the volume parameter block (VPB) of the device object to refer to the filesystem device that controls access to the volume and its namespace. The filesystem driver typically supports either opening the entire volume or a regular file or directory named by a path in the filesystem (e.g. "\Windows\explorer.exe"). The operations supported on the file object are entirely up to what's directly supported and allowed by the filesystem device. Any other device type usually manages its own namespace and operations. It can implement a filesystem or a fixed set of virtual files. For example, "\Device\NamedPipe\" (note the trailing backslash) is an NPFS (named-pipe filesystem) directory that contains named pipes, "\Device\Mup" (Multiple UNC Provider) mounts UNC shares in its namespace (with the remaining path managed by a filesystem redirector device, e.g. for SMB shares), and the console's "ConDrv" device supports virtual files such as "\Device\ConDrv\Input". The AFD driver implements an "Endpoint" virtual file to create an enpoint. Winsock calls The I/O manager provides a set of common I/O functions for file objects. For example, You probably see where this is going. The "receive" operation for a socket 0x12017 is a non-standard code. The standard format for a control code has the 16-bit device type in the upper word, the 2-bit required access left shifted by 14 bits, the 12-bit function code left shifted by 2 bits, and the buffering method in the lower 2 bits. When parsed normally, 0x12017 looks like a code for function 2053 on a beep-type device ( If a non-socket file handle is passed to a Winsock function such as |
Thanks @eryksun so much for such a detailed writeup! I have no word but to thank you for the effort. And I’ve learned a lot from it. Unfortunately this “file handle to socket handle” issue will be a huge blocker for tmux to work on Windows. I’ll close this issue now. I think people in the future will have the reference they need if they are tackling similar issues. |
@miniksa yeah basically I’m trying to do the impossible, to use the StdHandle as if it is on Linux and recv/select on it. |
I brought this up to Dustin yesterday. Feel like should also open a thread here.
Background
We know that on Linux file descriptor is a "universal" thing that can be used both for socket & file. However, on Windows file handle(
HANDLE
) & socket handle (SOCKET
) are two different things. Despite the fact that socket handle from a Winsock provider can be used with other non-Winsock functions, we can't do the other way around, that is passing a file handle into a function that accepts socket handle.I'm trying to port tmux on Windows which uses libevent a lot. Most of Libevent's APIs utilizes file descriptor, which make it suitable for both file & networking programming on Linux. In tmux, the IO of tty device (
/dev/tty
) is also managed by libevent using the same FD interface. Underneath the interface, libevent usesrecv
on Linux (again, works for both file & socket), and usesWSARecv
on Windows (which only works for SOCKET handle).ConPTY Interface
The
CreatePseudoConsole
interface is defined as this:HRESULT WINAPI CreatePseudoConsole( _In_ COORD size, _In_ HANDLE hInput, _In_ HANDLE hOutput, _In_ DWORD dwFlags, _Out_ HPCON* phPC );
The example in the documentation uses HANDLE created by
CreatePipe
. The documentation does not mention restriction about passing aSOCKET
handle.Question
So here's the problem. I can not use HANDLE created by
CreatePipe
because it won't work in libevent. I may be able to use SOCKET instead, which works in libevent. But I don't know if it works in ConPTY.I've tried to pass TCP/UDP sockets like this:
CreateProcess
does work. But the process exits immediately after creation (cmd.exe, powershell.exe).I've also tried this:
CreateProcess
still works, and the process survives. But I'm not seeing anything written into the socket.The text was updated successfully, but these errors were encountered: