summaryrefslogtreecommitdiff
path: root/emacs
diff options
context:
space:
mode:
authorNeil Jerram <neil@ossau.uklinux.net>2008-12-12 23:59:21 +0000
committerNeil Jerram <neil@ossau.uklinux.net>2008-12-13 00:01:34 +0000
commit72553cb0ce71d38c46c336ce48c151919a83ba60 (patch)
treed298bacb76f05ab1acaa0f9169ccc06588f73306 /emacs
parenta9408365f9e34cdedef0cbaa6af1124a1e978ee9 (diff)
Support multiple concurrent instances of Emacs + GDS server
By: - Making the Unix socket name unique (for each Emacs instance), by appending Emacs's PID to it. - Changing the GDS server to listen on both Unix domain and TCP (and not to mind if the TCP bind fails, which will happen if another GDS instance has already bound to the TCP port number). - Adding this unique Unix socket name to the environment (as GDS_UNIX_SOCKET_NAME), so that Guile clients started from inside Emacs can pick it up. - Changing the GDS client code to look for GDS_UNIX_SOCKET_NAME in the environment, and to connect to the Unix socket with that name instead of over TCP. Guile clients started outside Emacs will not find GDS_UNIX_SOCKET_NAME and so will fall back to using TCP. This means they will connect to whichever Emacs + GDS server instance started first. * emacs/gds-server.el (gds-start-server): Take both Unix socket name and TCP port args, instead of just one (which could be either Unix or TCP), and pass these on to `run-server'. Remove unused optional bufname arg. * emacs/gds.el (gds-unix-socket-name, gds-tcp-port): New variables. (gds-socket-type-alist): Removed. (gds-run-debug-server): Pass gds-unix-socket-name and gds-tcp-port to gds-start-server. Add the Unix socket name to the environment. (gds-server-socket-type): Note now obsolete. * ice-9/gds-client.scm (connect-to-gds): Get Unix socket name from environment, and connect to this in preference to using TCP. * ice-9/gds-server.scm (run-server): Take both Unix socket name and TCP port args. Listen and accept connections on both.
Diffstat (limited to 'emacs')
-rw-r--r--emacs/gds-server.el19
-rw-r--r--emacs/gds.el21
2 files changed, 22 insertions, 18 deletions
diff --git a/emacs/gds-server.el b/emacs/gds-server.el
index 86defc07b..2a11a1a93 100644
--- a/emacs/gds-server.el
+++ b/emacs/gds-server.el
@@ -44,25 +44,24 @@
:group 'gds
:type '(choice (const :tag "nil" nil) directory))
-(defun gds-start-server (procname port-or-path protocol-handler &optional bufname)
- "Start a GDS server process called PROCNAME, listening on TCP port
-or Unix domain socket PORT-OR-PATH. PROTOCOL-HANDLER should be a
-function that accepts and processes one protocol form. Optional arg
-BUFNAME specifies the name of the buffer that is used for process
-output; if not specified the buffer name is the same as the process
-name."
- (with-current-buffer (get-buffer-create (or bufname procname))
+(defun gds-start-server (procname unix-socket-name tcp-port protocol-handler)
+ "Start a GDS server process called PROCNAME, listening on Unix
+domain socket UNIX-SOCKET-NAME and TCP port number TCP-PORT.
+PROTOCOL-HANDLER should be a function that accepts and processes
+one protocol form."
+ (with-current-buffer (get-buffer-create procname)
(erase-buffer)
(let* ((code (format "(begin
%s
(use-modules (ice-9 gds-server))
- (run-server %S))"
+ (run-server %S %S))"
(if gds-scheme-directory
(concat "(set! %load-path (cons "
(format "%S" gds-scheme-directory)
" %load-path))")
"")
- port-or-path))
+ unix-socket-name
+ tcp-port))
(process-connection-type nil) ; use a pipe
(proc (start-process procname
(current-buffer)
diff --git a/emacs/gds.el b/emacs/gds.el
index 1275d778b..01c9d97fe 100644
--- a/emacs/gds.el
+++ b/emacs/gds.el
@@ -37,10 +37,11 @@
;; The subprocess object for the debug server.
(defvar gds-debug-server nil)
-(defvar gds-socket-type-alist '((tcp . 8333)
- (unix . "/tmp/.gds_socket"))
- "Maps each of the possible socket types that the GDS server can
-listen on to the path that it should bind to for each one.")
+(defvar gds-unix-socket-name (format "/tmp/.gds-socket-%d" (emacs-pid))
+ "Name of the Unix domain socket that GDS will listen on.")
+
+(defvar gds-tcp-port 8333
+ "The TCP port number that GDS will listen on.")
(defun gds-run-debug-server ()
"Start (or restart, if already running) the GDS debug server process."
@@ -48,10 +49,14 @@ listen on to the path that it should bind to for each one.")
(if gds-debug-server (gds-kill-debug-server))
(setq gds-debug-server
(gds-start-server "gds-debug"
- (cdr (assq gds-server-socket-type
- gds-socket-type-alist))
+ gds-unix-socket-name
+ gds-tcp-port
'gds-debug-protocol))
- (process-kill-without-query gds-debug-server))
+ (process-kill-without-query gds-debug-server)
+ ;; Add the Unix socket name to the environment, so that Guile
+ ;; clients started from within this Emacs will be able to use it,
+ ;; and thereby ensure that they connect to the GDS in this Emacs.
+ (setenv "GDS_UNIX_SOCKET_NAME" gds-unix-socket-name))
(defun gds-kill-debug-server ()
"Kill the GDS debug server process."
@@ -617,7 +622,7 @@ you would add an element to this alist to transform
:group 'gds)
(defcustom gds-server-socket-type 'tcp
- "What kind of socket the GDS server should listen on."
+ "This option is now obsolete and has no effect."
:group 'gds
:type '(choice (const :tag "TCP" tcp)
(const :tag "Unix" unix)))