From: Karl A. Krueger
Subject: CL newbie seeking sockets and select()
Date: 
Message-ID: <ba0hbo$258$1@baldur.whoi.edu>
I'm new to Common Lisp, and thought that as a "toy project" to learn my
way around the system, a simple TCP-based chat system might not be too
hard to do.  For CL implementations I have CLISP, CMUCL, and SBCL handy
(my platform is Debian "testing" for i386).

However, I am having an awful time trying to find a socket library that
allows for the equivalent of a C select() across a set of open sockets,
to block on input until some is available on any socket.  So far I've
looked into the CLOCC PORT package, Daniel Barlow's SOCKETS, and the
CLISP SOCKET extension.

The CLISP SOCKET seems the closest to what I am looking for, but while
it can wait for an incoming connection on a SOCKET-SERVER, using the
SOCKET-STATUS it doesn't seem to be able to wait on a set of open
sockets for input.

I'm guessing there's some Right Thing that I am overlooking.

Any suggestions?  Thanks much!

-- 
Karl A. Krueger <········@example.edu>
Woods Hole Oceanographic Institution
Email address is spamtrapped.  s/example/whoi/
"Outlook not so good." -- Magic 8-Ball Software Reviews

From: Eric Marsden
Subject: Re: CL newbie seeking sockets and select()
Date: 
Message-ID: <wziissbwb0b.fsf@melbourne.laas.fr>
>>>>> "kak" == Karl A Krueger <········@example.edu> writes:

  kak> However, I am having an awful time trying to find a socket
  kak> library that allows for the equivalent of a C select() across a
  kak> set of open sockets, to block on input until some is available
  kak> on any socket. So far I've looked into the CLOCC PORT package,
  kak> Daniel Barlow's SOCKETS, and the CLISP SOCKET extension.

in CMUCL and SBCL, the SERVE-EVENT facility does exactly this. See the
CMUCL User's Manual

  <URL:http://cvs2.cons.org/ftp-area/cmucl/doc/cmu-user/serve-event.html>

or for some example code that uses it to do TCP port forwarding, see

  <URL:http://www.chez.com/emarsden/downloads/tcp-forwarder.lisp>

-- 
Eric Marsden                          <URL:http://www.laas.fr/~emarsden/>
From: Karl A. Krueger
Subject: Re: CL newbie seeking sockets and select()
Date: 
Message-ID: <ba2skb$oqq$1@baldur.whoi.edu>
Eric Marsden <········@laas.fr> wrote:
>>>>>> "kak" == Karl A Krueger <········@example.edu> writes:
> 
>  kak> However, I am having an awful time trying to find a socket
>  kak> library that allows for the equivalent of a C select() across a
>  kak> set of open sockets, to block on input until some is available
>  kak> on any socket. So far I've looked into the CLOCC PORT package,
>  kak> Daniel Barlow's SOCKETS, and the CLISP SOCKET extension.
> 
> in CMUCL and SBCL, the SERVE-EVENT facility does exactly this.

Thanks!  That is just what I was looking for.

(Also thanks to Paul Foley, who pointed the same out in email.)

Please pardon my evident Unix-centricity in looking for something named
something like "select()" ... we all have to start somewhere.  :)

-- 
Karl A. Krueger <········@example.edu>
Woods Hole Oceanographic Institution
Email address is spamtrapped.  s/example/whoi/
"Outlook not so good." -- Magic 8-Ball Software Reviews
From: Sam Steingold
Subject: Re: CL newbie seeking sockets and select()
Date: 
Message-ID: <m365oa3hyn.fsf@loiso.podval.org>
> * In message <············@baldur.whoi.edu>
> * On the subject of "Re: CL newbie seeking sockets and select()"
> * Sent on Fri, 16 May 2003 14:29:31 +0000 (UTC)
> * Honorable "Karl A. Krueger" <········@example.edu> writes:
>
> Eric Marsden <········@laas.fr> wrote:
> >>>>>> "kak" == Karl A Krueger <········@example.edu> writes:
> > 
> >  kak> However, I am having an awful time trying to find a socket
> >  kak> library that allows for the equivalent of a C select() across a
> >  kak> set of open sockets, to block on input until some is available
> >  kak> on any socket. So far I've looked into the CLOCC PORT package,
> >  kak> Daniel Barlow's SOCKETS, and the CLISP SOCKET extension.
> > 
> > in CMUCL and SBCL, the SERVE-EVENT facility does exactly this.
> 
> Thanks!  That is just what I was looking for.
> 
> (Also thanks to Paul Foley, who pointed the same out in email.)
> 
> Please pardon my evident Unix-centricity in looking for something named
> something like "select()" ... we all have to start somewhere.  :)

searching CLISP implementation notes
<http://clisp.cons.org/impnotes.html> for "select" would have brought
you to SOCKET-STATUS on the fourth hit.

-- 
Sam Steingold (http://www.podval.org/~sds) running RedHat9 GNU/Linux
<http://www.camera.org> <http://www.iris.org.il> <http://www.memri.org/>
<http://www.mideasttruth.com/> <http://www.palestine-central.com/links.html>
If a train station is a place where a train stops, what's a workstation?
From: Johannes Grødem
Subject: Re: CL newbie seeking sockets and select()
Date: 
Message-ID: <aadd58c3.0305161429.342995ac@posting.google.com>
* Sam Steingold <···@gnu.org>:

> [...]
> searching CLISP implementation notes
> <http://clisp.cons.org/impnotes.html> for "select" would have brought
> you to SOCKET-STATUS on the fourth hit.

This only lets you select on sockets, though?  With CMUCL/SBCL, the REPL
hooks into the event-loop, so you can listen for connections while
still being able to interact with the REPL.  It would be nice to be
able to do that in CLISP as well.  In fact, serve-event, or something like
it, for CLISP would be a nice feature.

(Sorry, I'm not volunteering, just a suggestion.)

-- 
johs
From: Sam Steingold
Subject: Re: CL newbie seeking sockets and select()
Date: 
Message-ID: <m37k8p1a32.fsf@loiso.podval.org>
> * In message <····························@posting.google.com>
> * On the subject of "Re: CL newbie seeking sockets and select()"
> * Sent on 16 May 2003 15:29:23 -0700
> * Honorable ····@copyleft.no (Johannes Grødem) writes:
>
> * Sam Steingold <···@gnu.org>:
> 
> > searching CLISP implementation notes
> > <http://clisp.cons.org/impnotes.html> for "select" would have brought
> > you to SOCKET-STATUS on the fourth hit.
> 
> This only lets you select on sockets, though?  With CMUCL/SBCL, the
> REPL hooks into the event-loop, so you can listen for connections
> while still being able to interact with the REPL.  It would be nice to
> be able to do that in CLISP as well.  In fact, serve-event, or
> something like it, for CLISP would be a nice feature.

actually, SOCKET-STATUS works with any file descriptor-based stream, so,
yes, you should be able to listen for connections while still being able
to interact with the REPL.

-- 
Sam Steingold (http://www.podval.org/~sds) running RedHat9 GNU/Linux
<http://www.camera.org> <http://www.iris.org.il> <http://www.memri.org/>
<http://www.mideasttruth.com/> <http://www.palestine-central.com/links.html>
Those who don't know lisp are destined to reinvent it, poorly.
From: Sam Steingold
Subject: Re: CL newbie seeking sockets and select()
Date: 
Message-ID: <m3bry23i1z.fsf@loiso.podval.org>
> * In message <············@baldur.whoi.edu>
> * On the subject of "CL newbie seeking sockets and select()"
> * Sent on Thu, 15 May 2003 17:04:56 +0000 (UTC)
> * Honorable "Karl A. Krueger" <········@example.edu> writes:
>
> The CLISP SOCKET seems the closest to what I am looking for, but while
> it can wait for an incoming connection on a SOCKET-SERVER, using the
> SOCKET-STATUS it doesn't seem to be able to wait on a set of open
> sockets for input.

You are mistaken.

<http://clisp.cons.org/impnotes/socket.html#so-status>:

(SOCKET:SOCKET-STATUS  socket-stream-or-list  &OPTIONAL [seconds [microseconds]])

    Checks whether it is possible to read from or write to a
    SOCKET:SOCKET-STREAM or whether a connection is available on a
    SOCKET:SOCKET-SERVER without blocking. (For the cognoscenti: this is
    the interface to select). This is similar to LISTEN, which checks
    only one stream and only for input, and SOCKET:SOCKET-WAIT, which
    works only with SOCKET:SOCKET-SERVERs. 

    Possible values of socket-stream-or-list

    SOCKET:SOCKET-STREAM or SOCKET:SOCKET-SERVER
        Returns T if a connection on the SOCKET:SOCKET-SERVER is
        available; or :INPUT, :OUTPUT or :IO if some input/output is
        possible on the SOCKET:SOCKET-STREAM
    (SOCKET:SOCKET-STREAM . direction)
        Return the appropriate keyword (:INPUT, :OUTPUT or :IO) if some
        input/output is possible on the SOCKET:SOCKET-STREAM in the
        specified direction (which should be one of :INPUT, :OUTPUT or
        :IO).
    a list of the above
        Return a list of values, one for each element of the argument list (a la MAPCAR)

    The optional arguments specify the timeout. NIL means wait forever,
    0 means poll. Note that this function never waits for input or
    output to arrive, only for information on input or output presense
    (so that READ-CHAR or WRITE-CHAR will not block) to become available
    (or a connection to become possible). 

    For each SOCKET:SOCKET-STREAM this function returns:

    NIL
        when no information is available or no operation is possible
    :ERROR
        when an i/o operation will cause an error 
    :INPUT
        when you can only read from the stream 
    :OUTPUT
        when you can only write to the stream 
    :IO
        when you can both read from and write to the stream 

note that SOCKET-STATUS has been additionally enhanced in the CVS to
distinguish between EOF and available input, see
<http://cvs2.cons.org/ftp-area/clisp/snapshots/impnotes/socket.html#so-status>

-- 
Sam Steingold (http://www.podval.org/~sds) running RedHat9 GNU/Linux
<http://www.camera.org> <http://www.iris.org.il> <http://www.memri.org/>
<http://www.mideasttruth.com/> <http://www.palestine-central.com/links.html>
I want Tamagochi! -- What for?  Your pet hamster is still alive!
From: Karl A. Krueger
Subject: Re: CL newbie seeking sockets and select()
Date: 
Message-ID: <ba3acr$oh$1@baldur.whoi.edu>
Sam Steingold <···@gnu.org> wrote:
>> * In message <············@baldur.whoi.edu>
>> * On the subject of "CL newbie seeking sockets and select()"
>> * Sent on Thu, 15 May 2003 17:04:56 +0000 (UTC)
>> * Honorable "Karl A. Krueger" <········@example.edu> writes:
>>
>> The CLISP SOCKET seems the closest to what I am looking for, but while
>> it can wait for an incoming connection on a SOCKET-SERVER, using the
>> SOCKET-STATUS it doesn't seem to be able to wait on a set of open
>> sockets for input.
> 
> You are mistaken.
> 
> <http://clisp.cons.org/impnotes/socket.html#so-status>:
[snip]
>    The optional arguments specify the timeout. NIL means wait forever,
>    0 means poll. Note that this function never waits for input or
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>    output to arrive, only for information on input or output presense
     ^^^^^^^^^^^^^^^^
>    (so that READ-CHAR or WRITE-CHAR will not block) to become available
>    (or a connection to become possible). 

What I want to do (as I understand it) is to wait for input or output to
arrive.

-- 
Karl A. Krueger <········@example.edu>
Woods Hole Oceanographic Institution
Email address is spamtrapped.  s/example/whoi/
"Outlook not so good." -- Magic 8-Ball Software Reviews
From: Sam Steingold
Subject: Re: CL newbie seeking sockets and select()
Date: 
Message-ID: <m3znlm1yf4.fsf@loiso.podval.org>
> * In message <···········@baldur.whoi.edu>
> * On the subject of "Re: CL newbie seeking sockets and select()"
> * Sent on Fri, 16 May 2003 18:24:27 +0000 (UTC)
> * Honorable "Karl A. Krueger" <········@example.edu> writes:
>
> Sam Steingold <···@gnu.org> wrote:
> >> * Honorable "Karl A. Krueger" <········@example.edu> writes:
> >>
> >> The CLISP SOCKET seems the closest to what I am looking for, but while
> >> it can wait for an incoming connection on a SOCKET-SERVER, using the
> >> SOCKET-STATUS it doesn't seem to be able to wait on a set of open
> >> sockets for input.
> > 
> > You are mistaken.
> > 
> > <http://clisp.cons.org/impnotes/socket.html#so-status>:
> [snip]
> >    The optional arguments specify the timeout. NIL means wait forever,
> >    0 means poll. Note that this function never waits for input or
>                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> >    output to arrive, only for information on input or output presense
>      ^^^^^^^^^^^^^^^^
> >    (so that READ-CHAR or WRITE-CHAR will not block) to become available
> >    (or a connection to become possible). 
> 
> What I want to do (as I understand it) is to wait for input or output to
> arrive.

The words you don't like are taken verbatim from the select() man page.
You are the second person to be confused by them, so I remove them now.

The bottom line is that SOCKET-STATUS is exactly what you asked for.
It works perfectly well for many people.

-- 
Sam Steingold (http://www.podval.org/~sds) running RedHat9 GNU/Linux
<http://www.camera.org> <http://www.iris.org.il> <http://www.memri.org/>
<http://www.mideasttruth.com/> <http://www.palestine-central.com/links.html>
Type louder, please.
From: Karl A. Krueger
Subject: Re: CL newbie seeking sockets and select()
Date: 
Message-ID: <ba3cu3$1mj$1@baldur.whoi.edu>
Sam Steingold <···@gnu.org> wrote:
> The words you don't like are taken verbatim from the select() man page.
> You are the second person to be confused by them, so I remove them now.
> 
> The bottom line is that SOCKET-STATUS is exactly what you asked for.
> It works perfectly well for many people.

Thanks for the clarification.

Looking closer, it seems my misunderstanding was actually in the
difference between:

	(SOCKET-STATUS my-socket NIL)
	
		 and
		 
	(SOCKET-STATUS (CONS my-socket :INPUT) NIL)

Heh ... now I can implement the same toy program in CMUCL and CLISP and
see which one I like better.  Thanks!  :)

-- 
Karl A. Krueger <········@example.edu>
Woods Hole Oceanographic Institution
Email address is spamtrapped.  s/example/whoi/
"Outlook not so good." -- Magic 8-Ball Software Reviews