Subject: [clisp-list] UDP network streams

From: Frode Vatvedt Fjeld <[email-masked]>
Date: 29 May 2001 16:43:44 +0200

Hi, does CLISP (for unix) support communication over UDP/IP?

-- 
Frode Vatvedt Fjeld

---

From: Sam Steingold <[email-masked]>
Date: 29 May 2001 12:49:03 -0400

> * In message <[email-masked]>
> * On the subject of "[clisp-list] UDP network streams"
> * Sent on 29 May 2001 16:43:44 +0200
> * Honorable Frode Vatvedt Fjeld <[email-masked]> writes:
>

I don't think so.
what do you need this for?

-- 
Sam Steingold (http://www.podval.org/~sds)
Support Israel's right to defend herself! <http://www.i-charity.com/go/israel>
Read what the Arab leaders say to their people on <http://www.memri.org/>
Yeah, yeah, I love cats too... wanna trade recipes?

---

From: Frode Vatvedt Fjeld <[email-masked]>
Date: 29 May 2001 21:59:13 +0200

Sam Steingold <[email-masked]> writes:

> I don't think so.  what do you need this for?

Well, I need it.. can I build something atop the FFI interface and
libc funtions?

Is there an (relatively) easy way to interface libc (FreeBSD) in
CLISP?

-- 
Frode Vatvedt Fjeld

---

From: Sam Steingold <[email-masked]>
Date: 29 May 2001 16:42:41 -0400

> * In message <[email-masked]>
> * On the subject of "Re: [clisp-list] UDP network streams"
> * Sent on 29 May 2001 21:59:13 +0200
> can I build something atop the FFI interface and
> libc funtions?
> 

yep - FFI is your friend.
look at modules/bindings/linuxlibc6 in the CLISP source tree.

-- 
Sam Steingold (http://www.podval.org/~sds)
Support Israel's right to defend herself! <http://www.i-charity.com/go/israel>
Read what the Arab leaders say to their people on <http://www.memri.org/>
The software said it requires Windows 3.1 or better, so I installed Linux.

---

From: Frode Vatvedt Fjeld <[email-masked]>
Date: 30 May 2001 02:08:32 +0200

Sam Steingold <[email-masked]> writes:

> yep - FFI is your friend.  look at modules/bindings/linuxlibc6 in
> the CLISP source tree.

Ok, now what is the intended way to pass buffers between lisp and C?

For example, the libc read function is defined like this

  (def-c-call-out read (:arguments (fd int) (buf c-pointer) (nbytes size_t))
                       (:return-type ssize_t)
                       (:name "full_read"))

What sort of lisp object can be used as a BUF here? I tried using an
array, but that didn't work..?

-- 
Frode Vatvedt Fjeld

---

From: Sam Steingold <[email-masked]>
Date: 30 May 2001 10:15:42 -0400

> * In message <[email-masked]>
> * Sent on 30 May 2001 02:08:32 +0200

I would think (array (unsigned-byte 8) nbytes)

please look at the modules/bindings/linuxlibc6.

-- 
Sam Steingold (http://www.podval.org/~sds)
Support Israel's right to defend herself! <http://www.i-charity.com/go/israel>
Read what the Arab leaders say to their people on <http://www.memri.org/>
Bus error -- please leave by the rear door.

---

From: Frode Vatvedt Fjeld <[email-masked]>
Date: 31 May 2001 02:36:45 +0200

> I would think (array (unsigned-byte 8) nbytes)

This is what happens:

[1]> (freebsd::read 1 (make-array 200 :element-type '(unsigned-byte 8)) 200)

*** - 
#(0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  0 0 0 0 0) cannot be converted to the foreign type FFI:C-POINTER
1. Break [2]> 
 
> please look at the modules/bindings/linuxlibc6.

Well, that is precisely where the definition above comes from. There
doesn't seem to be much there in the way of documentation there.

-- 
Frode Vatvedt Fjeld

---

From: Sam Steingold <[email-masked]>
Date: 31 May 2001 12:59:59 -0400

> * In message <[email-masked]>
> * Sent on 31 May 2001 02:36:45 +0200

Bruno said to this:

read() is a good example for a function which is not well handled by
the FFI, because of the untyped 'buf' which makes it possible to
inadvertently smash CLISP memory.

I'd recommend to write a wrapper that converts the bytes read (and
only those!) to a freshly allocated (array (unsigned-byte 8)).

Look at the "call-in" example in the impnotes.

Something like this. (Untested, I hope you can complete it.)

void* read_result_buf;
size_t read_result_len;
size_t read_result_size;
ssize_t my_read (int fd, size_t max)
{ 
  if (read_result_size < max) {
    read_result_size = max;
    read_result_buf = xrealloc(read_result_buf,read_result_size);
  }
  ssize_t n = full_read (fd, read_result_buf, max);
  if (n >= 0)
    read_result_len = n;
  return n;
}

(def-c-var read_result_buf (:type c-pointer))
(defun my-read (fd max)
  (let ((n (my_read fd max)))
    (if (< n 0)
      (error ... 'file-error ...))
    (if (= n 0)
      nil
      (cast read_result_buf `(c-ptr (c-array uint8 ,n)))
) ) )

An alternative is the use of read-sequence, of course.

Bruno

-- 
Sam Steingold (http://www.podval.org/~sds)
Support Israel's right to defend herself! <http://www.i-charity.com/go/israel>
Read what the Arab leaders say to their people on <http://www.memri.org/>
Only adults have difficulty with childproof caps.

---

From: [email-masked] (Don Cohen)
Date: Thu, 31 May 2001 11:16:14 -0700 (PDT)

I have no good advice here, but wanted to mention that
(1) I hope you get this stuff working
(2) I hope you try to make it reasonably clean and usable by others
(3) I hope you make it available to the rest of us.
If you do a good enough job of it I suppose Sam/Bruno might even
adopt it into the distributed version.

Thanks for that effort.

---

From: Frode Vatvedt Fjeld <[email-masked]>
Date: 07 Jun 2001 21:40:11 +0200

I've been looking a bit into the issue of creating a reasonable lisp
interface to UDP sockets. In my opinion, such an interface should
include some sort of event dispatch facility (i.e. a unix select kind
of thing). From what I've read of clisp documentation, there is no
existing event model in clisp. For example, SOCKET:SOCKET-WAIT only
waits for a single socket.

So this is a request for comments or advice on this issue. How
should/could synchronization to several (kinds of) sockets be
implemented?

And how come the socket streams extension is not present in my clisp,
taken from either FreeBSD or NetBSD's packages?

[1]> (socket:socket-server)

*** - READ from #<CONCATENATED-STREAM #<STRING-INPUT-STREAM> #<SYNONYM-STREAM *TERMINAL-IO*>>: there is no package with name "SOCKET"
1. Break [2]> 

-- 
Frode Vatvedt Fjeld

---

From: Miles Egan <[email-masked]>
Date: Thu, 7 Jun 2001 13:07:49 -0700

> should/could synchronization to several (kinds of) sockets be

I think the Unix model is pretty good here.  Something like select?

-- 
miles

---

From: Sam Steingold <[email-masked]>
Date: 07 Jun 2001 16:57:13 -0400

> * In message <[email-masked]>
> * Sent on 07 Jun 2001 21:40:11 +0200

I am not clairvoyant.  Sorry.  I really wish I were.

Who built your packages?
From which sources?
What is your CLISP version?  (lisp-implementation-version)
What does (apropos "socket") say?

-- 
Sam Steingold (http://www.podval.org/~sds)
Support Israel's right to defend herself! <http://www.i-charity.com/go/israel>
Read what the Arab leaders say to their people on <http://www.memri.org/>
Sex is like air.  It's only a big deal if you can't get any.

---

From: Frode Vatvedt Fjeld <[email-masked]>
Date: 07 Jun 2001 23:32:23 +0200

> What does (apropos "socket") say?

I now discovered the socket stuff is actually there, only there is
something funny going on with the reader or somewhere that causes the
following (to me) very unexpected behavior. I'm quite new to CLISP, so
please point me to some FAQ or wherever this behavior is explained.

[1]> (socket::socket-server)

*** - READ from #<CONCATENATED-STREAM #<STRING-INPUT-STREAM> #<SYNONYM-STREAM *TERMINAL-IO*>>: there is no package with name "SOCKET"
1. Break [2]> 
[3]> (in-package :socket)
#<PACKAGE SOCKET>
SOCKET[4]> (socket-server)
#<SOCKET-SERVER 0.0.0.0:2930>
SOCKET[5]> (in-package :user)
#<PACKAGE USER>
[6]> (socket::socket-server)
#<SOCKET-SERVER 0.0.0.0:2931>
[7]> (lisp-implementation-version)  
"2.25.1 (released 2001-04-06) (built 3200149047) (memory 3200149510)"

-- 
Frode Vatvedt Fjeld

---

From: [email-masked] (Don Cohen)
Date: Thu, 7 Jun 2001 15:27:46 -0700 (PDT)

The argument for select seems to apply just as well to tcp as udp.  
My hope is that clisp will soon support multiple threads, and at that
point I expect select will become less important.  For now I suggest
that you ignore this issue in your UDP interface.

I recall select being discussed at least once before.  I think the
result of the last such discsussion was the addition of SOCKET-STATUS.

---

From: Frode Vatvedt Fjeld <[email-masked]>
Date: 08 Jun 2001 14:58:19 +0200

> result of the last such discsussion was the addition of

Right, SOCKET-STATUS seems to me to be a select variant. It seems to
me it would be a mistake to start building a UDP interface based on
libc/FFI. The right thing would be to extend the existing SOCKET
package to support UDP in addition to TCP.

-- 
Frode Vatvedt Fjeld

---

From: Sam Steingold <[email-masked]>
Date: 08 Jun 2001 10:58:02 -0400

> * In message <[email-masked]>
> * Sent on 07 Jun 2001 23:32:23 +0200

You are confused: 2.25.1 did not have a SOCKET package.
(describe 'socket-server) would tell you that it is in LISP, not SOCKET.

get the latest released sources - 2.26 and apply the patches (or use CVS).
./configure --build build
try again your code.

-- 
Sam Steingold (http://www.podval.org/~sds)
Support Israel's right to defend herself! <http://www.i-charity.com/go/israel>
Read what the Arab leaders say to their people on <http://www.memri.org/>
A clear conscience is usually the sign of a bad memory.