From: Brian Jiang
Subject: Socket stream in Corman Lisp: hang when listen or read-char-no-hang
Date: 
Message-ID: <5574fefb-c088-4ef4-943d-3e74ae9a8b20@s8g2000prg.googlegroups.com>
I just installed Corman Lisp recently. But I meet a problem about its
socket stream. The problem is like this:

Firstly, I create a socket stream like:

(setq ss (make-socket-stream (make-client-socket :host
"137.117.3.30" :port 21))) ;; connect to ftp actually, just for
testing.

Then I read (read-line) all the context in the stream. It works well.
But after no data in stream, I call 'listen' or 'read-char-no-hang',
the program is hang (hang for ever and I have to kill it). It SHALL
return immediately.

Any idea about this?

Thanks,
Brian

From: George Neuner
Subject: Re: Socket stream in Corman Lisp: hang when listen or read-char-no-hang
Date: 
Message-ID: <ge5nl354to7movnsdfcr3lbepb084cuebj@4ax.com>
On Sat, 8 Dec 2007 09:21:52 -0800 (PST), Brian Jiang
<········@gmail.com> wrote:

>I just installed Corman Lisp recently. But I meet a problem about its
>socket stream. The problem is like this:
>
>Firstly, I create a socket stream like:
>
>(setq ss (make-socket-stream (make-client-socket :host
>"137.117.3.30" :port 21))) ;; connect to ftp actually, just for
>testing.
>
>Then I read (read-line) all the context in the stream. It works well.
>But after no data in stream, I call 'listen' or 'read-char-no-hang',
>the program is hang (hang for ever and I have to kill it). It SHALL
>return immediately.
>
>Any idea about this?
>
>Thanks,
>Brian

FTP is a dual connection protocol, it doesn't work with a single
connection.  see
http://en.wikipedia.org/wiki/File_Transfer_Protocol#Connection_Methods

George
--
for email reply remove "/" from address
From: Brian Jiang
Subject: Re: Socket stream in Corman Lisp: hang when listen or 	read-char-no-hang
Date: 
Message-ID: <4c4be67d-a09c-4f9b-b1ab-3c3a458f67e2@d27g2000prf.googlegroups.com>
On Dec 9, 3:19 pm, George Neuner <·········@/comcast.net> wrote:
> On Sat, 8 Dec 2007 09:21:52 -0800 (PST), Brian Jiang
>
>
>
> <········@gmail.com> wrote:
> >I just installed Corman Lisp recently. But I meet a problem about its
> >socket stream. The problem is like this:
>
> >Firstly, I create a socket stream like:
>
> >(setq ss (make-socket-stream (make-client-socket :host
> >"137.117.3.30" :port 21))) ;; connect to ftp actually, just for
> >testing.
>
> >Then I read (read-line) all the context in the stream. It works well.
> >But after no data in stream, I call 'listen' or 'read-char-no-hang',
> >the program is hang (hang for ever and I have to kill it). It SHALL
> >return immediately.
>
> >Any idea about this?
>
> >Thanks,
> >Brian
>
> FTP is a dual connection protocol, it doesn't work with a single
> connection.  seehttp://en.wikipedia.org/wiki/File_Transfer_Protocol#Connection_Methods
>
> George
> --
> for email reply remove "/" from address

I just use it as an example to test whether the code works. It is not
ftp problem. I know ftp need an additional data connection for some
commands. But here I have not invoked those commands.

In this example, when I connect to the ftp server, the ftp server
response a welcome message. And I can read the message successfully
using read-line. And then the stream is empty. Then I call 'listen'
and 'read-char-no-hang', in Corman Lisp, the program is hang. But in
other lisp implementaions such CLISP, Allegro Lisp and LipsWorks,
'listen' and 'read-char-no-hang' return immediately as expected and I
can use USER and PASS command to login in the server successfully.
From: George Neuner
Subject: Re: Socket stream in Corman Lisp: hang when listen or  read-char-no-hang
Date: 
Message-ID: <o98rl3pt6o02dr2n6cc0h9ctvd63l4ahvm@4ax.com>
On Sun, 9 Dec 2007 02:31:57 -0800 (PST), Brian Jiang
<········@gmail.com> wrote:

>On Dec 9, 3:19 pm, George Neuner <·········@/comcast.net> wrote:
>> On Sat, 8 Dec 2007 09:21:52 -0800 (PST), Brian Jiang
>>
>> >(setq ss (make-socket-stream (make-client-socket :host
>> >"137.117.3.30" :port 21))) ;; connect to ftp actually, just for
>> >testing.

>... when I connect to the ftp server, the ftp server
>response a welcome message. And I can read the message successfully
>using read-line. And then the stream is empty. Then I call 'listen'
>and 'read-char-no-hang', in Corman Lisp, the program is hang. But in
>other lisp implementaions such CLISP, Allegro Lisp and LipsWorks,
>'listen' and 'read-char-no-hang' return immediately as expected and I
>can use USER and PASS command to login in the server successfully.

Sockets by default are created synchronous - the raw TCP function
'recv' - which is underlying the stream 'listen' and 'read-char*'
functions - will block unless the socket is asynchronous.

I could be wrong, but from a quick glance at the latest version (1.9)
of Corman's socket library, it seems like it directly supports only
synchronous socket use.  The function 'populate-socket-read-buffer'
supports non-blocking reads and looks like it should work properly,
but AFAICT, the 'read-socket*' functions all call it with :blocking
set to T.  [I'm assuming that the stream read functions are internally
calling the socket read functions.]

There is a function 'socket-data-available' which can check whether
there is anything available to read.  You may be able to use it to
work around the problem.  It should be relatively simple to implement
new 'read-socket*' functions that work asynchronously.


George
--
for email reply remove "/" from address
From: Brian Jiang
Subject: Re: Socket stream in Corman Lisp: hang when listen or 	read-char-no-hang
Date: 
Message-ID: <51fb5343-24de-490d-85c3-fecbb16f5447@s8g2000prg.googlegroups.com>
On Dec 11, 5:45 am, George Neuner <·········@/comcast.net> wrote:
> On Sun, 9 Dec 2007 02:31:57 -0800 (PST), Brian Jiang
>
> <········@gmail.com> wrote:
> >On Dec 9, 3:19 pm, George Neuner <·········@/comcast.net> wrote:
> >> On Sat, 8 Dec 2007 09:21:52 -0800 (PST), Brian Jiang
>
> >> >(setq ss (make-socket-stream (make-client-socket :host
> >> >"137.117.3.30" :port 21))) ;; connect to ftp actually, just for
> >> >testing.
> >... when I connect to the ftp server, the ftp server
> >response a welcome message. And I can read the message successfully
> >using read-line. And then the stream is empty. Then I call 'listen'
> >and 'read-char-no-hang', in Corman Lisp, the program is hang. But in
> >other lisp implementaions such CLISP, Allegro Lisp and LipsWorks,
> >'listen' and 'read-char-no-hang' return immediately as expected and I
> >can use USER and PASS command to login in the server successfully.
>
> Sockets by default are created synchronous - the raw TCP function
> 'recv' - which is underlying the stream 'listen' and 'read-char*'
> functions - will block unless the socket is asynchronous.
>
> I could be wrong, but from a quick glance at the latest version (1.9)
> of Corman's socket library, it seems like it directly supports only
> synchronous socket use.  The function 'populate-socket-read-buffer'
> supports non-blocking reads and looks like it should work properly,
> but AFAICT, the 'read-socket*' functions all call it with :blocking
> set to T.  [I'm assuming that the stream read functions are internally
> calling the socket read functions.]
>
> There is a function 'socket-data-available' which can check whether
> there is anything available to read.  You may be able to use it to
> work around the problem.  It should be relatively simple to implement
> new 'read-socket*' functions that work asynchronously.
>
> George
> --
> for email reply remove "/" from address

Thanks for information. Will have a try later.

Regards,
Brian