Why IMPORT c failed

Q&A's, tips, howto's
Locked
dexter
Posts: 74
Joined: Fri Nov 11, 2011 12:55 am

Why IMPORT c failed

Post 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 ?

sunmountain
Posts: 39
Joined: Tue Mar 15, 2011 5:11 am

Re: Why IMPORT c failed

Post 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.

dexter
Posts: 74
Joined: Fri Nov 11, 2011 12:55 am

Re: Why IMPORT c failed

Post 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

TedWalther
Posts: 608
Joined: Mon Feb 05, 2007 1:04 am
Location: Abbotsford, BC
Contact:

Re: Why IMPORT c failed

Post by TedWalther »

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.

Locked