So this is basically about getting common-lisp to use cffi to use the fcgi c library to interoperate with httpd. common-lisp <-> cffi <-> c code The stack so far: ``` pkg_add fcgi sbcl ``` httpd.conf: ``` location * { fastcgi socket tcp 127.0.0.1 8000 } ``` This is just whats needed for dev on a single machine. But, if it works here it will play nice on a multi-tech machine. I am starting with a complete working c example that will serve content thru httpd. (no cffi/common-lisp yet) Then I will work back from the common-lisp side minimizing the c code needed. I didn't show an earlier version of this that was just a "main()" . I took that and made it into a library with an include header file, and a src/*.c implentation file. This is so I can make a *.so that has just callable functions basicallyhat is what cffi will hook into. ``` #include #include "myfcgi.h" void myfcgi_serve1() { int sockfd = FCGX_OpenSocket(":8000", 1024); FCGX_Request request; char **ptr; FCGX_Init(); FCGX_InitRequest(&request, sockfd, 0); while (FCGX_Accept_r(&request) == 0) { FCGX_FPrintF(request.out, "Content-type: text/html\r\n\r\n"); FCGX_FPrintF(request.out, "

myfcgi -- serve1

\n"); ptr = request.envp; FCGX_FPrintF(request.out, "\n"); FCGX_Finish_r(&request); } } ``` So this mygcgi_serve1() function is a single function that is externally callable if I turn it into a .so. After getting that to work with httpd/fastcgi I now use a common-lisp code with cffi to do the same thing, but teh code is ran from inside common-lisp. ``` (defun ff-serve1 () (cffi:foreign-funcall "myfcgi_serve1" :void)) ``` That is the basics missing some cffi boilerplate. (I'll revisit that, also the details of the c Makefile stuff to handle making the .so file.) So I have common-lisp calling c code using cffi, and it serves http content thru OpenBSD httpd. I see that common-lisp isn't really doing anything itself yet, but this is a great place to now start doing more in common-lisp and maybe splitting up the c side of things to go along with that. Even if this doesn't pan out in total, I am happy to be as comfortable with cffi as I am now, and look forward to playing with it more. I understand that it's probably better to prefer native code (in common-lisp) BUT, Using cffi means that I can always get stuff done one way or the other.