What is broken pipe in xboard ?

Discussion of chess software programming and technical issues.

Moderator: Ras

Chan Rasjid
Posts: 588
Joined: Thu Mar 09, 2006 4:47 pm
Location: Singapore

What is broken pipe in xboard ?

Post by Chan Rasjid »

Hello,

I have just compiled TSCP for Fedora7 and can now play engine-engine match in a crude way, just edit command to :-
xboard -fcp /usr/bin/gnuchess
-scp /home/rasjid/tscp/tscp -tc 1:0 -mps 60
and everthings fine.

My own SnailChess can run without bugs in winboard Windows XP but fails as the second program in xboard fedora7. There is a message "fail to write to second program, broken pipe ...second program exited unexpectedly"

Can someone tell what is the likely problem.

Best Regards,
Rasjid
jswaff

Re: What is broken pipe in xboard ?

Post by jswaff »

Are you flushing stdout?
Chan Rasjid
Posts: 588
Joined: Thu Mar 09, 2006 4:47 pm
Location: Singapore

Re: What is broken pipe in xboard ?

Post by Chan Rasjid »


Are you flushing stdout?
Yes.

With winboard+Windows XP compiled with mingw, it plays just normal and never crash or hang.

I suspect it is still my code for linux gcc that has problems. It seems my program exited unexpectedly and thus xboard "fail to write to second chess program, broken pipe" ? may be because my program exited.

Rasjid
Guetti

Re: What is broken pipe in xboard ?

Post by Guetti »

Did you follow point 7. Signals in the engine-intf.html distributed with xboard?
It applies only to engines running under Unix.

I just do a:

Code: Select all

signal(SIGINT, SIG_IGN);
when I receive the xboard command.
Tony

Re: What is broken pipe in xboard ?

Post by Tony »

Chan Rasjid wrote:

Are you flushing stdout?
Yes.

With winboard+Windows XP compiled with mingw, it plays just normal and never crash or hang.

I suspect it is still my code for linux gcc that has problems. It seems my program exited unexpectedly and thus xboard "fail to write to second chess program, broken pipe" ? may be because my program exited.

Rasjid
Yes, it's a consequence of an error, not the error itself.

Tony
Chan Rasjid
Posts: 588
Joined: Thu Mar 09, 2006 4:47 pm
Location: Singapore

Re: What is broken pipe in xboard ?

Post by Chan Rasjid »

Yes, I have signal(SIGINT, SIG_IGN);

I have traced the line that gave problems. It is fgets() in the while loop.

In a game with
tscp - w
snail - b
1) tscp makes the 1st move and snail receives "go" and searches and returns a valid move acknowledged by xboard and "make" in the GUI.
2) tscp makes the 2nd move and xboard pipe it to snail through stdin. But fgets(line, 255, stdin) fails !

I don't know much about streams or fedora linux.

Code: Select all

int main(int argc, char *argv[]) {
setbuf(stdin, NULL);
setbuf(stdout, NULL);
signal(SIGTERM, SIG_IGN);
printf("\n");
...
}

while (1) {
fflush(stdout);

if (side == computerSide) {
int r = callSearch(board, ss, searchinfo, incheck, side, followPV);
if (r != RESULT_NULL) {
gameResult(r, side, *ss->pv);
computerSide = NullSide;
continue;
}
side ^= 1;
continue;
}

ftime(&searchinfo->timeb_start);

printf("telluser fgets \n");
if (!fgets(line, 256, stdin)) {
return;
}
printf("telluser fgets ok\n");

if (line[0] == '\n'){
continue;
}

sscanf(line,"%s",command);

if (!strcmp(command, "xboard")) {
printf("\n");
continue;
}
.....
}/* while loop*/
Rasjid
Aleks Peshkov
Posts: 892
Joined: Sun Nov 19, 2006 9:16 pm
Location: Russia

Re: What is broken pipe in xboard ?

Post by Aleks Peshkov »

On success, the function returns the same str parameter.
If the End-of-File is encountered and no characters have been read, the contents of str remain unchanged and a null pointer is returned.
If an error occurs, a null pointer is returned.
Use either ferror or feof to check whether an error happened or the End-of-File was reached.
jswaff

Re: What is broken pipe in xboard ?

Post by jswaff »

Chan Rasjid wrote:

Are you flushing stdout?
Yes.

With winboard+Windows XP compiled with mingw, it plays just normal and never crash or hang.

I suspect it is still my code for linux gcc that has problems. It seems my program exited unexpectedly and thus xboard "fail to write to second chess program, broken pipe" ? may be because my program exited.

Rasjid
Yeah, unfortunately I've seen that error all to many times. It's invariably because my program crashed (to the surprise of XBoard).
Chan Rasjid
Posts: 588
Joined: Thu Mar 09, 2006 4:47 pm
Location: Singapore

Re: What is broken pipe in xboard ?

Post by Chan Rasjid »

I do follow closely as what tscp did but my think() to get a move is fairly elaborate. Don't know why fgets() fails after return from the first think().

Code: Select all

printf("telluser fgets A\n");

if (!fgets(line, 256, stdin)) {
printf("telluser fgets B\n");
return;
}

printf("telluser fgets C\n"); 
The problem is control only reaches A and prints "fgets A" and does not print "fgets B". Just have to sit back a while.

Rasjid
User avatar
Zach Wegner
Posts: 1922
Joined: Thu Mar 09, 2006 12:51 am
Location: Earth

Re: What is broken pipe in xboard ?

Post by Zach Wegner »

Are you sure you have SIGINT ignored too? The code you posted only has SIGTERM. You should have both. The error isn't necessarily caused by fgets, because your program will be blocking, waiting for input inside the function, where it could be interrupted.