*** empty log message ***

This commit is contained in:
Dave Schuyler 2002-04-17 01:04:49 +00:00
parent fa097c6a18
commit 15477e84b7
2 changed files with 48 additions and 25 deletions

View File

@ -122,7 +122,7 @@ namespace {
CloseHandle(pi.hProcess); CloseHandle(pi.hProcess);
CloseHandle(pi.hThread); CloseHandle(pi.hThread);
} else { } else {
cerr<<"CreateProcess failed: "<<cmd<<endl; nout<<"CreateProcess failed: "<<cmd<<endl;
} }
return pid; return pid;
} }
@ -131,8 +131,7 @@ namespace {
DirectD::DirectD() : DirectD::DirectD() :
_host_name("localhost"), _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),
_shutdown(false) { _shutdown(false) {
} }
@ -144,7 +143,6 @@ DirectD::~DirectD() {
_cm.close_connection((*ci)); _cm.close_connection((*ci));
} }
_connections.clear(); _connections.clear();
cerr<<"DirectD dtor"<<endl;
} }
int int
@ -182,7 +180,7 @@ DirectD::wait_for_servers(int count, int timeout_ms) {
//handle_datagram(datagram); //handle_datagram(datagram);
DatagramIterator di(datagram); DatagramIterator di(datagram);
string s=di.get_string(); string s=di.get_string();
cerr<<"wait_for_servers() count="<<count<<", s="<<s<<endl; nout<<"wait_for_servers() count="<<count<<", s="<<s<<endl;
if (s=="r" && !--count) { if (s=="r" && !--count) {
return true; return true;
} }
@ -214,7 +212,7 @@ DirectD::start_app(const string& cmd) {
void void
DirectD::kill_app() { DirectD::kill_app() {
if (_app_pid) { if (_app_pid) {
cerr<<"trying k "<<_app_pid<<endl; nout<<"trying kill "<<_app_pid<<endl;
TerminateApp(_app_pid, 1000); TerminateApp(_app_pid, 1000);
} }
} }
@ -274,7 +272,7 @@ DirectD::send_one_message(const string& host_name,
_cm.close_connection(c); _cm.close_connection(c);
} }
void int
DirectD::connect_to(const string& host_name, int port) { DirectD::connect_to(const string& host_name, int port) {
NetAddress host; NetAddress host;
if (!host.set_host(host_name, port)) { if (!host.set_host(host_name, port)) {
@ -285,7 +283,7 @@ DirectD::connect_to(const string& host_name, int port) {
PT(Connection) c = _cm.open_TCP_client_connection(host, timeout_ms); PT(Connection) c = _cm.open_TCP_client_connection(host, timeout_ms);
if (c.is_null()) { if (c.is_null()) {
nout << "No connection.\n"; nout << "No connection.\n";
return; return 0;
} }
nout << "Successfully opened TCP connection to " << host_name nout << "Successfully opened TCP connection to " << host_name
@ -295,6 +293,7 @@ DirectD::connect_to(const string& host_name, int port) {
_reader.add_connection(c); _reader.add_connection(c);
_connections.insert(c); _connections.insert(c);
return c->get_address().get_port();
} }
void void
@ -338,21 +337,14 @@ DirectD::check_for_datagrams(){
} }
} }
void
DirectD::spawn_background_server() {
stringstream ss;
ss<<"directd -s "<<_host_name.c_str()<<" "<<_port;
DWORD serverPID = StartApp(ss.str());
}
void void
DirectD::listen_to(int port, int backlog) { DirectD::listen_to(int port, int backlog) {
PT(Connection) rendezvous = _cm.open_TCP_server_rendezvous(_port, backlog); PT(Connection) rendezvous = _cm.open_TCP_server_rendezvous(port, backlog);
if (rendezvous.is_null()) { if (rendezvous.is_null()) {
nout << "Cannot grab port " << _port << ".\n"; nout << "Cannot grab port " << port << ".\n";
exit(1); exit(1);
} }
nout << "Listening for connections on port " << _port << "\n"; nout << "Listening for connections on port " << port << "\n";
_listener.add_connection(rendezvous); _listener.add_connection(rendezvous);
} }

View File

@ -39,8 +39,29 @@ typedef int intptr_t;
// //
// Start a directd client on the controlling machine or // Start a directd client on the controlling machine or
// import ShowBaseGlobal with the xxxxx flag in your // import ShowBaseGlobal with the xxxxx flag in your
// Configrc. The client will connact each of the servers // Configrc. The client will connect each of the servers
// in the xxxxx list in your Configrc. // in the xxxxx list in your Configrc.
//
// There are two API groups in this class, they are:
//
// listen_to()
// client_ready()
// wait_for_servers()
// server_ready()
//
// and:
//
// connect_to()
// send_command()
// disconnect_from()
//
// The second group was from a more general implementation
// of DirectD. The first group summarizes the main intents
// of DirectD.
// Both groups are presented in order chronologically by their
// intended usage.
// The first group will probably provide everthing needed for
// DirectD.
class EXPCL_DIRECT DirectD { class EXPCL_DIRECT DirectD {
PUBLISHED: PUBLISHED:
DirectD(); DirectD();
@ -58,6 +79,9 @@ PUBLISHED:
// import ShowbaseGlobal is nearly finished. // import ShowbaseGlobal is nearly finished.
// cmd: a cli command that will be executed on the remote // cmd: a cli command that will be executed on the remote
// machine. // machine.
// A new connection will be created and closed. If you
// want to send more than one command, you should use
// connect_to(), send_command(), and disconnect_from().
int client_ready(const string& client_host, int port, const string& cmd); 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
@ -66,6 +90,8 @@ 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()).
//
// timeout_ms defaults to two minutes.
bool wait_for_servers(int count, int timeout_ms=2*60*1000); 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
@ -73,16 +99,23 @@ PUBLISHED:
int server_ready(const string& client_host, int port); int server_ready(const string& client_host, int port);
// Description: Call connect_to from client for each server. // Description: Call connect_to from client for each server.
void connect_to(const string& server_host, int port); // returns the port number of the connection (which
// is different from the rendezvous port used in the
// second argument). The return value can be used
// for the port arguemnt in disconnect_from().
int connect_to(const string& server_host, int port);
// Description: // Description: This is the counterpart to connect_to(). Pass
// the same server_host as for connect_to(), but pass
// the return value from connect_to() for the port,
// not the port passed to connect_to().
void disconnect_from(const string& server_host, int port); void disconnect_from(const string& server_host, int port);
// Description: process command string. // Description: Send the same command string to all current
// connections.
void send_command(const string& cmd); void send_command(const string& cmd);
protected: protected:
void spawn_background_server();
void start_app(const string& cmd); void start_app(const string& cmd);
void kill_app(); void kill_app();
virtual void handle_command(const string& cmd); virtual void handle_command(const string& cmd);
@ -95,8 +128,6 @@ protected:
ConnectionWriter _writer; ConnectionWriter _writer;
QueuedConnectionListener _listener; QueuedConnectionListener _listener;
string _host_name;
int _port;
intptr_t _app_pid; intptr_t _app_pid;
typedef pset< PT(Connection) > ConnectionSet; typedef pset< PT(Connection) > ConnectionSet;
ConnectionSet _connections; ConnectionSet _connections;