Problem with fastcgi hello world example /cgi/fcgi_hello.c
"Bjorn" <[email protected]> Sun, 10 Feb 2008 20:34:48 -0000
| Newsgroups | gmane.text.clearsilver.general |
|---|---|
| Message-ID | <[email protected]> |
Hi,
It's awesome that ClearSilver comes with a fastcgi example, because I
would have never figured out I had to wrap output functions, I thought
fastcgi took care of all of that on it's own. However the file has
some problems. The file I'm talking about is /cgi/fcgi_hello.c
The problems are all in the same function:
static int cs_write(void *ctx, const char *s, int n) {
return fwrite(const_cast<char *>(s), n, 1, FCGI_stdout);
}
The first problem is that .c is a C extension, but this function uses
C++. There is no other C++ code in this file. The other problem is
that fwrite returns the number of objects written, and not the number
of bytes/characters which is what cs_write is supposed to return.
Since fwrite does not return the same value as n, cgi_display will
always return an error, even though one had not occured. I have found
that this small fix solves all of these problems (I think, I'm new to C):
static int cs_write(void *ctx, const char *s, int n) {
if(fwrite(s, n, 1, FCGI_stdout) < 1){
return 0;
}
return n;
}