diff --git a/kernel-src/include/kernel/tty.h b/kernel-src/include/kernel/tty.h index 61fe6062..e5449747 100644 --- a/kernel-src/include/kernel/tty.h +++ b/kernel-src/include/kernel/tty.h @@ -7,8 +7,8 @@ #include #include -#define DEVICE_BUFFER_SIZE 512 -#define READ_BUFFER_SIZE 4096 +#define TTY_DEVICE_BUFFER_SIZE 512 +#define TTY_READ_BUFFER_SIZE 4096 typedef size_t (*ttydevicewritefn_t)(void *internal, char *str, size_t size); typedef void (*ttyinactivefn_t)(void *internal); diff --git a/kernel-src/io/tty.c b/kernel-src/io/tty.c index 3c4a4438..b06b7e05 100644 --- a/kernel-src/io/tty.c +++ b/kernel-src/io/tty.c @@ -100,7 +100,7 @@ void tty_process(tty_t *tty, char c) { tty->writetodevice(tty->deviceinternal, "\b \b", 3); tty->devicepos = 0; - memset(tty->devicebuffer, 0, DEVICE_BUFFER_SIZE); + memset(tty->devicebuffer, 0, TTY_DEVICE_BUFFER_SIZE); return; } else if (c == tty->termios.c_cc[VEOF]) { // end of file TODO make read return 0 @@ -115,17 +115,18 @@ void tty_process(tty_t *tty, char c) { // check if buffer is full tty->devicebuffer[tty->devicepos++] = c; - if (tty->devicepos == DEVICE_BUFFER_SIZE) + if (tty->devicepos == TTY_DEVICE_BUFFER_SIZE) flush = true; if (flush) { MUTEX_ACQUIRE(&tty->readmutex, false); + ringbuffer_write(&tty->readbuffer, tty->devicebuffer, tty->devicepos); + + memset(tty->devicebuffer, 0, TTY_DEVICE_BUFFER_SIZE); + tty->devicepos = 0; - // XXX is this needed? - size_t datacount = RINGBUFFER_DATACOUNT(&tty->readbuffer); - if (datacount) - poll_event(&tty->pollheader, POLLIN); + poll_event(&tty->pollheader, POLLIN); MUTEX_RELEASE(&tty->readmutex); } @@ -453,11 +454,11 @@ tty_t *tty_create(char *name, ttydevicewritefn_t writefn, ttyinactivefn_t inacti if (tty->name == NULL) goto error; - tty->devicebuffer = alloc(DEVICE_BUFFER_SIZE); + tty->devicebuffer = alloc(TTY_DEVICE_BUFFER_SIZE); if (tty->devicebuffer == NULL) goto error; - if (ringbuffer_init(&tty->readbuffer, READ_BUFFER_SIZE)) + if (ringbuffer_init(&tty->readbuffer, TTY_READ_BUFFER_SIZE)) goto error; int minor = allocminor(tty);