Finally Make Server STDIN Code Not Suck As Much

This commit is contained in:
TheBrokenRail 2021-11-20 23:09:25 -05:00
parent d17416421a
commit 7ad36d0ce1

View File

@ -9,6 +9,7 @@
#include <fstream>
#include <vector>
#include <sys/ioctl.h>
#include <pthread.h>
#include <unistd.h>
@ -231,6 +232,11 @@ static void *read_stdin_thread(__attribute__((unused)) void *data) {
if (isatty(fileno(stdin))) {
// Loop
while (1) {
int bytes_available;
if (ioctl(fileno(stdin), FIONREAD, &bytes_available) == -1) {
bytes_available = 0;
}
for (int i = 0; i < bytes_available; i++) {
if (!stdin_buffer_complete) {
// Read Data
int x = fgetc(stdin);
@ -247,6 +253,7 @@ static void *read_stdin_thread(__attribute__((unused)) void *data) {
}
}
}
}
return NULL;
}
__attribute__((destructor)) static void _free_stdin_buffer() {