[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Guile Interpreter as a Standalone Server
From: |
Neil Jerram |
Subject: |
Re: Guile Interpreter as a Standalone Server |
Date: |
Fri, 20 Oct 2006 21:45:26 +0100 |
User-agent: |
Gnus/5.1007 (Gnus v5.10.7) Emacs/21.4 (gnu/linux) |
Volkan YAZICI <address@hidden> writes:
> Hi,
>
> I need such a feature:
>
> /*
> * If there's an already running guile process in the background,
> * return it, otherwise create a new one and return new process.
> */
> interp = guile_interp(...);
I appreciate that Ludovic has already replied to you about this, but I
thought I'd some more thoughts.
I think the core of this idea is pretty simple to implement, and I've
appended a basic (and untested!) implementation of the server below.
After the basics, however, I think you would quickly run into
practical problems that are more tricky, such as whether you really
want an eval from one client to affect global data for another one;
what to do about error handling; what to do if an evaluation hangs;
whether you want to constrain evaluations so that they take place in a
"safe" environment; and so on.
In my view, addressing all of these things carefully would make for an
interesting project.
> With such a functionality, it'd be possible to
>
> - Parse & execute faster. (We won't need to create a new process
> everytime.)
Is this for a specific application, out of interest?
> - Cache parse plans.
I don't understand what this item means.
> - Use global variables that's accessible by any process using the
> same interpreter.
Yes - assuming that that is a desirable feature, in general.
> Is such a feature already supported by Guile? Can I achieve above 3
> functionalities with using another method?
This doesn't feel to me like something that needs to be supported by
core Guile; it feels like a useful application that can be built on
top of Guile.
Regards,
Neil
(let loop ((server (let ((s (socket PF_INET SOCK_STREAM 0)))
(setsockopt s SOL_SOCKET SO_REUSEADDR 1)
(bind s AF_INET INADDR_ANY port)
(listen s 5)
s))
(clients '())
(readable '()))
(if (null? readable)
;; Do a new select.
(loop server clients (car (select (cons server clients) '() '())))
;; Handle next readable socket.
(let ((s (car readable)))
(if (eq? s server)
;; Accept new connection.
(loop server (cons (car (accept s)) clients) (cdr readable))
;; Read from existing connection.
(let ((x (read s)))
(if (eof-object? x)
;; Connection closed.
(loop server (delq s clients) (cdr readable))
;; New form to evaluate.
(begin
(write (eval x (current-module)) s)
(loop server clients (cdr readable)))))))))