Safe I/O

Programming Topics (Computer Chess) and technical aspects as test techniques, book building, program tuning etc

Moderator: Andres Valverde

Safe I/O

Postby Fabien Letouzey » 10 Dec 2004, 14:06

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.
Fabien Letouzey
 
Posts: 110
Joined: 03 Dec 2004, 10:17
Location: France

Re: Safe I/O

Postby Joachim Rang » 10 Dec 2004, 22:55

Hi Volker,

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

regards Joachim
Joachim Rang
 
Posts: 69
Joined: 26 Sep 2004, 22:00

Re: Safe I/O

Postby Volker Pittlik » 10 Dec 2004, 23:00

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
User avatar
Volker Pittlik
 
Posts: 1031
Joined: 24 Sep 2004, 10:14
Location: Murten / Morat, Switzerland

Re: Safe I/O

Postby Niyaz Khasanov » 11 Dec 2004, 08:49

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);
Niyaz Khasanov
 
Posts: 22
Joined: 28 Sep 2004, 11:54

Re: Safe I/O

Postby Anonymous » 12 Dec 2004, 23:15

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
Anonymous
 

Re: Safe I/O

Postby Fabien Letouzey » 13 Dec 2004, 10:48

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.
Fabien Letouzey
 
Posts: 110
Joined: 03 Dec 2004, 10:17
Location: France

Re: Safe I/O

Postby Volker Pittlik » 13 Dec 2004, 10:53

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
User avatar
Volker Pittlik
 
Posts: 1031
Joined: 24 Sep 2004, 10:14
Location: Murten / Morat, Switzerland


Return to Programming and Technical Discussions

Who is online

Users browsing this forum: No registered users and 5 guests