Why IMPORT c failed

Started by dexter, November 13, 2011, 05:43:08 AM

Previous topic - Next topic

dexter

After before

I changed a new way



Import libfcgi.so to run it

I thought it will work, BUT  NEWLISP DISPOINTED ME AGAIN!



#!/usr/bin/newlisp
(import "/usr/local/lib/libfcgi.so.0.0.0" "FCGI_Accept")
    (while (>= (FCGI_Accept) 0)  
;       (net-send 1  (pack "c c c c c c c c" 0x01 0x06 0x00 0x01 0x00 0x57  0x00 0x00))
        (print "Content-type: text/htmlrnrn"
             "<title>Newlisp FastCGI Hello!</title>"
        "<h1>FastCGI Hello!</h1>" )
    )  


save to a file like /tmp/fcgi.lsp

run it by spawn-fcgi

spawn-fcgi -p 9000 -f /tmp/fcgi.lsp


YOU KNOW it is almost like in C version

ANYBODY can tell me why?

I used wireshark to capture the process

it turned out to be this program only send a fastcgi foot  to browser

Did I miss something ?

sunmountain

#1
First, you should always end with rn.

Second, be nice an end with 0, if everything is OK.

Third, is the script callable (chmod +755 /tmp/fcgi.lsp) ?

Forth, if you import libfcgi, your standard out channel is not changed to the one the FCGI server

offers.

A print in newlisp will still go to stdout.

If you develop fcgi programs in C, print* is overwritten in fcgi_stdio.h.

So, you have to deal with this, too.



#!/usr/bin/newlisp
(import "/usr/local/lib/libfcgi.so.0.0.0" "FCGI_Accept")
(import "/usr/local/lib/libfcgi.so.0.0.0" "FCGI_puts")
    (while (>= (FCGI_Accept) 0)
        (FCGI_puts "Content-type: text/htmlrnrn")
        (FCGI_puts "<title>Newlisp FastCGI Hello!</title>rn")
        (FCGI_puts "<h1>FastCGI Hello!</h1>rn")
    )
(exit 0)  


Didn't check it, but that should do.



For example, see the magic http://opensource.apple.com/source/apache_mod_php/apache_mod_php-12/php/sapi/cgi/libfcgi/include/fcgi_stdio.h">here.

dexter

#2
Thanks man

I did it

lol





https://github.com/guu/newlisp-fastcgi/blob/master/fcgi.lsp">https://github.com/guu/newlisp-fastcgi/ ... r/fcgi.lsp">https://github.com/guu/newlisp-fastcgi/blob/master/fcgi.lsp



next I'll do the multi process version



Soon, newlisp can run in fastcgi mode

So great

TedWalther

#3
Congratulations!
Cavemen in bearskins invaded the ivory towers of Artificial Intelligence.  Nine months later, they left with a baby named newLISP.  The women of the ivory towers wept and wailed.  \"Abomination!\" they cried.