Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The new API improves upon the old API in a number of ways: * The old API provided a single data pipe for input and output, and it provided the pipe in the form of a HANDLE opened with FILE_FLAG_OVERLAPPED. Using a bare HANDLE is difficult in higher-level languages, and overlapped/asynchronous I/O is hard to get right. winpty_close closed the data pipe, which also didn't help things, though I think the handle could have been duplicated. Using a single handle for input and output complicates shutdown. When the child process exits, the agent scrapes the final output, then closes the data pipe once its written. It's possible that a winpty client will first detect the closed pipe when it's writing *input* rather than reading output, which seems wrong. (On the other hand, the agent doesn't implement "backpressure" for either input or output (yet), and if it did, it's possible that post-exit shutdown should interrupt a blocked write into the console input queue. I need to think about it more.) The new API splits the data pipe into CONIN and CONOUT pipes, which are accessed by filename. After `winpty_open` returns, the client queries pipe names using `winpty_conin_name` and `winpty_conout_name`, then opens them using any mechanism, low-level or high-level, blocking or overlapped. * The old libwinpty handled errors by killing the process. The new libwinpty uses C++ exceptions internally and translates exceptions at API boundaries using: - a boolean error result (e.g. BOOL, NULL-vs-non-NULL) - a potentially heap-allocated winpty_error_t object returned via an optional winpty_error_ptr_t parameter. That parameter can be NULL. If it isn't, then an error code and message can be queried from the error object. The winpty_error_t object must be freed with winpty_error_free. * winpty_start_process is renamed to winpty_spawn. winpty_open and winpty_spawn accept a "config" object which holds parameters. New configuration options can be added without disturbing the source or binary API. * The winpty_get_exit_code and winpty_get_process_id APIs are removed. The winpty_spawn function has an out parameter providing the child's process and thread HANDLEs (duplicated from the agent via DuplicateHandle). The winpty client can call GetExitCodeProcess and GetProcessId (as well as the WaitForXXX APIs to wait for child exit).
- Loading branch information