34 #include <sys/types.h>
35 #include <sys/socket.h>
45 using std::ostringstream ;
74 cerr <<
"Unable to determine method to handle clients, "
75 <<
"single or multiple as defined by BES.ProcessManagerMethod"
79 if( _method !=
"multiple" && _method !=
"single" )
81 cerr <<
"Unable to determine method to handle clients, "
82 <<
"single or multiple as defined by BES.ProcessManagerMethod"
97 if (_method ==
"single")
111 if ((pid = fork()) < 0)
113 string error(
"fork error");
114 const char* error_info = strerror(errno);
116 error +=
" " + (string) error_info;
133 if( ( pid1 = fork() ) < 0 )
137 kill( main_process, 9 );
138 perror(
"fork error" );
139 exit( SERVER_EXIT_CHILD_SUBPROCESS_ABNORMAL_TERMINATION );
150 exit( SERVER_EXIT_CHILD_SUBPROCESS_NORMAL_TERMINATION );
152 if( waitpid( pid, NULL, 0 ) != pid )
155 string error(
"waitpid error" );
156 const char *error_info = strerror( errno );
158 error +=
" " + (string)error_info;
172 string from = strm.str() ;
174 map<string,string> extensions ;
187 done = c->
receive( extensions, &ss ) ;
191 if( extensions[
"status"] == c->
exit() )
202 string cmd_str = ss.str() ;
203 BESDEBUG(
"server",
"BESServerHandler::execute - command = "
204 << cmd_str << endl ) ;
217 std::streambuf *holder ;
218 holder = cout.rdbuf() ;
222 int status = cmd.execute_request( from ) ;
228 cout.rdbuf( holder ) ;
230 BESDEBUG(
"server",
"BESServerHandler::execute - "
231 <<
"executed successfully" << endl ) ;
235 if( sw && sw->
stop() )
238 "BESServerHandler::execute - executed in "
239 << sw->
seconds() <<
" seconds and "
245 BESDEBUG(
"timing",
"BESServerHandler::execute - "
246 <<
"no timing available" << endl ) ;
253 BESDEBUG(
"server",
"BESServerHandler::execute - "
254 <<
"error occurred" << endl ) ;
261 map<string,string> extensions ;
262 extensions[
"status"] =
"error" ;
265 extensions[
"exit"] =
"true" ;
271 cmd.finish_with_error( status ) ;
277 cout.rdbuf( holder ) ;
285 cout <<
"BES server " << getpid()
286 <<
": Status not OK, dispatcher returned value "
317 << (
void *)
this <<
")" << endl ;
#define BES_SYNTAX_USER_ERROR
#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
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 SERVER_EXIT_FATAL_CAN_NOT_START
#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