First of all: I would like to read and handle the output of a game console with my external, so I will be able to write some new feature for the game server.
My problem is that, I redirected the output of the Source
to the Mod
via batch pipe this way:
.\Source.exe | Mod.exe
Mod.exe (for test now):
#include <iostream>
#include <windows.h>
int main() {
std::string line;
while(std::getline(std::cin, line, '\n')) {
std::cout << line << std::endl;
Sleep(1000);
^^^^^^^^^^^^
}
return 0;
}
and the pipe does not seem to be async.
I mean I am not able to connect to the server until the Mod
does not finish writing the lines from its STDIN. And if I connect to the server after waiting the Mod
flushing its content, I am able to make the server lagging with writing lot of things to chat (make the Source
console filled with data)
So the Source
stoppes, if the pipe has too much data unhandled by the Mod
I have found this about this here: Why does delayed expansion fail when inside a piped block of code?
Asynchronously is not the full truth
I said that the both threads are asynchronous, normally this is true. But in reality the left thread can lock itself when the piped data isn't consumed by the right thread. There seems to be a limit of ~1000 characters in the "pipe" buffer, then the thread is blocked until the data is consumed.
It is problem because the Mod
can have slowly executable content later, and it can make the Source
unavailable/lagged. (This is why I tested it delayed)
Is there any other way to make the Source
to not wait Mod
to get all contents? (I use C++ for the mod)