Page 1 of 1

Safe I/O

PostPosted: 10 Dec 2004, 14:06
by Fabien Letouzey
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.

Thanks,

Fabien.

Re: Safe I/O

PostPosted: 10 Dec 2004, 22:55
by Joachim Rang
Hi Volker,

you could make this a sticky - at least for a while.

regards Joachim

Re: Safe I/O

PostPosted: 10 Dec 2004, 23:00
by Volker Pittlik
Joachim Rang wrote:Hi Volker,

you could make this a sticky - at least for a while.

regards Joachim


Well let's see if someone complains.

Volker

Re: Safe I/O

PostPosted: 11 Dec 2004, 08:49
by Niyaz Khasanov
What is the equivalent of EOF if I use PeekNamedPipe and ReadFile in Windows? The 00h symbol or another one?
What change need I do in the following code:

peeked_OK:= PeekNamedPipe(inh,nil,0,nil,addr(NumAvail),nil);
if (NumAvail>0) or not(peeked_OK) then
ReadFile(inh,BigBuffer,SizeOf(BigBuffer),NumGot,nil);

Re: Safe I/O

PostPosted: 12 Dec 2004, 23:15
by Anonymous
Niyaz, you must check the return value of ReadFile(). To check your code, start your engine under any GUI. Kill the GUI with task manager, then (at various times, for example under force mode/WB, respectively while just doing nothing/UCI. Also while calculating - ponder/analyse for example). Actually if not(peeked_OK) this will already mean, that the GUI was closed. But ReadFile will give an error later anyway.

Regards,
Dieter

Re: Safe I/O

PostPosted: 13 Dec 2004, 10:48
by Fabien Letouzey
Hi Volker,

I think this message is better repeated every two months or so, instead of left sticky all the time.

You can unglue it in a few days, regular users will have read it by then ...

Thanks,

Fabien.

Re: Safe I/O

PostPosted: 13 Dec 2004, 10:53
by Volker Pittlik
Fabien Letouzey wrote:Hi Volker,

...You can unglue it in a few days, regular users will have read it by then ...
...


OK, I'm going to do so on Wednesday. Feel free to post it again whenever you think it is necessary.

Volker