Regards, some questions with respect to unix/cmucl 18b
1) I'm trying to find a function that will check if a port (say 7040) is
available
before a call to (EXT:CREATE-INET-LISTENER 7040). Anybody knows of such
a function.
2) What is the semantics of EXT:ADD-FD-HANDLER. I've seen that to
create a server
CL-HTTP uses ADD-FD-HANDLER instead of spawning a process on unix
(since no multiprocessing
exists). That is, is there any timing semantics to the handler?
3) Where is the internet interface of CMU documented. I could not find
it in the
Encycmuclopedia.
Thanks,
Tunc
Tunc Simsek <······@robotics.eecs.berkeley.edu> writes:
> Regards, some questions with respect to unix/cmucl 18b
>
> 1) I'm trying to find a function that will check if a port (say 7040) is
> available
> before a call to (EXT:CREATE-INET-LISTENER 7040). Anybody knows of such
> a function.
As others have already suggested, the only safe way to handle this
situation is to call create-inet-listener and to handle the error.
> 2) What is the semantics of EXT:ADD-FD-HANDLER. I've seen that to
> create a server
> CL-HTTP uses ADD-FD-HANDLER instead of spawning a process on unix
> (since no multiprocessing
> exists). That is, is there any timing semantics to the handler?
Here is a snippet from the CMUCL driver for the dynamic HTTP server
that we use in-house (called CLASH) that handles the connection stuff
on platforms without MP. Note that this was written in the middle of
the night to demo an application on a Sun Ultra, so this code might
both be overly complex and non-production quality (though a server
using this code has been running for nearly a month now, sustaining
some heavy benchmarking traffic as well as a bit of interactive use).
The normal deployment stuff uses MP code on Linux/x86...
The function start-http-listener sets everything up so that
connections get served by the actual server object via
serve-connection.
;;; Event-driven handler
#-MP
(defvar *fd-handlers* (make-hash-table))
#-MP
(defvar *fd-addresses* (make-hash-table))
#-MP
(defun start-http-listener (port server)
(labels ((read-handler (socket)
(let ((address (gethash socket *fd-addresses*)))
(system:remove-fd-handler (gethash socket *fd-handlers*))
(remhash socket *fd-handlers*)
(remhash socket *fd-addresses*)
(serve-connection server
(make-instance 'cmucl-connection
:socket socket
:binary-address address))))
(accept-handler (listener)
(multiple-value-bind (socket remote-host)
(ext:accept-tcp-connection listener)
(setf (gethash socket *fd-addresses*) remote-host
(gethash socket *fd-handlers*)
(system:add-fd-handler socket :input #'read-handler)))))
(let ((fd (ext:create-inet-listener port)))
(setf (gethash fd *fd-handlers*)
(system:add-fd-handler fd :input #'accept-handler)))))
> 3) Where is the internet interface of CMU documented. I could not find
> it in the
> Encycmuclopedia.
There's no documentation I'm aware of, but reading the code in
inter*.lisp will give you a rough impression of what needs to be
done most of the time.
Regs, Pierre.
--
Pierre R. Mai <····@acm.org> http://www.pmsf.de/pmai/
The most likely way for the world to be destroyed, most experts agree,
is by accident. That's where we come in; we're computer professionals.
We cause accidents. -- Nathaniel Borenstein
Tunc Simsek <······@robotics.eecs.berkeley.edu> writes:
> 1) I'm trying to find a function that will check if a port (say 7040) is
> available
> before a call to (EXT:CREATE-INET-LISTENER 7040). Anybody knows of such
> a function.
Pardon me for being curious, but why do you want to do this?
If there are other processes that might might bind a socket to that
port, they might as well do it between your check and call to
create-inet-listener. A safer way would probably be to just call
create-inet-listener and use handler-bind to catch any errors
(depending on what you're trying to do).
> 3) Where is the internet interface of CMU documented. I could not find
> it in the
> Encycmuclopedia.
I didn't find any either, so I just poke around in src/code/*.lisp.
--
// John Markus Bj�rndalen
John Markus Bjorndalen wrote:
>
> Tunc Simsek <······@robotics.eecs.berkeley.edu> writes:
>
> > 1) I'm trying to find a function that will check if a port (say 7040) is
> > available
> > before a call to (EXT:CREATE-INET-LISTENER 7040). Anybody knows of such
> > a function.
>
> Pardon me for being curious, but why do you want to do this?
>
well, it turns out I don't want to do that, as both you and a personal
reply
points out the race condition in this approach. I think I'll use:
(handler-case
(ext:create-inet-listener port)
(error ()
....))
> If there are other processes that might might bind a socket to that
> port, they might as well do it between your check and call to
> create-inet-listener. A safer way would probably be to just call
> create-inet-listener and use handler-bind to catch any errors
> (depending on what you're trying to do).
>
> > 3) Where is the internet interface of CMU documented. I could not find
> > it in the
> > Encycmuclopedia.
>
> I didn't find any either, so I just poke around in src/code/*.lisp.
that turns out to be the general approach. I guess that the
implementation
is conformant with most texts describing TCP/IP, BSD style sockets etc
...
that playing around with the code should suffice.
Thanks,
Tunc
>
> --
> // John Markus Bj�rndalen
On Thu, 10 Aug 2000 16:35:35 -0700, Tunc Simsek
<······@robotics.eecs.berkeley.edu> wrote:
> 3) Where is the internet interface of CMU documented. I could not find
> it in the
> Encycmuclopedia.
As far as I know, it is not formally documented. The only option currently
seems to browse the source code and/or docstrings.
Paolo
--
EncyCMUCLopedia * Extensive collection of CMU Common Lisp documentation
http://cvs2.cons.org:8000/cmucl/doc/EncyCMUCLopedia/