34 #include <sys/types.h> 35 #include <sys/socket.h> 44 using std::ostringstream;
50 #include "BESServerHandler.h" 51 #include "Connection.h" 53 #include "BESXMLInterface.h" 54 #include "TheBESKeys.h" 55 #include "BESInternalError.h" 56 #include "ServerExitConditions.h" 58 #include "PPTStreamBuf.h" 59 #include "PPTProtocol.h" 62 #include "BESStopWatch.h" 64 BESServerHandler::BESServerHandler()
71 cerr <<
"Unable to determine method to handle clients, " 72 <<
"single or multiple as defined by BES.ProcessManagerMethod" <<
": " << e.
get_message() << endl;
73 exit(SERVER_EXIT_FATAL_CANNOT_START);
76 if (_method !=
"multiple" && _method !=
"single") {
77 cerr <<
"Unable to determine method to handle clients, " 78 <<
"single or multiple as defined by BES.ProcessManagerMethod" << endl;
79 exit(SERVER_EXIT_FATAL_CANNOT_START);
92 if (_method ==
"single") {
104 if ((pid = fork()) < 0) {
105 string error(
"fork error");
106 const char* error_info = strerror(errno);
107 if (error_info) error +=
" " + (string) error_info;
121 strm <<
"ip " << c->getSocket()->getIp() <<
", port " << c->getSocket()->getPort();
122 string from = strm.str();
124 map<string, string> extensions;
136 done = c->receive(extensions, &ss);
140 if (extensions[
"status"] == c->exit()) {
149 BESDEBUG(
"beslistener",
150 "BESServerHandler::execute() - Received PPT_EXIT_NOW in an extension chunk." << endl);
156 c->closeConnection();
158 BESDEBUG(
"beslistener",
159 "BESServerHandler::execute() - Calling exit(CHILD_SUBPROCESS_READY) which has a value of " << CHILD_SUBPROCESS_READY << endl);
161 exit(CHILD_SUBPROCESS_READY);
169 string cmd_str = ss.str();
171 BESDEBUG(
"server",
"BESServerHandler::execute - command ... " << cmd_str << endl);
174 if (BESISDEBUG(TIMING_LOG)) sw.
start(
"BESServerHandler::execute");
178 int descript = c->getSocket()->getSocketDescriptor();
179 unsigned int bufsize = c->getSendChunkSize();
181 std::streambuf *holder;
182 holder = cout.rdbuf();
186 int status = cmd.execute_request(from);
195 BESDEBUG(
"server",
"BESServerHandler::execute - " <<
"error occurred" << endl);
202 map<string, string> extensions;
203 extensions[
"status"] =
"error";
204 if (status == BES_INTERNAL_FATAL_ERROR) {
205 extensions[
"exit"] =
"true";
207 c->sendExtensions(extensions);
211 cmd.finish_with_error(status);
222 case BES_INTERNAL_FATAL_ERROR:
223 LOG(
"BES Internal Fatal Error; child returning " 224 << SERVER_EXIT_ABNORMAL_TERMINATION <<
" to the master listener." << endl);
226 c->closeConnection();
227 exit(SERVER_EXIT_ABNORMAL_TERMINATION);
233 case BES_INTERNAL_ERROR:
234 LOG(
"BES Internal Error" << endl);
237 case BES_SYNTAX_USER_ERROR:
238 LOG(
"BES User Syntax Error" << endl);
241 case BES_FORBIDDEN_ERROR:
242 LOG(
"BES Forbidden Error" << endl);
245 case BES_NOT_FOUND_ERROR:
246 LOG(
"BES Not Found Error" << endl);
250 LOG(
"Unrecognized BES Error" << endl);
256 c->closeConnection();
267 strm << BESIndent::LMarg <<
"BESServerHandler::dump - (" << (
void *)
this <<
")" << endl;
269 strm << BESIndent::LMarg <<
"server method: " << _method << endl;
270 BESIndent::UnIndent();
exception thrown if inernal error encountered
virtual std::string get_message()
get the error message for this exception
void get_value(const string &s, string &val, bool &found)
Retrieve the value of a given key, if set.
virtual bool start(string name)
Abstract exception class for the BES with basic string message.
static TheBESKeys * TheKeys()
virtual void dump(ostream &strm) const
dumps information about this object
Entry point into BES using xml document requests.