Go to the documentation of this file.00001 #include <fastcgi++/manager.hpp>
00002
00003
00004 Fastcgipp::ManagerPar* Fastcgipp::ManagerPar::instance=0;
00005
00006 Fastcgipp::ManagerPar::ManagerPar(int fd, const boost::function<void(Protocol::FullId, Message)>& sendMessage_): transceiver(fd, sendMessage_), asleep(false), stopBool(false), terminateBool(false) { setupSignals(); instance=this; }
00007
00008 void Fastcgipp::ManagerPar::terminate()
00009 {
00010 boost::lock_guard<boost::mutex> lock(terminateMutex);
00011 terminateBool=true;
00012 }
00013
00014 void Fastcgipp::ManagerPar::stop()
00015 {
00016 boost::lock_guard<boost::mutex> lock(stopMutex);
00017 stopBool=true;
00018 }
00019
00020 void Fastcgipp::ManagerPar::signalHandler(int signum)
00021 {
00022 switch(signum)
00023 {
00024 case SIGUSR1:
00025 {
00026 if(instance) instance->terminate();
00027 break;
00028 }
00029 case SIGTERM:
00030 {
00031 if(instance) instance->stop();
00032 break;
00033 }
00034 }
00035 }
00036
00037 void Fastcgipp::ManagerPar::setupSignals()
00038 {
00039 struct sigaction sigAction;
00040 sigAction.sa_handler=Fastcgipp::ManagerPar::signalHandler;
00041
00042 sigaction(SIGPIPE, &sigAction, NULL);
00043 sigaction(SIGUSR1, &sigAction, NULL);
00044 sigaction(SIGTERM, &sigAction, NULL);
00045 }
00046
00047 void Fastcgipp::ManagerPar::localHandler(Protocol::FullId id)
00048 {
00049 using namespace std;
00050 using namespace Protocol;
00051 Message message(messages.front());
00052 messages.pop();
00053
00054 if(!message.type)
00055 {
00056 const Header& header=*(Header*)message.data.get();
00057 switch(header.getType())
00058 {
00059 case GET_VALUES:
00060 {
00061 size_t nameSize;
00062 size_t valueSize;
00063 const char* name;
00064 const char* value;
00065 processParamHeader(message.data.get()+sizeof(Header), header.getContentLength(), name, nameSize, value, valueSize);
00066 if(nameSize==14 && !memcmp(name, "FCGI_MAX_CONNS", 14))
00067 {
00068 Block buffer(transceiver.requestWrite(sizeof(maxConnsReply)));
00069 memcpy(buffer.data, (const char*)&maxConnsReply, sizeof(maxConnsReply));
00070 transceiver.secureWrite(sizeof(maxConnsReply), id, false);
00071 }
00072 else if(nameSize==13 && !memcmp(name, "FCGI_MAX_REQS", 13))
00073 {
00074 Block buffer(transceiver.requestWrite(sizeof(maxReqsReply)));
00075 memcpy(buffer.data, (const char*)&maxReqsReply, sizeof(maxReqsReply));
00076 transceiver.secureWrite(sizeof(maxReqsReply), id, false);
00077 }
00078 else if(nameSize==15 && !memcmp(name, "FCGI_MPXS_CONNS", 15))
00079 {
00080 Block buffer(transceiver.requestWrite(sizeof(mpxsConnsReply)));
00081 memcpy(buffer.data, (const char*)&mpxsConnsReply, sizeof(mpxsConnsReply));
00082 transceiver.secureWrite(sizeof(mpxsConnsReply), id, false);
00083 }
00084
00085 break;
00086 }
00087
00088 default:
00089 {
00090 Block buffer(transceiver.requestWrite(sizeof(Header)+sizeof(UnknownType)));
00091
00092 Header& sendHeader=*(Header*)buffer.data;
00093 sendHeader.setVersion(Protocol::version);
00094 sendHeader.setType(UNKNOWN_TYPE);
00095 sendHeader.setRequestId(0);
00096 sendHeader.setContentLength(sizeof(UnknownType));
00097 sendHeader.setPaddingLength(0);
00098
00099 UnknownType& sendBody=*(UnknownType*)(buffer.data+sizeof(Header));
00100 sendBody.setType(header.getType());
00101
00102 transceiver.secureWrite(sizeof(Header)+sizeof(UnknownType), id, false);
00103
00104 break;
00105 }
00106 }
00107 }
00108 }