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