// g++ FcgiFrontEndTest1.C FcgiFrontEnd.C ../shared/MiscSupport.C // This is similar to FcgiFrontEndTest1.C but I'm trying to check for multiple connections at the same time. #include #include #include #include #include #include #include #include #include #include "FcgiFrontEnd.h" //static std::fstream logFile; static std::ostream &logFile = std::cout; static int externalSocket; static FcgiFrontEnd *frontEnd; class MyActions : public FcgiExternalActions { public: void newResponderRequest(FcgiRequestId id, PropertyList const ¶ms, std::string stdin); void abort(FcgiRequestId id); void assertionFailed(std::string message); void debugInformation(std::string message); void sendBytes(std::string); }; bool checkInput() { char buffer[1024]; ssize_t result = read(externalSocket, buffer, 1024); if (result < 0) { if (errno == EAGAIN) { logFile<<"No input available.\n"; } else { logFile<<"unexpected error in input "<bytesReceived(std::string(buffer, result)); } return true; } void MyActions::newResponderRequest(FcgiRequestId id, PropertyList const ¶ms, std::string stdin) { logFile<<"newResponderRequest id="<setHeader(id, "Content-Type", "text/plain"); for (PropertyList::const_iterator it = params.begin(); it != params.end(); it++) { frontEnd->sendBody(id, it->first + " => " + it->second + ", "); if (!checkInput()) { // This idea is correct, but it's not enough. When we see an eof on // the socket, we need to stop sending any output to the socket. // That's not just the line below, but the standard end of message // stuff. break; } sleep(1); } frontEnd->sendBody(id, "=================================\r\n"); frontEnd->close(id, 0); logFile.flush(); } void MyActions::abort(FcgiRequestId id) { logFile<<"abort requested, id="<sendBody(id, "Aborted on user request.\r\n"); frontEnd->close(id, 0); } void MyActions::assertionFailed(std::string message) { logFile<<"assertion failed: "< 0) { ssize_t result = write(externalSocket, start, remaining); if (result < 0) { logFile<bytesReceived(std::string(buffer, result)); } } close(externalSocket); } }