Christophe Weblog Wiki Code Publications Music
log and fix bug #20: infinite errors on disconnect.
[swankr.git] / swank.R
diff --git a/swank.R b/swank.R
index dea28cf99f2f72cec6ccadc13d1266b88b571c78..20311847afef86a62468a50c58b0f1962cc7dc9b 100644 (file)
--- a/swank.R
+++ b/swank.R
@@ -33,9 +33,10 @@ acceptConnections <- function(port, portFile) {
     cat(port, file=f)
     close(f)
   }
+  ## FIXME: maybe we should support dontClose here?
   s <- socketConnection(host="localhost", server=TRUE, port=port, open="r+b")
   on.exit(close(s))
-  serve(s)
+  tryCatch(serve(s), endOfFile=function(c) NULL)
 }
 
 serve <- function(io) {
@@ -145,6 +146,11 @@ readPacket <- function(io) {
 
 readChunk <- function(io, len) {
   buffer <- readChar(io, len)
+  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")
   }