summaryrefslogtreecommitdiffabout
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--include/kingate/fastcgi.h15
-rw-r--r--src/fastcgi.cc5
2 files changed, 19 insertions, 1 deletions
diff --git a/include/kingate/fastcgi.h b/include/kingate/fastcgi.h
index fd293b9..6f136b3 100644
--- a/include/kingate/fastcgi.h
+++ b/include/kingate/fastcgi.h
@@ -20,56 +20,71 @@ namespace kingate {
/**
* socket file descriptor.
*/
int sock;
/**
* @param s the socket name. (if the socket starts with a colon,
* then it is interpreted as a tcp port number.
* @param bl backlog listen queue depth.
*/
fcgi_socket(const char* s,int bl);
/**
* @param s the file descriptor of preopened socket.
*/
fcgi_socket(int s);
~fcgi_socket();
};
/**
* The implementation of the interface to the FastCGI.
*/
class fcgi_interface : public cgi_interface {
public:
/**
+ * buffer for sbin
+ * @see sbin
+ */
+ char buf_sbin[512];
+ /**
* stdin fcgi streambuf.
*/
fcgi_streambuf sbin;
/**
+ * buffer for sbout
+ * @see sbout
+ */
+ char buf_sbout[512];
+ /**
* stdout fcgi streambuf.
*/
fcgi_streambuf sbout;
/**
+ * buffer for sberr
+ * @see sberr
+ */
+ char buf_sberr[512];
+ /**
* stderr fcgi streambuf.
*/
fcgi_streambuf sberr;
/**
* stdin istream.
*/
istream sin;
/**
* stdout ostream.
*/
ostream sout;
/**
* stderr ostream.
*/
ostream serr;
/**
* The FCGI request.
*/
FCGX_Request request;
/**
* @param s the socked used for interfacing with the server.
* @param f the request flags (e.g. FCGI_FAIL_ON_INTR).
*/
diff --git a/src/fastcgi.cc b/src/fastcgi.cc
index 6285370..8b7668c 100644
--- a/src/fastcgi.cc
+++ b/src/fastcgi.cc
@@ -16,49 +16,52 @@ namespace kingate {
_initialized = true;
}
sock = FCGX_OpenSocket(s,bl);
if(sock<0)
throw exception(CODEPOINT,"failed to FCGX_OpenSocket(");
// TODO: check if there is a ':', not if it starts with ':'
if(*s != ':')
if(chmod(s,0777)) // XXX: configurable.
throw exception(CODEPOINT,"failed to chmod()");
}
fcgi_socket::fcgi_socket(int s)
: sock(0) {
if(!_initialized) {
if( FCGX_Init() )
throw exception(CODEPOINT,"failed to FCGX_Init()");
_initialized = true;
}
}
fcgi_socket::~fcgi_socket() {
if(sock>=0)
close(sock);
}
fcgi_interface::fcgi_interface(fcgi_socket& s,int f)
- : sin(&sbin), sout(&sbout), serr(&sberr) {
+ : sbin(buf_sbin,sizeof(buf_sbin)),
+ sbout(buf_sbout,sizeof(buf_sbout)),
+ sberr(buf_sberr,sizeof(buf_sberr)),
+ sin(&sbin), sout(&sbout), serr(&sberr) {
if( FCGX_InitRequest(&request,s.sock,f) )
throw exception(CODEPOINT,"failed to FCGX_InitRequest()");
if( FCGX_Accept_r(&request) )
throw exception(CODEPOINT,"failed to FCGX_Accept_r()");
sbin.attach(request.in);
sbout.attach(request.out);
sberr.attach(request.err);
for(char **p = request.envp; *p; p++) {
const char *e = strchr(*p,'=');
if(!e){
// XXX: check if we have it already?
metavars[*p] = string(0);
}else{
int l = e-*p; e++;
// XXX: check if we have it already?
metavars[string(*p,l)]=e;
}
}
}
fcgi_interface::~fcgi_interface() {
sout.flush();
serr.flush();
FCGX_Finish_r(&request);
}