Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: About WinBoard IO things

Author: Robert Hyatt

Date: 14:53:02 11/04/02

Go up one level in this thread


On November 04, 2002 at 17:19:30, Severi Salminen wrote:

>I try to get the WinBoard interface working without disabling input buffering.
>Disabling the buffer by setbuf(stdin, NULL) causes problems with WB. But I have
>also a problem _without_ disabling the buffer:
>
>These are send to engine:
>
>7360 >first : time 5794
>otim 5935
>7360 >first : usermove 7360 >first : g1f3
>
>PeekNamedPipe reports 34 bytes in pipe. After 1st fget() I get only the first
>command (time 5694) but after that PeekNamedPipe tells that 0 bytes available in
>pipe. When doing a fget() after this I can, however, read the next command. So,
>the question: how can I fetch these commands so that PeekNamedPipe doesn't get
>confused -> after first fget(), PeeknamedPipe should give 24 bytes available,
>not 0. fget clearly is not the right function, but others seem to behave
>identically.
>
>Severi

If you don't disable buffering, it simply won't work correctly.  You need to be
able to
ask the question "is there any unread input that I need to process?"  You can
only do this
at the system level, checking on system buffers.  Unfortunately, when you do a
buffered
I/O read, the C library reads in _everything_ in the system buffer, and gives
the first piece
of it to you.  If you ask "is there more input" the answer is "no" because the
system buffer
is empty.  you get way out of sync with things.  If you do another read, you
will get the
next piece of data, but if there is none, you block, which you don't want to do.

You have two choices:

(1) disable buffering or else use unbuffered I/O (read/write).  I do the latter
and it works
perfectly;

(2) use a separate I/O thread so that blocking waiting on input is perfectly OK,
since the
engine thread can continue to execute as it should....




This page took 0 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.