34 #include <sys/types.h>
35 #include <sys/socket.h>
44 using std::ostringstream;
71 cerr <<
"Unable to determine method to handle clients, "
72 <<
"single or multiple as defined by BES.ProcessManagerMethod" <<
": " << e.
get_message() << endl;
75 if (_method !=
"multiple" && _method !=
"single") {
76 cerr <<
"Unable to determine method to handle clients, "
77 <<
"single or multiple as defined by BES.ProcessManagerMethod" << endl;
91 if (_method ==
"single") {
103 if ((pid = fork()) < 0) {
104 string error(
"fork error");
105 const char* error_info = strerror(errno);
106 if (error_info) error +=
" " + (string) error_info;
122 if( ( pid1 = fork() ) < 0 )
126 kill( main_process, 9 );
127 perror(
"fork error" );
128 exit( SERVER_EXIT_CHILD_SUBPROCESS_ABNORMAL_TERMINATION );
139 exit( SERVER_EXIT_CHILD_SUBPROCESS_NORMAL_TERMINATION );
141 if( waitpid( pid, NULL, 0 ) != pid )
144 string error(
"waitpid error" );
145 const char *error_info = strerror( errno );
147 error +=
" " + (string)error_info;
160 string from = strm.str();
162 map<string, string> extensions;
174 done = c->
receive(extensions, &ss);
178 if (extensions[
"status"] == c->
exit()) {
187 BESDEBUG(
"beslistener",
"BESServerHandler::execute() - Received PPT_EXIT_NOW in an extension chunk." << endl);
193 BESDEBUG(
"beslistener",
"BESServerHandler::execute() - Closing client connection." << endl);
197 BESDEBUG(
"beslistener",
"BESServerHandler::execute() - Client connection has been closed." << endl);
199 BESDEBUG(
"beslistener",
"BESServerHandler::execute() - Calling exit(CHILD_SUBPROCESS_READY) which has a value of "
210 string cmd_str = ss.str();
211 BESDEBUG(
"server2",
"BESServerHandler::execute - command = " << cmd_str << endl);
212 BESDEBUG(
"server",
"BESServerHandler::execute - command ... " << endl);
225 std::streambuf *holder;
226 holder = cout.rdbuf();
230 int status = cmd.execute_request(from);
237 BESDEBUG(
"server",
"BESServerHandler::execute - " <<
"executed successfully" << endl);
241 if( sw && sw->
stop() )
244 "BESServerHandler::execute - executed in "
245 << sw->
seconds() <<
" seconds and "
251 BESDEBUG(
"timing",
"BESServerHandler::execute - "
252 <<
"no timing available" << endl );
259 BESDEBUG(
"server",
"BESServerHandler::execute - "
260 <<
"error occurred" << endl );
267 map<string,string> extensions;
268 extensions[
"status"] =
"error";
271 extensions[
"exit"] =
"true";
277 cmd.finish_with_error( status );
283 cout.rdbuf( holder );
293 cout <<
"BES server " << getpid()
294 <<
": Status not OK, dispatcher returned value "
300 BESDEBUG(
"beslistener",
"BES Internal Fatal Error");
302 *(
BESLog::TheLog()) <<
"beslistener: BES Internal Fatal Error; child returning "
332 strm <<
BESIndent::LMarg <<
"BESServerHandler::dump - (" << (
void *)
this <<
")" << endl;
#define BES_SYNTAX_USER_ERROR
#define SERVER_EXIT_FATAL_CANNOT_START
#define BESISDEBUG(x)
macro used to determine if the specified debug context is set
exception thrown if inernal error encountered
#define BES_INTERNAL_ERROR
virtual int microseconds()
virtual void sendExtensions(map< string, string > &extensions)=0
virtual void closeConnection()=0
#define BES_FORBIDDEN_ERROR
virtual string get_message()
get the error message for this exception
#define SERVER_EXIT_ABNORMAL_TERMINATION
Abstract exception class for the BES with basic string message.
virtual void handle(Connection *c)
virtual unsigned int getSendChunkSize()=0
static ostream & LMarg(ostream &strm)
#define BES_INTERNAL_FATAL_ERROR
virtual void dump(ostream &strm) const
dumps information about this object
#define CHILD_SUBPROCESS_READY
Entry point into BES using xml document requests.
virtual int getSocketDescriptor()
void get_value(const string &s, string &val, bool &found)
Retrieve the value of a given key, if set.
#define BES_NOT_FOUND_ERROR
#define BESDEBUG(x, y)
macro used to send debug information to the debug stream
virtual Socket * getSocket()
static BESKeys * TheKeys()
virtual bool receive(map< string, string > &extensions, ostream *strm=0)=0