36 #include <sys/types.h>
37 #include <sys/socket.h>
47 #include "BESServerHandler.h"
48 #include "Connection.h"
50 #include "BESXMLInterface.h"
51 #include "TheBESKeys.h"
52 #include "BESInternalError.h"
53 #include "ServerExitConditions.h"
55 #include "PPTStreamBuf.h"
56 #include "PPTProtocol.h"
59 #include "BESStopWatch.h"
61 using std::ostringstream;
73 #define EXIT_ON_INTERNAL_ERROR "BES.ExitOnInternalError"
75 BESServerHandler::BESServerHandler()
82 cerr <<
"Unable to determine method to handle clients, "
83 <<
"single or multiple as defined by BES.ProcessManagerMethod" <<
": " << e.
get_message() << endl;
84 exit(SERVER_EXIT_FATAL_CANNOT_START);
87 if (_method !=
"multiple" && _method !=
"single") {
88 cerr <<
"Unable to determine method to handle clients, "
89 <<
"single or multiple as defined by BES.ProcessManagerMethod" << endl;
90 exit(SERVER_EXIT_FATAL_CANNOT_START);
103 if (_method ==
"single") {
115 if ((pid = fork()) < 0) {
116 string error(
"fork error");
117 const char* error_info = strerror(errno);
118 if (error_info) error +=
" " + (string) error_info;
132 strm <<
"ip " << c->getSocket()->getIp() <<
", port " << c->getSocket()->getPort();
133 string from = strm.str();
135 map<string, string> extensions;
147 done = c->receive(extensions, &ss);
151 if (extensions[
"status"] == c->exit()) {
160 BESDEBUG(
"beslistener",
161 "BESServerHandler::execute() - Received PPT_EXIT_NOW in an extension chunk." << endl);
167 c->closeConnection();
169 BESDEBUG(
"beslistener",
170 "BESServerHandler::execute() - Calling exit(CHILD_SUBPROCESS_READY) which has a value of " << CHILD_SUBPROCESS_READY << endl);
172 INFO_LOG(
"Received exit command." << endl);
174 exit(CHILD_SUBPROCESS_READY);
182 string cmd_str = ss.str();
184 BESDEBUG(
"server",
"BESServerHandler::execute - command ... " << cmd_str << endl);
191 int descript = c->getSocket()->getSocketDescriptor();
192 unsigned int bufsize = c->getSendChunkSize();
194 std::streambuf *holder;
195 holder = cout.rdbuf();
199 int status = cmd.execute_request(from);
207 BESDEBUG(
"server",
"BESServerHandler::execute - " <<
"error occurred" << endl);
212 map<string, string> extensions;
213 extensions[
"status"] =
"error";
214 if (status == BES_INTERNAL_FATAL_ERROR) {
215 extensions[
"exit"] =
"true";
217 c->sendExtensions(extensions);
228 case BES_INTERNAL_FATAL_ERROR:
229 ERROR_LOG(
"BES Internal Fatal Error; child returning "
230 << SERVER_EXIT_ABNORMAL_TERMINATION <<
" to the master listener." << endl);
232 c->closeConnection();
233 exit(SERVER_EXIT_ABNORMAL_TERMINATION);
237 case BES_INTERNAL_ERROR:
240 ERROR_LOG(
"BES Internal Error; child returning "
241 << SERVER_EXIT_ABNORMAL_TERMINATION <<
" to the master listener." << endl);
243 c->closeConnection();
244 exit(SERVER_EXIT_ABNORMAL_TERMINATION);
249 case BES_SYNTAX_USER_ERROR:
250 case BES_FORBIDDEN_ERROR:
251 case BES_NOT_FOUND_ERROR:
258 c->closeConnection();
269 strm << BESIndent::LMarg <<
"BESServerHandler::dump - (" << (
void *)
this <<
")" << endl;
271 strm << BESIndent::LMarg <<
"server method: " << _method << endl;
272 BESIndent::UnIndent();
static bool IsSet(const std::string &flagName)
see if the debug context flagName is set to true
Abstract exception class for the BES with basic string message.
virtual std::string get_message()
get the error message for this exception
exception thrown if internal error encountered
virtual void dump(std::ostream &strm) const
dumps information about this object
virtual bool start(std::string name)
Entry point into BES using xml document requests.
void get_value(const std::string &s, std::string &val, bool &found)
Retrieve the value of a given key, if set.
static TheBESKeys * TheKeys()