From: Brian King
Subject: CMUCL Sockets and Docs
Date: 
Message-ID: <slrn9v6upf.54o.bking@mellie.lan>
Howdy,

I'm new to Lisp and I'm having a difficult time figuring a few things
out. For one, I'm trying to decide on a Lisp system. I've tried clisp
and CMUCL. I can't get GCL to compile on my Linux box, after numerous
attempts, so I've given up on that one. clisp and CMUCL seem rather
comparable on the surface, although CMUCL seems to have more
extensions, such as processes. Unfortunately, I can't find extensive
documentation on CMUCL. Is there a recommended freeware
implementation, or is this very much a personal feel kind of thing?

How do I work with TCP/IP sockets in CMUCL? I tried the
connect-to-inet-socket function, but then I can't figure out how to
read and write the socket (it appears, from the description and the
source code, that it returns an integer rather than a stream, as I was
expecting from implementing a simple HTTP protocol suite in
clisp). The CMUCL user's guide doesn't appear to offer information on
sockets, only on WIRE, which, I think, is not what I'm looking for.

Are CMUCL processes documented anywhere?


-- 
Brian King, linux_king at yahoo dot com

From: Dr. Edmund Weitz
Subject: Re: CMUCL Sockets and Docs
Date: 
Message-ID: <m3herwfn2z.fsf@bird.agharta.de>
·····@mellie.lan (Brian King) writes:

> Howdy,
> 
> I'm new to Lisp and I'm having a difficult time figuring a few things
> out. For one, I'm trying to decide on a Lisp system. I've tried clisp
> and CMUCL. I can't get GCL to compile on my Linux box, after numerous
> attempts, so I've given up on that one. clisp and CMUCL seem rather
> comparable on the surface, although CMUCL seems to have more
> extensions, such as processes. Unfortunately, I can't find extensive
> documentation on CMUCL. Is there a recommended freeware
> implementation, or is this very much a personal feel kind of thing?
> 
> How do I work with TCP/IP sockets in CMUCL? I tried the
> connect-to-inet-socket function, but then I can't figure out how to
> read and write the socket (it appears, from the description and the
> source code, that it returns an integer rather than a stream, as I was
> expecting from implementing a simple HTTP protocol suite in
> clisp). The CMUCL user's guide doesn't appear to offer information on
> sockets, only on WIRE, which, I think, is not what I'm looking for.
> 
> Are CMUCL processes documented anywhere?
> 
> 
> -- 
> Brian King, linux_king at yahoo dot com


Paolo Amoroso's EncyCMUCLopedia is a great collection of CMUCL-related
documents including the current CMUCL documentation. I think you
should find everything you need in there.

The home of the EncyCMUCLopedia is usually
<http://cvs2.cons.org:8000/cmucl/doc/EncyCMUCLopedia/> but due to
problems with cons.org you should try
<http://web.mclink.it/amoroso/ency/README> at the moment.

As for CLISP vc. CMUCL the CMUCL FAQ
<http://www.cons.org/cmucl/FAQ.html> IMHO has a fair and correct
answer:

  Q: How does CMUCL compare with other Common Lisp implementations?

  A: The short answer is that this really depends on your needs. Most
  free implementations are fairly easy to install, and you should be
  able to obtain evaluation copies of the commercial implementations,
  so it isn't difficult to make a choice yourself.

  A longer answer is that compared with the various commercial Common
  Lisp implementations, CMUCL is free: you can use it without any
  licensing restrictions and for zero upfront cost. You also have
  access to the source code if you wish to customize the
  implementation to your requirements. However, you can't get a
  support contract from the vendor, and CMUCL is missing certain
  features present in the commercial implementations (graphical
  browsers, widgets, add-on libraries ...).

  Compared with CLISP, CMUCL runs on fewer platforms and has
  significantly higher memory usage. CLISP also has better
  internationalization support, in particular support for
  UNICODE. Since CMUCL compiles to native code, it is an order of
  magnitude faster on most applications than CLISP's bytecode
  execution model. However, the mathematical primitives in CLISP are
  very fast, in particular its bignum operations. CLISP also provides
  floats of unlimited precision, while CMUCL is limited to IEEE-754
  singles and doubles. CMUCL also has a more powerful foreign function
  interface than CLISP, supports multithreading on x86, and has a more
  powerful networking library. The builtin CLOS implementation in
  CLISP is missing certain features, notably the metaobject
  protocol.

Edi.
From: Brian King
Subject: Re: CMUCL Sockets and Docs
Date: 
Message-ID: <slrn9v71fh.54o.bking@mellie.lan>
On 15 Nov 2001 09:35:48 +0100, Dr. Edmund Weitz <···@agharta.de> wrote:
>Paolo Amoroso's EncyCMUCLopedia is a great collection of CMUCL-related
>documents including the current CMUCL documentation. I think you
>should find everything you need in there.
>
>The home of the EncyCMUCLopedia is usually
><http://cvs2.cons.org:8000/cmucl/doc/EncyCMUCLopedia/> but due to
>problems with cons.org you should try
><http://web.mclink.it/amoroso/ency/README> at the moment.

Aha! I went looking for that a few days ago, but ran into the cons.org
problems. I have now found exactly the information I was looking
for. Thank you.

>As for CLISP vc. CMUCL the CMUCL FAQ
><http://www.cons.org/cmucl/FAQ.html> IMHO has a fair and correct
>answer:

It does. I've read that before, but I've been in the midst of a
whirlwind learning tour and forgot most of it. I may have to choose
between them on a project by project basis (e.g. unicode + low memory
vs. threading + fast execution). Having figured out sockets, though, I
think I'll stick with CMUCL for the time being.

Thanks for you help.

-- 
Brian King, linux_king at yahoo dot com
From: Daniel Barlow
Subject: Re: CMUCL Sockets and Docs
Date: 
Message-ID: <874rnwm8bl.fsf@noetbook.telent.net>
·····@mellie.lan (Brian King) writes:

> How do I work with TCP/IP sockets in CMUCL? I tried the

Get the source package if you don't have it already, and look at
code/internet.lisp - most of what you need is in there

Or use the portability layer in CLOCC PORT, if you prefer.

> source code, that it returns an integer rather than a stream, as I was

The integer is a file descriptor.  (system:make-fd-stream n) will
create a stream that you can do with to using the normal stuff.


-dan

-- 

  http://ww.telent.net/cliki/ - Link farm for free CL-on-Unix resources 
From: Pierre R. Mai
Subject: Re: CMUCL Sockets and Docs
Date: 
Message-ID: <87n11oujpw.fsf@orion.bln.pmsf.de>
·····@mellie.lan (Brian King) writes:

> How do I work with TCP/IP sockets in CMUCL? I tried the
> connect-to-inet-socket function, but then I can't figure out how to
> read and write the socket (it appears, from the description and the
> source code, that it returns an integer rather than a stream, as I was
> expecting from implementing a simple HTTP protocol suite in
> clisp). The CMUCL user's guide doesn't appear to offer information on
> sockets, only on WIRE, which, I think, is not what I'm looking for.

The socket stuff isn't really well documented (documented at all?), so
you'll have to sometimes look at the source code, which can be found
in code/internet.lisp in the CMU CL sources.  You can also find
examples in the MP code, in code/multi-proc.lisp, for example the
server-side stuff done by start-lisp-connection-listener.

To give a short overview (which maybe could be added to future
editions of the EncyCMUCLopedia, should I not get around to writing a
relevant chapter for the cmu-user guide):

All symbols having to do with the sockets interface are exported from
the EXTENSIONS package (nickname EXT).  They are modelled to some
degree after the BSD sockets interface, though they combine and
simplify certain operations from the POV of the casual user.

All socket functions return and work on Unix socket/file-descriptors,
just like the normal BSD sockets interface.  You can use the Unix
Interface functions for working with them (e.g. unix:unix-close).  You
can also use the standard CMUCL File Descriptor Streams facility to
create streams for descriptors that represent connected stream-type
(e.g. TCP) sockets, by using MAKE-FD-STREAM.  See the Unix Interface
section of the User Manual (especially section 6.7 for File Descriptor
Streams) for details.

The interface combines the aspects of socket type and socket protocol
into that of a socket "kind".  Currently the following kinds are
supported:

- :stream => Creates sockets of type SOCK_STREAM.  For internet domain
  sockets (AF_INET) this selects the TCP protocol.  For unix domain
  sockets (AF_UNIX) this "selects" the default stream protocol.

- :datagram => Creates sockets of type SOCK_DGRAM.  For internet
  domain (AF_INET) this selects the UDP protocol.  For unix domain
  sockets (AF_UNIX) this "selects" the default datagram protocol.

1. Clients (medium-level stuff)

Clients can create connections to sockets with connect-to-unix-socket
(for unix/local domain sockets) or connect-to-inet-socket (for
inet/IPv4 domain sockets):

connect-to-unix-socket (path &optional (kind :stream))

  Connect to a unix domain socket of the given kind at the given
  path.  Returns the connected socket descriptor.

connect-to-inet-socket (host port &optional (kind :stream))

  Connect to inet domain socket of the given kind at the given host
  (either a resolvable hostname string or an (unsigned-byte 32) that
  contains the IPv4 address in host-order) and port.  Returns the
  connected socket descriptor.

2. Servers (medium-level stuff)

Servers can create and bind inet domain sockets using
create-inet-listener.  They can accept pending connections on this
socket with accept-tcp-connection:

create-inet-listener (port &optional (kind :stream)
                           &key
                           reuse-address
                           (backlog 5))

  Creates an inet domain socket and binds it to port on all
  interfaces of the local host.  The returned descriptor represents
  the unconnected socket.  Processes can wait for unconnected input or
  connection attempts on it with mp:process-wait-until-fd-usable, or
  they can use the standard operations of the SERVE-EVENT facility to
  wait for and process events on this fd.  The argument reuse-address
  controls the use of the socket option SO_REUSEADDR, backlog
  specifies the size of the backlog queue for :stream sockets, as
  passed to the kernel via the second argument to listen(2).

accept-tcp-connection (unconnected)

  This accepts a pending connection on the unconnected :stream socket,
  and returns a new fd for the connection, which can then be used for
  e.g. make-fd-stream, etc.  The connection can be closed with
  socket-close (this is automatically done for fd-streams when they
  are closed via cl:close, or upon GC when :auto-close was true in the
  call to make-fd-stream), etc.

3. Out of band data (medium-level stuff)

Handlers for out of band data (the stuff sent and received by
send/recv on sockets) can be added via add-oob-handler, and removed
via remove-oob-handler and remove-all-oob-handlers.  OOB data can be
sent with send-character-out-of-band.

add-oob-handler (fd char handler)

  Arange to funcall HANDLER (with no arguments) when CHAR shows up
  out-of-band on FD.

remove-oob-handler (fd char)

  Remove any handlers for CHAR on FD.

remove-all-oob-handlers (fd)

  Remove all handlers for FD.

send-character-out-of-band (fd char)

  Sends CHAR across FD out of band.

4. File Descriptor Streams

File descriptor streams can be created from descriptors using
make-fd-stream.  After that they can be handled like normal Common
Lisp streams.  See section 6.7 of the User Manual for details.

5. Creating and closing sockets and other low-level stuff

Sockets can be created with create-unix-socket (for unix domain
sockets) and create-inet-socket (for inet domain sockets). Sockets can
be closed with close-socket.

htonl (x)
ntohl (x)
htons (x)
ntohs (x)

  Does the usual host-order to network-order and vice-versa
  byte-swapping on 4 byte (*l) or 2 byte (*s) numbers, if required.

lookup-host-entry (host)
  Return a host-entry for the given host. The host may be an address
  string or an IP address, i.e. (unsigned-byte 32), in host order.

host-entry-name (host-entry)
host-entry-aliases (host-entry)
host-entry-addr-list (host-entry)
host-entry-addr (host-entry)

  Accesses various slots of the host-entry structure.  host-entry-addr
  returns the first element of host-entry-addr-list.

create-unix-socket (&optional (kind :stream))

  Create an unbound unix domain socket of the given kind.

create-inet-socket (&optional (kind :stream))

  Create an unbound inet domain socket of the given kind.

close-socket (socket)

  Close the given socket.  This works on all kinds of sockets.

get-peer-host-and-port (socket) ;; Unexported

  Return the peer host address and port in host order for a connected
  socket.

get-socket-host-and-port (socket) ;; Unexported

  Return the socket host address and port in host order for a bound or
  connected socket.

> Are CMUCL processes documented anywhere?

Again this is something with little documentation, but there are
entries in the current EncyCMUCLopedia for starters.  The source code
also provides a couple of examples, as mentioned above.

Hope this helps...

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
From: Brian King
Subject: Re: CMUCL Sockets and Docs
Date: 
Message-ID: <slrn9vc6m4.1g3.linux_king@mellie.lan>
On 15 Nov 2001 16:39:23 +0100, Pierre R. Mai <····@acm.org> wrote:
...
>
>Hope this helps...
>
>Regs, Pierre.

Excellent stuff. Thank you.

-- 
Brian King, linux_king at yahoo dot com