Giter VIP home page Giter VIP logo

Comments (8)

abitmore avatar abitmore commented on May 29, 2024 1

Thanks. Closing. BTW I've updated the sample code above to handle interruption during searching.

from editline.

troglobit avatar troglobit commented on May 29, 2024

We have the new alternate interface, for event loops, bc7fc7e, which may be of interest to you.

There is also the option of using a different rl_getc_function. Editline defaults to use the local rl_getc() fucntion which uses read(), which is wrapped in a do-while(EINTR)-loop to handle aborted syscalls due to signals. So if you like you could do another implementation of that and install a signal handler in the thread (to prevent the thread from dying), upon return from readline() the TTY will be restored by el_deprep().

Maybe GNU Readline has some other API or method for this, but at this point I haven't looked into that.

from editline.

abitmore avatar abitmore commented on May 29, 2024

Thanks. I'll take a look. I was trying to modify rl_getc() just now.

from editline.

troglobit avatar troglobit commented on May 29, 2024

I added a reference implementation for the alternate API in examples/excallback.c. Having everything in the same thread/process is sometimes the preferred way to go. In particular if you use libev or some other neat event loop instead of rolling your own (as the example does).

from editline.

abitmore avatar abitmore commented on May 29, 2024

If I'm correct, current implementation of rl_getc() ignores SIGINT directly, thus I need a new implementation anyway, even if I go for the alternate API approach. Created PR #29 for this.

The links you provided in #28 is useful for this discussion:

from editline.

troglobit avatar troglobit commented on May 29, 2024

You're almost correct. The rl_getc() implementation ignores any signal by checking for EINTR and restarting the syscall. This is common practice in UNIX.

from editline.

abitmore avatar abitmore commented on May 29, 2024

FWIW, my implementation of rl_getc() looks like:

static int interrupted = false;
static int interruptible_getc(void)
{
   int r;
   char c;

   if (interrupted)
      return EOF;

   r = read(0, &c, 1); // read from stdin, will return -1 when interrupted by a signal

   if (r == -1 && errno == EINTR)
      interrupted = true;

   return r == 1 ? c : EOF;
}

seems work for me.

EDIT: updated the code to make it work when got interrupted when searching

from editline.

troglobit avatar troglobit commented on May 29, 2024

Yup, that definitely looks like it should work for you. You may want to keep a list of which signals your application handles and add a check in interruptible_getc() to make sure you only return EOF when there is SIGINT and not another signal ...

... so maybe we can close this issue now?

from editline.

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.