Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > gnu.bash.bug > #15403

Re: Some questions about the use of readline()

From Chet Ramey <chet.ramey@case.edu>
Newsgroups gnu.bash.bug
Subject Re: Some questions about the use of readline()
Date 2019-09-22 14:45 -0400
Organization ITS, Case Western Reserve University
Message-ID <mailman.807.1569177936.2190.bug-bash@gnu.org> (permalink)
References <CACDGAZVP+7KthNJHBDHOaxfaZnXT2h70+1Yzm3zfNGQC9T47sA@mail.gmail.com> <4c861134-4b54-0c20-d1ba-f113b7638c65@case.edu>

Show all headers | View raw


On 9/21/19 11:23 AM, Aust zhu wrote:
> Hello!
>     I am having some problems with readline().  When calling the readline()
> function it is blocked. I want to set a timeout for the readline function
> to return.

You don't post any code, but I assume you're using a signal handler for
SIGALRM.

>     I tried setting rl_done=1, and fprintf(rl_instream,"\r\n");
> fflush(rl_instream); can't make the readline() function return. What should
> I do to make the readline() function return?

SIGALRM is one of the signals readline handles, so it will resume whatever
it was doing (presumably reading a character) if the calling application's
signal handler returns.

You can use rl_signal_event_hook or some other mechnanism to longjmp back
to readline's caller, once your signal handler notes that your application
received the SIGALRM. That's how bash implements read builtin timeouts in
the presence of `read -e'.

Chet

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
		 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    chet@case.edu    http://tiswww.cwru.edu/~chet/

Back to gnu.bash.bug | Previous | Next | Find similar | Unroll thread


Thread

Re: Some questions about the use of readline() Chet Ramey <chet.ramey@case.edu> - 2019-09-22 14:45 -0400

csiph-web