From 15477e84b7bbeccbb218be71fefba7bf9a10db3c Mon Sep 17 00:00:00 2001 From: Dave Schuyler Date: Wed, 17 Apr 2002 01:04:49 +0000 Subject: [PATCH] *** empty log message *** --- direct/src/directd/directd.cxx | 28 ++++++++------------- direct/src/directd/directd.h | 45 ++++++++++++++++++++++++++++------ 2 files changed, 48 insertions(+), 25 deletions(-) diff --git a/direct/src/directd/directd.cxx b/direct/src/directd/directd.cxx index 6cfca2db99..37131eab6e 100644 --- a/direct/src/directd/directd.cxx +++ b/direct/src/directd/directd.cxx @@ -122,7 +122,7 @@ namespace { CloseHandle(pi.hProcess); CloseHandle(pi.hThread); } else { - cerr<<"CreateProcess failed: "<get_address().get_port(); } 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 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()) { - nout << "Cannot grab port " << _port << ".\n"; + nout << "Cannot grab port " << port << ".\n"; exit(1); } - nout << "Listening for connections on port " << _port << "\n"; + nout << "Listening for connections on port " << port << "\n"; _listener.add_connection(rendezvous); } diff --git a/direct/src/directd/directd.h b/direct/src/directd/directd.h index e477c9cfb2..0d0ae16828 100644 --- a/direct/src/directd/directd.h +++ b/direct/src/directd/directd.h @@ -39,8 +39,29 @@ typedef int intptr_t; // // Start a directd client on the controlling machine or // 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. +// +// 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 { PUBLISHED: DirectD(); @@ -58,6 +79,9 @@ PUBLISHED: // import ShowbaseGlobal is nearly finished. // cmd: a cli command that will be executed on the remote // 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); // Description: Call this function from the client after @@ -66,6 +90,8 @@ PUBLISHED: // Call listen_to(port) prior to calling // wait_for_servers() (or better yet, prior // to calling client_ready()). + // + // timeout_ms defaults to two minutes. bool wait_for_servers(int count, int timeout_ms=2*60*1000); // Description: Call this function from the server when @@ -73,16 +99,23 @@ PUBLISHED: int server_ready(const string& client_host, int port); // 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); - // Description: process command string. + // Description: Send the same command string to all current + // connections. void send_command(const string& cmd); protected: - void spawn_background_server(); void start_app(const string& cmd); void kill_app(); virtual void handle_command(const string& cmd); @@ -95,8 +128,6 @@ protected: ConnectionWriter _writer; QueuedConnectionListener _listener; - string _host_name; - int _port; intptr_t _app_pid; typedef pset< PT(Connection) > ConnectionSet; ConnectionSet _connections;