diff --git a/direct/src/directd/directd.cxx b/direct/src/directd/directd.cxx index 075d92b28f..5d0ebe601f 100644 --- a/direct/src/directd/directd.cxx +++ b/direct/src/directd/directd.cxx @@ -131,7 +131,6 @@ namespace { DirectD::DirectD() : - _app_pid(0), _reader(&_cm, 1), _writer(&_cm, 0), _listener(&_cm, 0), _shutdown(false) { } @@ -143,6 +142,8 @@ DirectD::~DirectD() { _cm.close_connection((*ci)); } _connections.clear(); + + kill_all(); } int @@ -211,16 +212,29 @@ DirectD::server_ready(const string& client_host, int port) { void DirectD::start_app(const string& cmd) { nout<<"start_app(cmd="<]" Kill the most recent application + // started with client_ready() or "!". + // Or kill the nth most recent or 'a' for All. + // E.g. "k", "k0", "k2", "ka". + // "q" Tell the server to quit. + // "!cmd" Exectue the cmd on the server (this + // is a dos shell command; if you want + // a bash command, include bash in the + // command e.g. "!bash pwd"). When you call + // client_ready(), it prefixes "!" for you. // A new connection will be created and closed. int tell_server(const string& server_host, int port, const string& cmd); @@ -129,7 +132,8 @@ PUBLISHED: protected: void start_app(const string& cmd); - void kill_app(); + void kill_app(int index); + void kill_all(); virtual void handle_command(const string& cmd); void handle_datagram(NetDatagram& datagram); void send_one_message(const string& host_name, @@ -140,7 +144,8 @@ protected: ConnectionWriter _writer; QueuedConnectionListener _listener; - intptr_t _app_pid; + typedef pvector< long /*intptr_t*/ > PidStack; + PidStack _pids; typedef pset< PT(Connection) > ConnectionSet; ConnectionSet _connections; diff --git a/direct/src/directdServer/directdClient.cxx b/direct/src/directdServer/directdClient.cxx index 05d4e5ac5a..f1a4b55b44 100644 --- a/direct/src/directdServer/directdClient.cxx +++ b/direct/src/directdServer/directdClient.cxx @@ -84,7 +84,7 @@ main(int argc, char *argv[]) { port=(atoi(argv[argc-1])); } DirectDClient directd; - directd.run_client(port); + directd.run_client(host, port); return 0; } diff --git a/direct/src/directdServer/directdClient.h b/direct/src/directdServer/directdClient.h index c3011a6ca6..144e2ed606 100644 --- a/direct/src/directdServer/directdClient.h +++ b/direct/src/directdServer/directdClient.h @@ -19,7 +19,7 @@ #include "directd.h" // Description: DirectDClient is a test app for DriectDServer. -class EXPCL_DIRECT DirectDClient: public DirectD { +class DirectDClient: public DirectD { public: DirectDClient(); ~DirectDClient(); diff --git a/direct/src/directdServer/directdServer.cxx b/direct/src/directdServer/directdServer.cxx index 208de9f293..74130e1e99 100644 --- a/direct/src/directdServer/directdServer.cxx +++ b/direct/src/directdServer/directdServer.cxx @@ -30,7 +30,7 @@ DirectDServer::handle_command(const string& cmd) { if (cmd.size()==1) { switch (cmd[0]) { case 'k': - kill_app(); + kill_app(0); break; case 'q': _shutdown=true; @@ -41,6 +41,14 @@ DirectDServer::handle_command(const string& cmd) { } } else { switch (cmd[0]) { + case 'k': + if (cmd[1]=='a') { + kill_all(); + } else { + int index = atoi(cmd.substr(1, string::npos).c_str()); + kill_app(index); + } + break; case '!': { string c=cmd.substr(1, string::npos); //read_command(c);