summaryrefslogtreecommitdiffabout
Unidiff
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 {
20 /** 20 /**
21 * socket file descriptor. 21 * socket file descriptor.
22 */ 22 */
23 int sock; 23 int sock;
24 24
25 /** 25 /**
26 * @param s the socket name. (if the socket starts with a colon, 26 * @param s the socket name. (if the socket starts with a colon,
27 * then it is interpreted as a tcp port number. 27 * then it is interpreted as a tcp port number.
28 * @param bl backlog listen queue depth. 28 * @param bl backlog listen queue depth.
29 */ 29 */
30 fcgi_socket(const char* s,int bl); 30 fcgi_socket(const char* s,int bl);
31 /** 31 /**
32 * @param s the file descriptor of preopened socket. 32 * @param s the file descriptor of preopened socket.
33 */ 33 */
34 fcgi_socket(int s); 34 fcgi_socket(int s);
35 ~fcgi_socket(); 35 ~fcgi_socket();
36 }; 36 };
37 37
38 /** 38 /**
39 * The implementation of the interface to the FastCGI. 39 * The implementation of the interface to the FastCGI.
40 */ 40 */
41 class fcgi_interface : public cgi_interface { 41 class fcgi_interface : public cgi_interface {
42 public: 42 public:
43 /** 43 /**
44 * buffer for sbin
45 * @see sbin
46 */
47 char buf_sbin[512];
48 /**
44 * stdin fcgi streambuf. 49 * stdin fcgi streambuf.
45 */ 50 */
46 fcgi_streambuf sbin; 51 fcgi_streambuf sbin;
47 /** 52 /**
53 * buffer for sbout
54 * @see sbout
55 */
56 char buf_sbout[512];
57 /**
48 * stdout fcgi streambuf. 58 * stdout fcgi streambuf.
49 */ 59 */
50 fcgi_streambuf sbout; 60 fcgi_streambuf sbout;
51 /** 61 /**
62 * buffer for sberr
63 * @see sberr
64 */
65 char buf_sberr[512];
66 /**
52 * stderr fcgi streambuf. 67 * stderr fcgi streambuf.
53 */ 68 */
54 fcgi_streambuf sberr; 69 fcgi_streambuf sberr;
55 /** 70 /**
56 * stdin istream. 71 * stdin istream.
57 */ 72 */
58 istream sin; 73 istream sin;
59 /** 74 /**
60 * stdout ostream. 75 * stdout ostream.
61 */ 76 */
62 ostream sout; 77 ostream sout;
63 /** 78 /**
64 * stderr ostream. 79 * stderr ostream.
65 */ 80 */
66 ostream serr; 81 ostream serr;
67 /** 82 /**
68 * The FCGI request. 83 * The FCGI request.
69 */ 84 */
70 FCGX_Request request; 85 FCGX_Request request;
71 86
72 /** 87 /**
73 * @param s the socked used for interfacing with the server. 88 * @param s the socked used for interfacing with the server.
74 * @param f the request flags (e.g. FCGI_FAIL_ON_INTR). 89 * @param f the request flags (e.g. FCGI_FAIL_ON_INTR).
75 */ 90 */
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 {
16 _initialized = true; 16 _initialized = true;
17 } 17 }
18 sock = FCGX_OpenSocket(s,bl); 18 sock = FCGX_OpenSocket(s,bl);
19 if(sock<0) 19 if(sock<0)
20 throw exception(CODEPOINT,"failed to FCGX_OpenSocket("); 20 throw exception(CODEPOINT,"failed to FCGX_OpenSocket(");
21 // TODO: check if there is a ':', not if it starts with ':' 21 // TODO: check if there is a ':', not if it starts with ':'
22 if(*s != ':') 22 if(*s != ':')
23 if(chmod(s,0777)) // XXX: configurable. 23 if(chmod(s,0777)) // XXX: configurable.
24 throw exception(CODEPOINT,"failed to chmod()"); 24 throw exception(CODEPOINT,"failed to chmod()");
25 } 25 }
26 fcgi_socket::fcgi_socket(int s) 26 fcgi_socket::fcgi_socket(int s)
27 : sock(0) { 27 : sock(0) {
28 if(!_initialized) { 28 if(!_initialized) {
29 if( FCGX_Init() ) 29 if( FCGX_Init() )
30 throw exception(CODEPOINT,"failed to FCGX_Init()"); 30 throw exception(CODEPOINT,"failed to FCGX_Init()");
31 _initialized = true; 31 _initialized = true;
32 } 32 }
33 } 33 }
34 fcgi_socket::~fcgi_socket() { 34 fcgi_socket::~fcgi_socket() {
35 if(sock>=0) 35 if(sock>=0)
36 close(sock); 36 close(sock);
37 } 37 }
38 38
39 fcgi_interface::fcgi_interface(fcgi_socket& s,int f) 39 fcgi_interface::fcgi_interface(fcgi_socket& s,int f)
40 : sin(&sbin), sout(&sbout), serr(&sberr) { 40 : sbin(buf_sbin,sizeof(buf_sbin)),
41 sbout(buf_sbout,sizeof(buf_sbout)),
42 sberr(buf_sberr,sizeof(buf_sberr)),
43 sin(&sbin), sout(&sbout), serr(&sberr) {
41 if( FCGX_InitRequest(&request,s.sock,f) ) 44 if( FCGX_InitRequest(&request,s.sock,f) )
42 throw exception(CODEPOINT,"failed to FCGX_InitRequest()"); 45 throw exception(CODEPOINT,"failed to FCGX_InitRequest()");
43 if( FCGX_Accept_r(&request) ) 46 if( FCGX_Accept_r(&request) )
44 throw exception(CODEPOINT,"failed to FCGX_Accept_r()"); 47 throw exception(CODEPOINT,"failed to FCGX_Accept_r()");
45 sbin.attach(request.in); 48 sbin.attach(request.in);
46 sbout.attach(request.out); 49 sbout.attach(request.out);
47 sberr.attach(request.err); 50 sberr.attach(request.err);
48 for(char **p = request.envp; *p; p++) { 51 for(char **p = request.envp; *p; p++) {
49 const char *e = strchr(*p,'='); 52 const char *e = strchr(*p,'=');
50 if(!e){ 53 if(!e){
51 // XXX: check if we have it already? 54 // XXX: check if we have it already?
52 metavars[*p] = string(0); 55 metavars[*p] = string(0);
53 }else{ 56 }else{
54 int l = e-*p; e++; 57 int l = e-*p; e++;
55 // XXX: check if we have it already? 58 // XXX: check if we have it already?
56 metavars[string(*p,l)]=e; 59 metavars[string(*p,l)]=e;
57 } 60 }
58 } 61 }
59 } 62 }
60 fcgi_interface::~fcgi_interface() { 63 fcgi_interface::~fcgi_interface() {
61 sout.flush(); 64 sout.flush();
62 serr.flush(); 65 serr.flush();
63 FCGX_Finish_r(&request); 66 FCGX_Finish_r(&request);
64 } 67 }