-rw-r--r-- | src/fastcgi.cc | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/src/fastcgi.cc b/src/fastcgi.cc index 6285370..8b7668c 100644 --- a/src/fastcgi.cc +++ b/src/fastcgi.cc | |||
@@ -1,66 +1,69 @@ | |||
1 | #include <unistd.h> | 1 | #include <unistd.h> |
2 | #include <sys/types.h> | 2 | #include <sys/types.h> |
3 | #include <sys/stat.h> | 3 | #include <sys/stat.h> |
4 | #include "kingate/fastcgi.h" | 4 | #include "kingate/fastcgi.h" |
5 | #include "kingate/exception.h" | 5 | #include "kingate/exception.h" |
6 | 6 | ||
7 | namespace kingate { | 7 | namespace kingate { |
8 | 8 | ||
9 | bool fcgi_socket::_initialized = false; | 9 | bool fcgi_socket::_initialized = false; |
10 | 10 | ||
11 | fcgi_socket::fcgi_socket(const char *s,int bl) | 11 | fcgi_socket::fcgi_socket(const char *s,int bl) |
12 | : sock(-1) { | 12 | : sock(-1) { |
13 | if(!_initialized) { | 13 | if(!_initialized) { |
14 | if( FCGX_Init() ) | 14 | if( FCGX_Init() ) |
15 | throw exception(CODEPOINT,"failed to FCGX_Init()"); | 15 | throw exception(CODEPOINT,"failed to FCGX_Init()"); |
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 | } |
65 | 68 | ||
66 | } | 69 | } |