Darren Cook wrote: > Hi, > I'm connecting to gnugo 3.6 using GTP: using pipes from C++. When > running my unit tests, they sometimes work fine, but sometimes they > fail. If it fails it seems to be on the first command I send after > successfully connecting. > > I was originally using lower-level file descriptors, but after having > lots of problems, I looked at gnugo's oracle.c code and switched to > using two FILE*. So my code is now basically the same as oracle.c > (except I use fwrite instead of fprintf). Does anyone have similar > problems with that code? > > My send_command() is shown below. > > I'm wondering if when fgets() returns NULL if it means Gnugo is still > processing? Should I just do a continue to have it try again? Perhaps > combined with sleeping for a millisecond or something. Or should fgets() > wait forever until the remote program sends a carriage-return?
No, fgets() is synchronous. If it returns NULL, then your pipe has passed out already. I cannot really read your code, but it seems correct. I can think of two possible problems: bad pipe setup or too small `readbuf'. If you send `list_commands', two kilobytes might be not enough... You may want to look at Quarry's (http://home.gna.org/quarry/) way of handling GTP. It can be used asynchronously and the main program does it that way. The simple test in `src/gtp/gtp-test.c' demonstrates setting up the pipes, connecting to an engine and printing basic info. The client code is in `src/gtp/gtp-client.c'. Paul _______________________________________________ gnugo-devel mailing list [email protected] http://lists.gnu.org/mailman/listinfo/gnugo-devel

