X-Git-Url: http://christophe.rhodes.io/gitweb/?p=swankr.git;a=blobdiff_plain;f=swank.R;fp=swank.R;h=901f1c16a5bc7f1af0015a73b7bd352c4adf36b3;hp=57ead0ac9f803a1d2729f737d739c0d4a10fcb69;hb=a1e8d6a615cbc31ffe84b17cc07943310917f8fd;hpb=fc149c9eb2e0c2d1645f8ab3bfcd52eaaf823dab diff --git a/swank.R b/swank.R index 57ead0a..901f1c1 100644 --- a/swank.R +++ b/swank.R @@ -141,19 +141,27 @@ readPacket <- function(io) { header <- readChunk(io, 6) len <- strtoi(header, base=16) payload <- readChunk(io, len) - readSexpFromString(payload) + sexp <- readSexpFromString(payload) + sexp } readChunk <- function(io, len) { - buffer <- readChar(io, len) + buffer <- readChar(io, len, useBytes=TRUE) if(length(buffer) == 0) { condition <- simpleCondition("End of file on io") class(condition) <- c("endOfFile", class(condition)) signalCondition(condition) } - if(nchar(buffer) != len) { - stop("short read in readChunk") - } + ## FIXME: with the useBytes argument to readChar, it is normal for + ## the buffer returned to be fewer character than bytes were read, + ## given the possibility of multibyte characters. However, that + ## means we can’t detect at all the case where there is actually a + ## short read (though empirically the readChar call blocks rather + ## than returning early). + ## + ## if(nchar(buffer) != len) { + ## stop("short read in readChunk") + ## } buffer }