Skip to content

Commit

Permalink
Post to the readyness fd for EOF
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dankamongmen committed Jan 5, 2022
1 parent 15122f3 commit b459af7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/lib/in.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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);
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/poc/cli1.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit b459af7

Please sign in to comment.