Christophe Weblog Wiki Code Publications Music
enough support for emacs/slim to start swank for itself
authorChristophe Rhodes <csr21@cantab.net>
Wed, 6 Apr 2011 08:13:30 +0000 (09:13 +0100)
committerChristophe Rhodes <csr21@cantab.net>
Wed, 6 Apr 2011 08:13:30 +0000 (09:13 +0100)
There's a race condition, I think, in between writing the socket port
and running the socket server; it might be as simple as reordering the
writing and the socket opening, but strange things happened once when
I did that.

swank.R

diff --git a/swank.R b/swank.R
index 8c5bafdccd1d5d198f534d971db0455fba703095..ebf580c510af115b66c703f4557797917b72c27e 100644 (file)
--- a/swank.R
+++ b/swank.R
@@ -18,10 +18,15 @@ swank <- function(port=4005) {
 }
 
 startSwank <- function(portFile) {
 }
 
 startSwank <- function(portFile) {
-  acceptConnections(FALSE, portFile)
+  acceptConnections(4005, portFile)
 }
 
 acceptConnections <- function(port, portFile) {
 }
 
 acceptConnections <- function(port, portFile) {
+  if(portFile != FALSE) {
+    f <- file(portFile, open="w+")
+    cat(port, file=f)
+    close(f)
+  }
   s <- socketConnection(host="localhost", server=TRUE, port=port, open="r+b")
   on.exit(close(s))
   serve(s)
   s <- socketConnection(host="localhost", server=TRUE, port=port, open="r+b")
   on.exit(close(s))
   serve(s)