From b459af7fe576821ad8871fbdf93e897a253dcc9c Mon Sep 17 00:00:00 2001 From: nick black Date: Tue, 4 Jan 2022 23:44:11 -0500 Subject: [PATCH] Post to the readyness fd for EOF When we get to the EOF on stdin, we need account for that with the readiness fd. Post to it upon the EOF transition. Closes #2525. --- src/lib/in.c | 10 ++++++++++ src/poc/cli1.c | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/lib/in.c b/src/lib/in.c index 855c378ed..d9f925e27 100644 --- a/src/lib/in.c +++ b/src/lib/in.c @@ -476,6 +476,9 @@ mark_pipe_ready(ipipe pipes[static 2]){ } } +// shove the assembled input |tni| into the input queue (if there's room, +// and we're not draining, and we haven't hit EOF). send any synthesized +// signal as the last thing we do. static void load_ncinput(inputctx* ictx, const ncinput *tni, int synthsig){ inc_input_events(ictx); @@ -500,6 +503,8 @@ load_ncinput(inputctx* ictx, const ncinput *tni, int synthsig){ ictx->iwrite = 0; } ++ictx->ivalid; + // FIXME we don't always need to write here; write if ictx->ivalid was 0, and + // also write *from the client context* if we empty the input buffer there..? mark_pipe_ready(ictx->readypipes); pthread_mutex_unlock(&ictx->ilock); pthread_cond_broadcast(&ictx->icond); @@ -2290,8 +2295,13 @@ read_inputs_nblock(inputctx* ictx){ // now read bulk, possibly with term escapes intermingled within (if there // was not a distinct terminal source). if(rifd){ + unsigned eof = ictx->stdineof; read_input_nblock(ictx->stdinfd, ictx->ibuf, sizeof(ictx->ibuf), &ictx->ibufvalid, &ictx->stdineof); + if(!eof && ictx->stdineof){ + // we hit EOF; write an event to the readiness fd + mark_pipe_ready(ictx->readypipes); + } } } diff --git a/src/poc/cli1.c b/src/poc/cli1.c index 192e8db0c..87b1b06ae 100644 --- a/src/poc/cli1.c +++ b/src/poc/cli1.c @@ -32,7 +32,7 @@ int main(void){ #endif notcurses_get_blocking(nc, &ni); }while(ni.evtype == NCTYPE_RELEASE); - }while(ni.id != 'q'); + }while(ni.id != 'q' && ni.id != NCKEY_EOF); if(notcurses_render(nc)){ goto err; }