[Ecls-list] Problems with clines

Steve Smith tarka at internode.on.net
Sun Aug 26 07:44:24 UTC 2007


[n00b questions coming up, sorry.  I promise to document any useful
examples on the wiki :) ]

Basically what I'm trying to do is produce functionality similar to
the SBCL/CMUCL 'serve-event' (ideally a full port).  This is necessary
to do a single-threaded server.

> If you need to have such things, then use lisp foreign variables. Or
> static variables.

With these techniques how would I declare variable of type 'fd_set'
(it's an opaque typedef)?  I have a list of fds (with other metadata
that is ommitted here).  Ideally I would like to do something like
this:

  (clines "#include <sys/select.h>")

  ;; Somehow pull the opaque 'fd_set' typedef in as a type

  (defun waitfds (fdlist)
    (with-foreign-objects ((rfds 'fd_set)
                           (wfds 'fd_set))
      (dolist (fd fdlist)
        (c-inline (fd rfds) (:int :pointer-void) :void 
                  "FD_SET(#0, #1);"
                  :one-liner nil
                  :side-effects t))
      ;; select and return
      ;; ....

Does this make any sense?

Another method would be to malloc the fd_set structs in a c-inline and
return the pointers, then free them at the end.  This is more fragile
however, I'd rather have objects allocated on the stack, or at least
cleared up with unwind protect (hence the 'with-foreign-objects').

One other method would be to pass the whole list to the inline C and
traverse it there, but that would be much less elegant.

Any hints on the best way to do this would be appreciated.

Thanks,
Steve




More information about the ecl-devel mailing list