mirror of
https://github.com/dankamongmen/notcurses.git
synced 2024-11-02 09:40:15 +00:00
[input] read large chunks at once #1903
This commit is contained in:
parent
cf8b640064
commit
8a3579581a
@ -369,9 +369,9 @@ block_on_input(int fd, const struct timespec* ts, const sigset_t* sigmask){
|
|||||||
return events;
|
return events;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static inline size_t
|
||||||
input_queue_full(const ncinputlayer* nc){
|
input_queue_space(const ncinputlayer* nc){
|
||||||
return nc->inputbuf_occupied == sizeof(nc->inputbuf) / sizeof(*nc->inputbuf);
|
return sizeof(nc->inputbuf) / sizeof(*nc->inputbuf) - nc->inputbuf_occupied;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char32_t
|
static char32_t
|
||||||
@ -391,19 +391,27 @@ handle_queued_input(ncinputlayer* nc, ncinput* ni, int leftmargin, int topmargin
|
|||||||
static char32_t
|
static char32_t
|
||||||
handle_input(ncinputlayer* nc, ncinput* ni, int leftmargin, int topmargin,
|
handle_input(ncinputlayer* nc, ncinput* ni, int leftmargin, int topmargin,
|
||||||
const sigset_t* sigmask){
|
const sigset_t* sigmask){
|
||||||
unsigned char c;
|
ssize_t r = 0;
|
||||||
while(!input_queue_full(nc) && read(nc->infd, &c, 1) > 0){
|
size_t rlen;
|
||||||
nc->inputbuf[nc->inputbuf_write_at] = c;
|
//fprintf(stderr, "OCCUPY: %u@%u read: %d %zd\n", nc->inputbuf_occupied, nc->inputbuf_write_at, nc->inputbuf[nc->inputbuf_write_at], r);
|
||||||
//fprintf(stderr, "OCCUPY: %u@%u read: %d\n", nc->inputbuf_occupied, nc->inputbuf_write_at, nc->inputbuf[nc->inputbuf_write_at]);
|
if((rlen = input_queue_space(nc)) > 0){
|
||||||
if(++nc->inputbuf_write_at == sizeof(nc->inputbuf) / sizeof(*nc->inputbuf)){
|
// if we have at least as much available as we do room to the end, read
|
||||||
|
// all the way to the end. otherwise, read as much as we have available.
|
||||||
|
if(rlen >= sizeof(nc->inputbuf) / sizeof(*nc->inputbuf) - nc->inputbuf_write_at){
|
||||||
|
rlen = sizeof(nc->inputbuf) / sizeof(*nc->inputbuf) - nc->inputbuf_write_at;
|
||||||
|
}
|
||||||
|
while((r = read(nc->infd, nc->inputbuf + nc->inputbuf_write_at, rlen)) > 0){
|
||||||
|
nc->inputbuf_write_at += r;
|
||||||
|
if(nc->inputbuf_write_at == sizeof(nc->inputbuf) / sizeof(*nc->inputbuf)){
|
||||||
nc->inputbuf_write_at = 0;
|
nc->inputbuf_write_at = 0;
|
||||||
}
|
}
|
||||||
++nc->inputbuf_occupied;
|
nc->inputbuf_occupied += r;
|
||||||
const struct timespec ts = {};
|
const struct timespec ts = {};
|
||||||
if(block_on_input(nc->infd, &ts, sigmask) < 1){
|
if(block_on_input(nc->infd, &ts, sigmask) < 1){
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// highest priority is resize notifications, since they don't queue
|
// highest priority is resize notifications, since they don't queue
|
||||||
if(resize_seen){
|
if(resize_seen){
|
||||||
resize_seen = 0;
|
resize_seen = 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user