[Rd] Bug in read.socket (PR#2639)
mckay at gmr.com
mckay at gmr.com
Fri Mar 14 14:28:59 MET 2003
Full_Name: Neil McKay
Version: 1.6.1
OS: Linux (Redhat 7.1)
Submission from: (NULL) (129.124.42.210)
Specifying loop=true in a call to read.socket results in lost characters. To
see
the bug, set up an R server as follows:
sock <- make.socket(port=5432, server=TRUE);
while(TRUE) {
c<-read.socket(sock, maxlen=1, loop=TRUE);
cat(c, "\n", sep="", collapse="");
}
In another invocation of R, write this client:
sock<-make.socket("localhost", 5432);
write.socket(sock, "abc---xyz3210AA<>");
close.socket(sock);
The "-", "0", and "<>" characters will be dropped by the server. The cause is in
the
R code for read.socket. The line
if (rval > 0 || !loop)
should be
if (nchar(rval) > 0 || !loop)
(This bug occurs on Windows also, so I suspect it's in all versions of R.)
More information about the R-devel
mailing list