From: Miguel Arroz
Subject: SB-BSD-SOCKETS problem
Date: 
Message-ID: <1090491363.201151@jubilee.esoterica.pt>
Hi!

  I'm trying to use the SB-BSD-SOCKETS package that comes in the latest version of SBCL. I need to setup an UDP server, so I tryied to run the last test on the 
tests.lisp file:

-----------------------------------------------------------------------------
(defun udp-server (port)
  (let ((s (make-instance 'inet-socket :type :datagram :protocol :udp)))
    (socket-bind s #(0 0 0 0) port)
    (loop
     (multiple-value-bind (buf len address port) (socket-receive s nil 500)
       (format t "Received ~A bytes from ~A:~A - ~A ~%"
	       len address port (subseq buf 0 (min 10 len)))))))
-----------------------------------------------------------------------------

  When I try to run this, SBCL sets up the server, with no problems. But when a client sends info to the server, the server crashes with this error:

-----------------------------------------------------------------------------
debugger invoked on a TYPE-ERROR in thread 690:
  The value NIL is not of type CONS.

You can type HELP for debugger help, or (SB-EXT:QUIT) to exit from SBCL.

restarts (invokable by number or by possibly-abbreviated name):
  0: [ABORT   ] Reduce debugger level (leaving debugger, returning to toplevel).
  1: [TOPLEVEL] Restart at toplevel READ/EVAL/PRINT loop.
(SB-KERNEL:%SETELT
 3
 NIL
 0
 #<SB-ALIEN-INTERNALS:ALIEN-VALUE :SAP #X05804000 :TYPE (ARRAY
                                                         (SB-ALIEN:UNSIGNED 32)
                                                         1)>)[:EXTERNAL]
-----------------------------------------------------------------------------

  I'm having this problem in a Suse 9.1 Linux on Intel, with SBCL compiled with CMUCL, and on a Mac OS X machine, with SBCL compiled with OpenMCL, so I suppose 
this is not a platform-related problem or incompatibility. What's happening?

  Yours

Miguel Arroz

From: ·········@random-state.net
Subject: Re: SB-BSD-SOCKETS problem
Date: 
Message-ID: <cdo9l3$3hl80$1@midnight.cs.hut.fi>
Miguel Arroz <·····@guiamac.com> wrote:

First of, you've better chance of getting SBCL advice on the sbcl-help    
mailing list. It's pretty low-volume, and also available thru 
gmane. Subscribe here:

 http://sourceforge.net/mail/?group_id=1373

As an added bonus other who may in future face the same problem have a
greater chance of seeing your query -- so you'll be helping other as well
by asking questions there.

Secondly it would have been nice (and would have saved some time) had you
also included the client code, so that I could just have pasted it in,
instead of cooking one up myself. No biggie, but all future bugreporters
take note. For more on the same topic, see:

 http://www.chiark.greenend.org.uk/~sgtatham/bugs.html

That said... even though your code came from the test file, note that that
code is not being used currently, as indicated by the comment above
it. I'm not offhand sure if it has just bitrotted, or if there is a bug in
socket-receive:

>  (multiple-value-bind (buf len address port) (socket-receive s nil 500)
                                                                 ^
                                                                 here

That nil there is the cause of the problem. Using 

 (socket-receive s (make-list 500) nil) 

instead works fine, and applying the following patch (no correctness
guaranteed) to contrib/sb-bsd-sockets/sockets.lisp seems to make it work
as written.

Index: sockets.lisp
===================================================================
RCS file: /cvsroot/sbcl/sbcl/contrib/sb-bsd-sockets/sockets.lisp,v
retrieving revision 1.9
diff -u -r1.9 sockets.lisp
--- sockets.lisp        31 May 2004 20:01:09 -0000      1.9
+++ sockets.lisp        22 Jul 2004 11:46:53 -0000
@@ -173,6 +173,8 @@
        (error "Must supply at least one of BUFFER or LENGTH"))
       (unless length
        (setf length (length buffer)))
+      (unless buffer
+       (setf buffer (make-list length)))
       (let ((copy-buffer (sb-alien:make-alien (array sb-alien:unsigned
1) lengt
h)))
        (unwind-protect
            (sb-alien:with-alien ((sa-len (array (sb-alien:unsigned
32) 2)))

Thanks for the report!

Cheers,

 -- Nikodemus                   "Not as clumsy or random as a C++ or Java. 
                             An elegant weapon for a more civilized time."
From: ·········@random-state.net
Subject: Re: SB-BSD-SOCKETS problem
Date: 
Message-ID: <cdo9vp$3hl80$2@midnight.cs.hut.fi>
·········@random-state.net wrote:

> That nil there is the cause of the problem. Using 

>  (socket-receive s (make-list 500) nil) 

Duh. I was a tad hasty there, unless you want O(N^2) behaviour make that
MAKE-ARRAY, not MAKE-LIST. Ditto for the patch.

Cheers,

 -- Nikodemus                   "Not as clumsy or random as a C++ or Java. 
                             An elegant weapon for a more civilized time."
From: ·········@random-state.net
Subject: Re: SB-BSD-SOCKETS problem
Date: 
Message-ID: <cdobgk$3m7j9$1@midnight.cs.hut.fi>
·········@random-state.net wrote:

> it. I'm not offhand sure if it has just bitrotted, or if there is a bug in
> socket-receive:

The latter was the case. Andreas Fuchs kindly committed a fix (in SBCL
0.8.12.51) just in time for the forthcoming 0.8.13 -- which should be
released over the weekend.

Cheers,

 -- Nikodemus                   "Not as clumsy or random as a C++ or Java. 
                             An elegant weapon for a more civilized time."
From: Miguel Arroz
Subject: Re: SB-BSD-SOCKETS problem
Date: 
Message-ID: <1090501963.334775@jubilee.esoterica.pt>
Hi!

  Thanks for the fast response! I used this newsgroup because I
didn't know about the existence of the mail-list... I forgot to
say I'm kinda newbie to LISP! :-)

  Anyway, thanks again for your support.

  Yours

Miguel Arroz
From: Miguel Arroz
Subject: Re: SB-BSD-SOCKETS problem
Date: 
Message-ID: <1090508768.872471@jubilee.esoterica.pt>
Hi!

  BTW, another basic question... when I use the socket-receive function,
the result is something like this:

#(#<SB-ALIEN-INTERNALS:ALIEN-VALUE :SAP #X08274E50 :TYPE (ARRAY # 1)>
      #<SB-ALIEN-INTERNALS:ALIEN-VALUE :SAP #X08274E54 :TYPE (ARRAY # 1)>
      #<SB-ALIEN-INTERNALS:ALIEN-VALUE :SAP #X08274E58 :TYPE (ARRAY # 1)>
      #<SB-ALIEN-INTERNALS:ALIEN-VALUE :SAP #X08274E5C :TYPE (ARRAY # 1)>
      #<SB-ALIEN-INTERNALS:ALIEN-VALUE :SAP #X08274E60 :TYPE (ARRAY # 1)>
      #<SB-ALIEN-INTERNALS:ALIEN-VALUE :SAP #X08274E64 :TYPE (ARRAY # 1)>
      #<SB-ALIEN-INTERNALS:ALIEN-VALUE :SAP #X08274E68 :TYPE (ARRAY # 1)> ...)

  How can I convert this to a normal characteres array? I know I can
use socket-make-stream, but that has the problem of not separating the
UDP packets that are received in a short period of time. Again, sorry
for the basic questions, but as a newbie I'm having some problems
understanding all of this at once...

  Yours

Miguel Arroz