tty: fix permanently set EOF status on tty

This commit is contained in:
K. Lange 2022-03-22 14:09:32 +09:00
parent c13c241c3b
commit 6ceb9392cd
3 changed files with 12 additions and 2 deletions

View File

@ -16,6 +16,7 @@ typedef struct {
int internal_stop;
list_t * alert_waiters;
int discard;
int soft_stop;
} ring_buffer_t;
size_t ring_buffer_unread(ring_buffer_t * ring_buffer);
@ -29,4 +30,5 @@ void ring_buffer_destroy(ring_buffer_t * ring_buffer);
void ring_buffer_interrupt(ring_buffer_t * ring_buffer);
void ring_buffer_alert_waiters(ring_buffer_t * ring_buffer);
void ring_buffer_select_wait(ring_buffer_t * ring_buffer, void * process);
void ring_buffer_eof(ring_buffer_t * ring_buffer);

View File

@ -97,7 +97,8 @@ size_t ring_buffer_read(ring_buffer_t * ring_buffer, size_t size, uint8_t * buff
}
wakeup_queue(ring_buffer->wait_queue_writers);
if (collected == 0) {
if (ring_buffer->internal_stop) {
if (ring_buffer->internal_stop || ring_buffer->soft_stop) {
ring_buffer->soft_stop = 0;
spin_unlock(ring_buffer->lock);
return 0;
}
@ -164,6 +165,7 @@ ring_buffer_t * ring_buffer_create(size_t size) {
out->internal_stop = 0;
out->discard = 0;
out->soft_stop = 0;
out->wait_queue_readers = list_create("ringbuffer readers",out);
out->wait_queue_writers = list_create("ringbuffer writers",out);
@ -200,3 +202,9 @@ void ring_buffer_interrupt(ring_buffer_t * ring_buffer) {
wakeup_queue(ring_buffer->wait_queue_writers);
}
void ring_buffer_eof(ring_buffer_t * ring_buffer) {
ring_buffer->soft_stop = 1;
wakeup_queue(ring_buffer->wait_queue_readers);
wakeup_queue(ring_buffer->wait_queue_writers);
}

View File

@ -224,7 +224,7 @@ void tty_input_process(pty_t * pty, uint8_t c) {
if (pty->canon_buflen) {
dump_input_buffer(pty);
} else {
ring_buffer_interrupt(pty->in);
ring_buffer_eof(pty->in);
}
return;
}