Safe I/O (repeated)
Posted: 11 Feb 2005, 10:03
Hi all,
This is a request to engine authors that I already made a few months ago.
---
When reading input please test for end-of-file, and let the engine quit if encountered. In other words, interpret EOF as "quit" (input has ended so no more commands will ever be received).
I know this is not supposed to happen since the interface should send "quit" first, but the interface (e.g. PolyGlot) can be killed by third-party software before doing so. Be assured that this does happen.
The most popular function for reading input is probably fgets(). Just test the return value for equality with NULL. If you want to go further you can use feof() or ferror() when receiving NULL. In any case it is safe to quit when receiving NULL.
---
Here's how you can test whether an engine is safe or not,
no need to be a programmer:
On Windows:
1) launch the engine in a console
2) press ^Z (control-Z)
3) validate with Return
On Unix (e.g. Linux, Mac OS X, etc ...):
1) launch the engine in a shell
2) press ^D
Engines should quit at this point. Error messages are fine.
Check with Crafty.
Buggy engines will display a new prompt, start using CPU time, or fill
the console (and log files) with output. Sadly many engines do this,
including commercial ones.
---
Thanks for listening,
Fabien.
This is a request to engine authors that I already made a few months ago.
---
When reading input please test for end-of-file, and let the engine quit if encountered. In other words, interpret EOF as "quit" (input has ended so no more commands will ever be received).
I know this is not supposed to happen since the interface should send "quit" first, but the interface (e.g. PolyGlot) can be killed by third-party software before doing so. Be assured that this does happen.
The most popular function for reading input is probably fgets(). Just test the return value for equality with NULL. If you want to go further you can use feof() or ferror() when receiving NULL. In any case it is safe to quit when receiving NULL.
---
Here's how you can test whether an engine is safe or not,
no need to be a programmer:
On Windows:
1) launch the engine in a console
2) press ^Z (control-Z)
3) validate with Return
On Unix (e.g. Linux, Mac OS X, etc ...):
1) launch the engine in a shell
2) press ^D
Engines should quit at this point. Error messages are fine.
Check with Crafty.
Buggy engines will display a new prompt, start using CPU time, or fill
the console (and log files) with output. Sadly many engines do this,
including commercial ones.
---
Thanks for listening,
Fabien.