Page 1 of 1

Why IMPORT c failed

Posted: Sun Nov 13, 2011 1:43 pm
by dexter
After before
I changed a new way

Import libfcgi.so to run it
I thought it will work, BUT NEWLISP DISPOINTED ME AGAIN!

Code: Select all

#!/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/html\r\n\r\n"
             "<title>Newlisp FastCGI Hello!</title>" 
        "<h1>FastCGI Hello!</h1>" )
    )   

save to a file like /tmp/fcgi.lsp
run it by spawn-fcgi

Code: Select all

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 ?

Re: Why IMPORT c failed

Posted: Sun Nov 13, 2011 2:01 pm
by sunmountain
First, you should always end with \r\n.
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.

Code: Select all

#!/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/html\r\n\r\n")
        (FCGI_puts "<title>Newlisp FastCGI Hello!</title>\r\n")
        (FCGI_puts "<h1>FastCGI Hello!</h1>\r\n")
    ) 
(exit 0)  
Didn't check it, but that should do.

For example, see the magic here.

Re: Why IMPORT c failed

Posted: Mon Nov 14, 2011 3:30 am
by dexter
Thanks man
I did it
lol


https://github.com/guu/newlisp-fastcgi/ ... r/fcgi.lsp

next I'll do the multi process version

Soon, newlisp can run in fastcgi mode
So great

Re: Why IMPORT c failed

Posted: Tue Nov 15, 2011 8:47 am
by TedWalther
Congratulations!