That remote daemon simply forks a process, dup2's the socket on top of stdin and stdout, and then uses execve() to execute the indicated program. The Daemon is then "out of the loop" as the new process communicates directly to the remote machine (running xboard) over the socket connection. It can use recv()/send() if it chooses, since it is definitely talking over a socket.Sven Schüle wrote:We have some different cases to consider.bob wrote:[...][...]Code: Select all
xboard -smpCores 8 -defaultHashSize 800 -xexit -popupExitMessage false -icshelper /usr/bin/timestamp -geometry +0+0 -ics -zp -zippyMaxGames 2 -zippyReplayTimeout 3600 -autoflag -icshost 207.99.83.228 -fcp "ssh 138.26.64.202 ./runc" -size petite -xreuse -xanimate
How hard is that?
1) Remote engine "disguised" as local engine towards xboard
Your case is without -firstHost option but with -fcp "ssh HOST PROGRAM". (I use the upper case words HOST and PROGRAM like variables from here on, not to be mixed up with some "shouting" style of communication.).
The following happens (I assume you know this already but there are also other readers):
- xboard forks a local child process running the "ssh" command line, and creates two pipes to talk to that "ssh" process, as usual with a local engine. xboard does not know what "ssh" actually does.
- "ssh" connects to the remote HOST using a socket connection. (I omit all the user login/authentication/encryption/... stuff here which is not important for our context.) The local "ssh" process has an own, local socket. There is also a counterpart for it, the remote socket on the HOST which is already there when the ssh daemon is starting up.
- The HOST has a service running ("ssh daemon") that listens to that remote socket, usually on port 22. On an incoming connection the ssh daemon forks a new process, PROGRAM. The ssh daemon manages for PROGRAM to read from standard input the data that are received via the remote socket, and to send back via that socket the data that are written to stdout by PROGRAM. (I omit stderr here for simplicity, it also works in a similar way.) This is achieved with something like pipes.
- PROGRAM can use low-level read/write as well as "higher-level" fgets/getline/printf/fputs/... I/O functions. There should be no restriction to use only read/write for a remotely running engine since stdin/stdout (resp. standard file descriptors 0/1) are always the same.
- The mechanism described above realizes the simulation of a normal stdin/stdout connection between the local client (xboard/WinBoard) and the remote PROGRAM running on the HOST. The existence of a socket connection over the network is 100% transparent for both client and server programs.
- I am not sure whether it would even be possible to use send/recv in the remote PROGRAM (chess engine) since the described method involves to associate the remote socket with the stdin and stdout file descriptors (done by ssh daemon), so the PROGRAM must read from stdin and write to stdout to get the data from/to the communication partner, and cannot read from the socket directly. I have not tried it but my current understanding is NO.
2) "Real" remote engine started via "-firstHost"
Let me add first that I made a wrong statement when writing that xboard/WinBoard would not start the engine in case of using the -firstHost option. I did not look up the description carefully enough, did actually only refer to your statements (but misunderstood), and therefore initially thought it would just create a socket and connect to a remote socket which would have to be provided directly by the remote engine, not involving any RSH/SSH/... service, i.e. just TCP. That would indeed imply to care about starting of the engine separately, but my thought was wrong, sorry for that.
Here the essential mechanism is the same as above, the differences are in the details:
- Command line arguments are "-firstHost HOST" and "-fcp PROGRAM" (same convention as above).
- xboard/WinBoard uses the "rsh" mechanism to manage remote execution of PROGRAM on HOST. It creates a local socket and connects to the existing remote socket on HOST.
- There is again a daemon process running on the HOST, the "rsh daemon", which listens to the remote socket and forks a child process PROGRAM on an incoming connection. While the fine details may be different the basic mechanism is the same as in the "ssh" case above. "ssh" is preferred today over "rsh" for security reasons.
- Everything written above about stdin/stdout(/stderr) and sockets is also valid here. Therefore I believe that also "-firstHost" does not offer a way for a remotely running engine to access the remote socket via send/recv.
I have already discussed that issue. But it is resolvable, trivially. A change to xboard so that _all_ connections are via socket would work perfectly. For example, if _you_ use -fh localhost, you get a socket connection to a local process. Your program won't know anything is different, except that with the -fh option, it could use recv() (which I am not a proponent of) or it could use fgets() or any other normal input form. Without the -fh, you can use every input option except recv().
3) Local engine
This is the most relevant case for the majority of chess engine users:
- Command line options are "-fcp PROGRAM". The "-firstHost" option is not present, and PROGRAM is either a path on the local file system pointing to the local engine or a command line starting a local engine.
- xboard/WinBoard internally set HOST to "localhost" in this case, and do not create any socket connection. PROGRAM is forked as local child process of xboard/WinBoard, and pipes for read/write are created as usual.
- There is no chance for PROGRAM to use send/recv since there is no socket to use.
Again, your comments about remote engines is wrong. The remote engine is using a socket when it does _anything_ with stdin/stdout, since they have been replaced by the network socket descriptor...
Conclusion:
Same as before Explicitly using sockets via send/recv is not available for local engines, and to my knowledge also not available for remotely running engines, unless some extensions are offered by xboard/WinBoard (and other GUIs/tools as wells) in the future. The key point is, even if the "remote" case would turn out to be possible, it is not possible today for the "local" case covering >99% of the users.
Sven
The local/remote (pipe/socket) issue is _not_ a program issue. It is a GUI issue. If the GUI chooses, it can _always_ use a socket, in which case any valid I/O procedure is acceptable. If the GUI uses a pipe for local execution, then send()/recv() will not work. It's all up to the GUI. I would not mandate send/recv myself, I would mandate read/write which work for _ALL_ cases...