Giter Club home page Giter Club logo

Comments (6)

alexrp avatar alexrp commented on August 22, 2024

Setting a flag and writing some garbage with ioctl(TIOCSTI) could potentially be an option. The equivalent on Windows should simply be WriteConsole on the input handle (probably, maybe). Or WriteConsoleInput.

from cathode.

alexrp avatar alexrp commented on August 22, 2024

Setting a flag and writing some garbage with ioctl(TIOCSTI) could potentially be an option.

Then again, setting a flag and sending a signal should work just as well and seems less hacky. No such mechanism on Windows, though. Would also require knowing the thread ID of the reading thread.

from cathode.

alexrp avatar alexrp commented on August 22, 2024

Here's an approach I think is workable and way less hacky.

TerminalReader.Read (and APIs that use it) should be changed to accept an optional CancellationToken.

We will create a pipe on startup. Instead of trying to read immediately, we will poll on the input FD and pipe read FD. When poll returns, we check if the pipe had data written. If yes, we drain it and throw an OperationCanceledException (leaving any potential data in the input FD unread). If no, proceed to read input as normal.

The TerminalReader will hook into the cancellation token with UnsafeRegister. The callback will simply write a byte to the pipe write FD to indicate that cancellation is requested.

This scheme should in principle work the same on Windows - just replace pipe with CreatePipe, poll with WaitForMultipleObjects, read with ReadConsole/ReadFile, etc.

from cathode.

alexrp avatar alexrp commented on August 22, 2024

Bad news: WaitForMultipleObjects doesn't work on pipes. So the Unix approach won't translate neatly to Windows.

from cathode.

alexrp avatar alexrp commented on August 22, 2024

Mostly done in fe53706 (with a kinda gross but functional workaround for Windows).

Still need to see if cancellation can somehow be plumbed through for ReadLine in addition to ReadRaw.

from cathode.

alexrp avatar alexrp commented on August 22, 2024

Still need to see if cancellation can somehow be plumbed through for ReadLine in addition to ReadRaw.

It will probably be possible in .NET 7; see:

Closing this.

from cathode.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.