Re: ComStock 1.0.2 Stockfish with robobases
Posted: Tue Jan 11, 2011 9:54 am
OK, now I'm just confused as to why Fruit 2.1 doesn't have this problem. When I use fgets in the "getme.cpp" function, it says that input_available() is false.
Independent Computer Chess Discussion Forum
https://open-chess.org/
Code: Select all
void util_init() {
setvbuf(stdin,NULL,_IONBF,0);
setvbuf(stdout,NULL,_IONBF,0); // _IOLBF breaks on Windows!
}
You have done a lot of tests but still I have not understood if you have tried adding my above suggested code to data_available() .....BB+ wrote:I think I have a better grasp of the problem.
No I did not, as it was Windows only, no? At least it is in Fruit, and I don't see how to reference "stdin->_cnt" in Linux in any event.You have done a lot of tests but still I have not understood if you have tried adding my above suggested code to data_available()...
Code: Select all
void util_init() {
setvbuf(stdin,NULL,_IONBF,0);
setvbuf(stdout,NULL,_IONBF,0); // _IOLBF breaks on Windows!
}
Code: Select all
void InitInput()
{
out("init input...\n");
is_pipe = !isatty (0);
if (is_pipe)
{
signal(SIGINT, SIG_IGN);
}
setbuf(stdout, NULL);
setbuf(stdin, NULL);
}
Code: Select all
cout.rdbuf()->pubsetbuf(NULL, 0);
cin.rdbuf()->pubsetbuf(NULL, 0);
Code: Select all
#ifdef FRUIT // as in Fruit/GreKo
setvbuf(stdin,NULL,_IONBF,0);
setvbuf(stdout,NULL,_IONBF,0); // _IOLBF breaks on Windows!
cout << "Using setvbuf [Fruit]" << endl;
#else // as in Stockfish
cout.rdbuf()->pubsetbuf(NULL, 0);
cin.rdbuf()->pubsetbuf(NULL, 0);
cout << "Using cin.rdbuf()->pubsetbuf [Stockfish]" << endl;
#endif
Code: Select all
$ sh make.sh
Using setvbuf [Fruit]
Read input: go infinite
input_available() is 1
Read input: stop
Using cin.rdbuf()->pubsetbuf [Stockfish]
Read input: go infinite
input_available() is 0
Read input: stop
27.6.2.2.2 Buffer management and positioning [streambuf.buffer]
basic_streambuf<char_type,traits>* pubsetbuf(char_type* s, streamsize n);
Returns: setbuf(s, n).
So it might be that "pubsetbuf" is simply doing nothing, or at least it seems to be "implementation-defined", whereas setvbuf seems to be at least well-defined as to the behaviour. However, I could be wrong about something here.27.6.2.4.2 Buffer management and positioning [streambuf.virt.buffer]
basic_streambuf* setbuf(char_type* s, streamsize n);
Effects: Influences stream buffering in a way that is defined separately for each class derived from basic_streambuf in this Clause (27.8.1.4, 27.9.1.5).
Default behavior: Does nothing. Returns this.
In any event, as select is from a C library in any event, it makes more sense to me to use setvbuf rather than the C++ solution.27.9.1.5.12 basic_streambuf* setbuf(char_type* s, streamsize n);
Effects: If setbuf(0,0) is called on a stream before any I/O has occurred on that stream, the stream becomes unbuffered. Otherwise the results are implementation-defined. “Unbuffered” means that pbase() and pptr() always return null and output to the file should appear as soon as possible.
Thanks ! Patch applied.BB+ wrote:I figured out why my Fruit simulator failed, as I did not do:Adding the same to "getme.cpp" (and thus to Stockfish, I presume) solves the problem.Code: Select all
void util_init() { setvbuf(stdin,NULL,_IONBF,0); setvbuf(stdout,NULL,_IONBF,0); // _IOLBF breaks on Windows! }