From mckay at gmr.com  Fri Mar 14 14:28:59 2003
From: mckay at gmr.com (mckay@gmr.com)
Date: Fri Mar 14 14:29:15 2003
Subject: [Rd] Bug in read.socket (PR#2639)
Message-ID: <200303141329.h2EDSxn9010453@pubhealth.ku.dk>

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.)


[Rd] Bug in read.socket (PR#2639)
mckay@gmr.com