0

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)

Community
  • 1
  • 1
Iburidu
  • 450
  • 2
  • 5
  • 15
  • Uhhhm what?? What ever would you expect to happen asynchronously in the code sample you gave?? Do you have some serious misunderstandings? You might be interested looking into e.g. [`fork()`](http://pubs.opengroup.org/onlinepubs/009695399/functions/fork.html) and [`pipe()`](http://man7.org/linux/man-pages/man7/pipe.7.html) documentation. – πάντα ῥεῖ May 26 '14 at 21:26
  • I don't know how pipes work. I just want to handle the gameserver's output line by line. This code is async until about 1000 bytes as the quote told, then the Main thread locks itself. I need a non-blocking pipe or something that works like it is desired. As I know, fork() does not work on Windows. I tried CreateProcess, but it was not successful for me as well. – Iburidu May 26 '14 at 21:35
  • Try some POSIX compatible API for windows like [MinGW](http://www.mingw.org/) to get `fork()`/`pipe()` working; or even higher level abstractions as provided with [boost::asio](http://www.boost.org/doc/libs/1_55_0/doc/html/boost_asio.html). Just using the standard input/output handles with your program doesn't help out for your problem. Certainly `Sleep(1000);` doesn't cure anything (you don't have asynch IO there actually!). – πάντα ῥεῖ May 26 '14 at 21:46
  • Sleep(1000); wants to represent how slow the mod could be after I create that later :) – Iburidu May 26 '14 at 22:02
  • _'Sleep(1000); wants to represent ...'_ bad choice probably :P ... – πάντα ῥεῖ May 26 '14 at 22:10

0 Answers0