mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-03 02:15:43 -04:00
added kill all; fixed test client
This commit is contained in:
parent
9ea3af0608
commit
f43c59c642
@ -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="<<cmd<<")"<<endl;
|
||||
_app_pid=StartApp(cmd);
|
||||
nout<<" _app_pid="<<_app_pid<<endl;
|
||||
_pids.push_back(StartApp(cmd));
|
||||
nout<<" pid="<<_pids.back()<<endl;
|
||||
}
|
||||
|
||||
void
|
||||
DirectD::kill_app() {
|
||||
if (_app_pid) {
|
||||
nout<<"trying kill "<<_app_pid<<endl;
|
||||
TerminateApp(_app_pid, 1000);
|
||||
DirectD::kill_app(int index) {
|
||||
int i = _pids.size() - 1 - index % _pids.size();
|
||||
PidStack::iterator pi = _pids.begin() + i;
|
||||
if (pi!=_pids.end()) {
|
||||
nout<<"trying kill "<<(*pi)<<endl;
|
||||
TerminateApp((*pi), 1000);
|
||||
_pids.erase(pi);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
DirectD::kill_all() {
|
||||
PidStack::reverse_iterator pi;
|
||||
for (pi = _pids.rbegin(); pi != _pids.rend(); ++pi) {
|
||||
nout<<"trying kill "<<(*pi)<<endl;
|
||||
TerminateApp((*pi), 1000);
|
||||
}
|
||||
_pids.clear();
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -86,13 +86,16 @@ PUBLISHED:
|
||||
|
||||
// Description: Tell the server to do the command cmd.
|
||||
// cmd is one of the following:
|
||||
// "k" Kill the most recent application started with
|
||||
// client_ready() or "!".
|
||||
// "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.
|
||||
// "k[<n>]" 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;
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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();
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user