Discussion:
Slime, SBCL and add-fd-handler
Dmitri Hrapof
2006-01-05 16:03:17 UTC
Permalink
Hello!
I'm using add-fd-handler in my server,
and everything works in raw terminal.
However, when I start server from Slime,
I have to call (SB-IMPL::SERVE-EVENT) manually to
get my callbacks called and client's request
answered.
Is this expected behaviour?
What is idiomatic solution? It seems to me
I've done everything as Araneida does:

(defun make-repl-friendly (s)
(when *repl-friendly*
(%SYSDEP
"adds callbacks for socket"
#+sbcl
(sb-sys:add-fd-handler
(sb-bsd-sockets:socket-file-descriptor s)
:input
#'(lambda (fd)
(declare (ignore fd))
(loop while (op:work_pending *the-orb*)
do (op:perform_work *the-orb*)))))))

Where should I dig?

Thanks, Dmitri
Helmut Eller
2006-01-06 09:10:27 UTC
Permalink
Post by Dmitri Hrapof
Hello!
I'm using add-fd-handler in my server,
and everything works in raw terminal.
However, when I start server from Slime,
I have to call (SB-IMPL::SERVE-EVENT) manually to
get my callbacks called and client's request
answered.
Is this expected behaviour?
No.
Post by Dmitri Hrapof
What is idiomatic solution?
I think the most idiomatic solution would be use threads instead of
fd-handlers.
Post by Dmitri Hrapof
It seems to me
(defun make-repl-friendly (s)
(when *repl-friendly*
(%SYSDEP
"adds callbacks for socket"
#+sbcl
(sb-sys:add-fd-handler
(sb-bsd-sockets:socket-file-descriptor s)
:input
#'(lambda (fd)
(declare (ignore fd))
(loop while (op:work_pending *the-orb*)
do (op:perform_work *the-orb*)))))))
Where should I dig?
How do you wait for incoming requests? Fd-handlers are usually called
when an I/O operation would block (and, of course, explicit calls to
serve-event). In the usual SLIME/SBCL setup, the main thread blocks
in a call to READ and should call fd-handlers. Note that the main
thread writes its output to the *inferior-lisp* buffer and not the
*slime-repl* buffer (SLIME creates its own "repl thread" for the its
REPL).

Maybe you can find out something by looking at the backtraces for each
thread: list the thread with `M-x slime-list-threads' and press `d' to
invoke the debugger on the selected thread.

Helmut.
Dmitri Hrapof
2006-01-08 14:57:52 UTC
Permalink
Post by Helmut Eller
Post by Dmitri Hrapof
What is idiomatic solution?
I think the most idiomatic solution would be use threads instead of
fd-handlers.
I'd like to stay as cross-platform as possible, so I'd prefer not to
use threads while select() suffices. But thank you for your answer.
Thomas F. Burdick
2006-01-06 12:41:03 UTC
Permalink
Post by Dmitri Hrapof
Hello!
I'm using add-fd-handler in my server,
and everything works in raw terminal.
However, when I start server from Slime,
I have to call (SB-IMPL::SERVE-EVENT) manually to
get my callbacks called and client's request
answered.
What platform? What is the value of swank:*communication-style*? I
routinely use serve-event in combination with slime and sbcl, so I can
confirm that everything should work correctly, at least if you use
:fd-handler communication. Maybe you're on a threaded platform, and
slime's threaded communication is somehow blocking serve-event? If
that's the case, the easiest solution might be to spawn a thread that
just calls into serve-event.
Dmitri Hrapof
2006-01-08 14:53:55 UTC
Permalink
Post by Thomas F. Burdick
What platform?
SBCL 0.9.8, Linux 2.6.13 i686
Post by Thomas F. Burdick
What is the value of swank:*communication-style*?
it was :spawn, now it's :fd-handler and everything works.
Thanks a lot!
Loading...