*** empty log message ***

This commit is contained in:
Dave Schuyler 2002-04-16 04:11:20 +00:00
parent 08584e3487
commit fa097c6a18
5 changed files with 40 additions and 42 deletions

View File

@ -134,7 +134,7 @@ DirectD::DirectD() :
_host_name("localhost"), _host_name("localhost"),
_port(8001), _app_pid(0), _port(8001), _app_pid(0),
_reader(&_cm, 1), _writer(&_cm, 1), _listener(&_cm, 0), _reader(&_cm, 1), _writer(&_cm, 1), _listener(&_cm, 0),
_verbose(false), _shutdown(false) { _shutdown(false) {
} }
DirectD::~DirectD() { DirectD::~DirectD() {
@ -148,10 +148,11 @@ DirectD::~DirectD() {
} }
int int
DirectD::client_ready(const string& client_host, int port) { DirectD::client_ready(const string& client_host, int port,
connect_to(client_host, port); const string& cmd) {
send_command("s"); stringstream ss;
disconnect_from(client_host, port); ss<<"!"<<cmd;
send_one_message(client_host, port, ss.str());
return 0; return 0;
} }
@ -175,11 +176,9 @@ DirectD::wait_for_servers(int count, int timeout_ms) {
while (_reader.data_available()) { while (_reader.data_available()) {
NetDatagram datagram; NetDatagram datagram;
if (_reader.get_data(datagram)) { if (_reader.get_data(datagram)) {
if (_verbose) { nout << "Got datagram " /*<< datagram <<*/ "from "
nout << "Got datagram " /*<< datagram <<*/ "from " << datagram.get_address() << endl;
<< datagram.get_address() << endl; datagram.dump_hex(nout);
datagram.dump_hex(nout);
}
//handle_datagram(datagram); //handle_datagram(datagram);
DatagramIterator di(datagram); DatagramIterator di(datagram);
string s=di.get_string(); string s=di.get_string();
@ -207,7 +206,9 @@ DirectD::server_ready(const string& client_host, int port) {
void void
DirectD::start_app(const string& cmd) { DirectD::start_app(const string& cmd) {
nout<<"start_app(cmd="<<cmd<<")"<<endl;
_app_pid=StartApp(cmd); _app_pid=StartApp(cmd);
nout<<" _app_pid="<<_app_pid<<endl;
} }
void void
@ -238,9 +239,7 @@ DirectD::handle_datagram(NetDatagram& datagram){
void void
DirectD::handle_command(const string& cmd) { DirectD::handle_command(const string& cmd) {
if (_verbose) { nout<<"DirectD::handle_command: "<<cmd<<endl;
cerr<<"command: "<<cmd<<endl;
}
} }
void void
@ -331,11 +330,9 @@ DirectD::check_for_datagrams(){
while (_reader.data_available()) { while (_reader.data_available()) {
NetDatagram datagram; NetDatagram datagram;
if (_reader.get_data(datagram)) { if (_reader.get_data(datagram)) {
if (_verbose) { nout << "Got datagram " /*<< datagram <<*/ "from "
nout << "Got datagram " /*<< datagram <<*/ "from " << datagram.get_address() << endl;
<< datagram.get_address() << endl; datagram.dump_hex(nout);
datagram.dump_hex(nout);
}
handle_datagram(datagram); handle_datagram(datagram);
} }
} }
@ -355,7 +352,7 @@ DirectD::listen_to(int port, int backlog) {
nout << "Cannot grab port " << _port << ".\n"; nout << "Cannot grab port " << _port << ".\n";
exit(1); exit(1);
} }
if (_verbose) nout << "Listening for connections on port " << _port << "\n"; nout << "Listening for connections on port " << _port << "\n";
_listener.add_connection(rendezvous); _listener.add_connection(rendezvous);
} }
@ -366,7 +363,7 @@ DirectD::check_for_new_clients() {
NetAddress address; NetAddress address;
PT(Connection) new_connection; PT(Connection) new_connection;
if (_listener.get_new_connection(rv, address, new_connection)) { if (_listener.get_new_connection(rv, address, new_connection)) {
if (_verbose) nout << "Got connection from " << address << "\n"; nout << "Got connection from " << address << "\n";
_reader.add_connection(new_connection); _reader.add_connection(new_connection);
_connections.insert(new_connection); _connections.insert(new_connection);
} }

View File

@ -56,7 +56,9 @@ PUBLISHED:
// Description: Call this function from the client when // Description: Call this function from the client when
// import ShowbaseGlobal is nearly finished. // import ShowbaseGlobal is nearly finished.
int client_ready(const string& client_host, int port); // cmd: a cli command that will be executed on the remote
// machine.
int client_ready(const string& client_host, int port, const string& cmd);
// Description: Call this function from the client after // Description: Call this function from the client after
// calling <count> client_ready() calls. // calling <count> client_ready() calls.
@ -64,7 +66,7 @@ PUBLISHED:
// Call listen_to(port) prior to calling // Call listen_to(port) prior to calling
// wait_for_servers() (or better yet, prior // wait_for_servers() (or better yet, prior
// to calling client_ready()). // to calling client_ready()).
bool wait_for_servers(int count, int timeout_ms); bool wait_for_servers(int count, int timeout_ms=2*60*1000);
// Description: Call this function from the server when // Description: Call this function from the server when
// import ShowbaseGlobal is nearly finished. // import ShowbaseGlobal is nearly finished.
@ -79,16 +81,15 @@ PUBLISHED:
// Description: process command string. // Description: process command string.
void send_command(const string& cmd); void send_command(const string& cmd);
public: protected:
void spawn_background_server(); void spawn_background_server();
void start_app(const string& cmd); void start_app(const string& cmd);
void kill_app(); void kill_app();
void handle_command(const string& cmd); virtual void handle_command(const string& cmd);
void handle_datagram(NetDatagram& datagram); void handle_datagram(NetDatagram& datagram);
void send_one_message(const string& host_name, void send_one_message(const string& host_name,
int port, const string& message); int port, const string& message);
protected:
QueuedConnectionManager _cm; QueuedConnectionManager _cm;
QueuedConnectionReader _reader; QueuedConnectionReader _reader;
ConnectionWriter _writer; ConnectionWriter _writer;
@ -100,7 +101,6 @@ protected:
typedef pset< PT(Connection) > ConnectionSet; typedef pset< PT(Connection) > ConnectionSet;
ConnectionSet _connections; ConnectionSet _connections;
bool _verbose;
bool _shutdown; bool _shutdown;
void check_for_new_clients(); void check_for_new_clients();

View File

@ -49,9 +49,7 @@ DirectDClient::cli_command(const string& cmd) {
void void
DirectDClient::run_client(const string& host, int port) { DirectDClient::run_client(const string& host, int port) {
if (_verbose) { nout<<"client"<<endl;
cerr<<"client"<<endl;
}
connect_to(host, port); connect_to(host, port);

View File

@ -26,17 +26,9 @@ DirectDServer::~DirectDServer() {
void void
DirectDServer::handle_command(const string& cmd) { DirectDServer::handle_command(const string& cmd) {
if (_verbose) { nout<<"DirectDServer::handle_command: "<<cmd<<", size="<<cmd.size()<<endl;
cerr<<"command: "<<cmd<<endl;
}
if (cmd.size()==1) { if (cmd.size()==1) {
switch (cmd[0]) { switch (cmd[0]) {
case 's': {
string c;
read_command(c);
start_app(c);
}
break;
case 'k': case 'k':
kill_app(); kill_app();
break; break;
@ -45,9 +37,20 @@ DirectDServer::handle_command(const string& cmd) {
break; break;
default: default:
cerr<<"unknown command: "<<cmd<<endl; cerr<<"unknown command: "<<cmd<<endl;
break;
} }
} else { } else {
start_app(cmd); switch (cmd[0]) {
case '!': {
string c=cmd.substr(1, string::npos);
//read_command(c);
start_app(c);
}
break;
default:
start_app(cmd);
break;
}
} }
} }
@ -74,7 +77,7 @@ DirectDServer::read_command(string& cmd) {
void void
DirectDServer::run_server(int port) { DirectDServer::run_server(int port) {
if (_verbose) cerr<<"server"<<endl; nout<<"server"<<endl;
listen_to(port); listen_to(port);
@ -96,7 +99,7 @@ main(int argc, char *argv[]) {
return 1; return 1;
} }
cerr<<"directdServer"<<endl; cerr<<"directdServer "<<__DATE__<<endl;
int port=8001; int port=8001;
if (argc > 1) { if (argc > 1) {
port=(atoi(argv[argc-1])); port=(atoi(argv[argc-1]));

View File

@ -35,6 +35,6 @@ public:
protected: protected:
void read_command(string& cmd); void read_command(string& cmd);
void handle_command(const string& cmd); virtual void handle_command(const string& cmd);
}; };