Why I need it is due to this really long FEN on a 19x19 board which could be as long as 400 bytes.
All other engine-gui commands are really short which is probably why this problem went unnoticed.
Moderator: Ras
Could it be because of the size of the PIPE buffer (GUI)?Daniel Shawul wrote:Hope you will finish the job with the ReadFile(). I have surrendered already
Why I need it is due to this really long FEN on a 19x19 board which could be as long as 400 bytes.
All other engine-gui commands are really short which is probably why this problem went unnoticed.
No, please refer to my non-chess, non-GUI, non-PIPE example in my previous post.Karlo Bala wrote:Could it be because of the size of the PIPE buffer (GUI)?Daniel Shawul wrote:Hope you will finish the job with the ReadFile(). I have surrendered already
Why I need it is due to this really long FEN on a 19x19 board which could be as long as 400 bytes.
All other engine-gui commands are really short which is probably why this problem went unnoticed.
The simple answer is to use read()/write(). There is no limit to the number of bytes you can read, within reason, with a single read. I can't imagine why you would not just go to the basic I/O level and use read(). That is the method of input in Crafty for all things that are read, and it works just fine, whether it be reading from a file, across the network, or from the keyboard.Daniel Shawul wrote:Hope you will finish the job with the ReadFile(). I have surrendered already
Why I need it is due to this really long FEN on a 19x19 board which could be as long as 400 bytes.
All other engine-gui commands are really short which is probably why this problem went unnoticed.
read() is the correct way to deal with this. It eliminates one level of indirection, because everything else from scanf, to gets, to whatever all use read() internally...Daniel Shawul wrote:Yep. So far only crafty & tscp passed the test. Tscp doesn't do polling though.
A second way to fix the problem might be to ask your I/O library not to buffer on input. It should then be safe to poll the underlying file descriptor as described above. With C, you can try calling setbuf(stdin, NULL). However, I have never tried this. Also, there could be problems if you use scanf(), at least with certain patterns, because scanf() sometimes needs to read one extra character and "push it back" into the buffer; hence, there is a one-character pushback buffer even if you asked for stdio to be unbuffered. With C++, you can try cin.rdbuf()->setbuf(NULL, 0), but again, I have never tried this.
There are two levels of I/O. System-level and library-level. You are using library-level I/O which leaves it up to the library developers as to what kind of internal buffer sizes they use. You disabled internal buffering. Yet the data has to be read somewhere.Daniel Shawul wrote:That is one of the four methods recommended in the winboard communication protocol. The question is why one of the methods there does not work as intended on some operating system. It also seems many engines have this problem too. A "better" option which avoids hassle with unbuffered streams is to use a separate thread for input/ouput processing. I will use one of the working methods eventually but do you know why the current method doesn't work.A second way to fix the problem might be to ask your I/O library not to buffer on input. It should then be safe to poll the underlying file descriptor as described above. With C, you can try calling setbuf(stdin, NULL). However, I have never tried this. Also, there could be problems if you use scanf(), at least with certain patterns, because scanf() sometimes needs to read one extra character and "push it back" into the buffer; hence, there is a one-character pushback buffer even if you asked for stdio to be unbuffered. With C++, you can try cin.rdbuf()->setbuf(NULL, 0), but again, I have never tried this.
I could solve the problem in three other ways too but I/we wanted to know why fgets() doesn't work.. is that hard to understand? I used read() in the past too but replaced it with fgets() since the former required removal of the extra new line character at the end. Thanks for the rest of your post though, which seems to explain the cause of this problem.My read() code works on every system I have tried, from windows, to all the unix variants, VMS, etc. Why keep fooling around and dodging the problem? If you use read(), all this will work flawlessly and you can move on to other issues...
If it doesn't work, why does it matter why? Move on to something that does, and always has. This is called "beating your head against a brick wall". It is not a very effective way of developing code.Daniel Shawul wrote:I could solve the problem in three other ways too but I/we wanted to know why fgets() doesn't work.. is that hard to understand? I used read() in the past too but replaced it with fgets() since the former required removal of the extra new line character at the end. Thanks for the rest of your post though, which seems to explain the cause of this problem.My read() code works on every system I have tried, from windows, to all the unix variants, VMS, etc. Why keep fooling around and dodging the problem? If you use read(), all this will work flawlessly and you can move on to other issues...
If it doesn't work, why does it matter why? Move on to something that does, and always has. This is called "beating your head against a brick wall". It is not a very effective way of developing code.
This is not enough for winboard gui.*strchr(buffer, '\n') = NULL;
will do the trick. If you are not sure a n/l character is present,
if ((p = strchr(buffer, '\n')) *p = NULL;
can not replace a simple fgets() yet. So you see the inconviniece has already grown...
read(fileno(stdin),buffer,MAX_STR);
if ((p = strchr(buffer, '\n')) *p = NULL;