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

View File

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

View File

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

View File

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

View File

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