From 351446cb2fa5f69161f7331a66fb63a82dd5f3a7 Mon Sep 17 00:00:00 2001 From: Dave Schuyler Date: Mon, 15 Apr 2002 21:50:31 +0000 Subject: [PATCH] *** empty log message *** --- direct/src/directd/directd.cxx | 95 +++++++++++++++++++++++----------- direct/src/directd/directd.h | 37 ++++++++----- direct/src/directd/directd.py | 11 ++-- 3 files changed, 95 insertions(+), 48 deletions(-) diff --git a/direct/src/directd/directd.cxx b/direct/src/directd/directd.cxx index 32f38fe1a4..ddf70cf052 100644 --- a/direct/src/directd/directd.cxx +++ b/direct/src/directd/directd.cxx @@ -144,6 +144,7 @@ DirectD::~DirectD() { _cm.close_connection((*ci)); } _connections.clear(); + cerr<<"DirectD dtor"<(&s, port)); -} - -// Description: free memory and earse all elements from _servers. -void -DirectD::clear_server_list() { - ServerList::const_iterator i = _servers.begin(); - for (; i!=_servers.end(); ++i) { - string* name=(*i).first; - delete name; - } - _servers.clear(); -} - int -DirectD::connect() { - ServerList::const_iterator i = _servers; - for (; i!=_servers.end(); ++i) { - string* name=(*i).first; - int port=(*i).second; - cerr<<"connecting to "<get_address().get_ip_string()==host_name + && (*i)->get_address().get_port()==port) { + _cm.close_connection((*i)); + _reader.remove_connection((*i)); + _connections.erase(i); + break; + } + } +} + void DirectD::check_for_lost_connection() { while (_cm.reset_connection_available()) { @@ -386,8 +422,7 @@ DirectD::spawn_background_server() { } void -DirectD::listen_to(int port) { - const backlog=8; +DirectD::listen_to(int port, int backlog) { PT(Connection) rendezvous = _cm.open_TCP_server_rendezvous(_port, backlog); if (rendezvous.is_null()) { nout << "Cannot grab port " << _port << ".\n"; diff --git a/direct/src/directd/directd.h b/direct/src/directd/directd.h index 6191e0e821..5962fa2528 100644 --- a/direct/src/directd/directd.h +++ b/direct/src/directd/directd.h @@ -64,20 +64,35 @@ PUBLISHED: // Description: Call connect_to from client for each server. void connect_to(const string& server_host, int port); + // Description: + void disconnect_from(const string& server_host, int port); + // Description: Call listen_to in the server. // port is a rendezvous port. - void listen_to(int port); + // + // backlog refers to how many connections can queue up + // before you handle them. Consider setting backlog to + // the count you send to wait_for_servers(); or higher. + void listen_to(int port, int backlog=8); - // Description: - ////void disconnect() { - - // process command string. + // Description: process command string. void send_command(const string& cmd); - // Description: This function is overly named, but that's what it does. - // Call this function from the server when import ShowbaseGlobal is - // nearly finished. - int tell_client_the_server_is_ready(const string& client_host, int port); + // Description: Call this function from the client when + // import ShowbaseGlobal is nearly finished. + int client_is_ready(const string& client_host, int port); + + // Description: Call this function from the client after + // calling client_is_ready() calls. + // + // Call listen_to(port) prior to calling + // wait_for_servers() (or better yet, prior + // to calling client_is_ready()). + bool wait_for_servers(int count, int timeout_ms); + + // Description: Call this function from the server when + // import ShowbaseGlobal is nearly finished. + int server_is_ready(const string& client_host, int port); public: void set_host_name(const string& host_name); @@ -107,10 +122,6 @@ protected: string _host_name; int _port; intptr_t _app_pid; - #if 0 //[ - typedef pvector > ServerList; - ServerList _servers; - #endif //] typedef pset< PT(Connection) > ConnectionSet; ConnectionSet _connections; diff --git a/direct/src/directd/directd.py b/direct/src/directd/directd.py index e89b80dde5..a8c2bf8d7a 100755 --- a/direct/src/directd/directd.py +++ b/direct/src/directd/directd.py @@ -10,13 +10,13 @@ import DatagramIterator print "hello" -class DirectDServer: +class DirectD: notify = DirectNotifyGlobal.directNotify.newCategory("DirectD") def __init__(self): pass - def connect(self, ip, port, timeout=35000): + def connect(self, ip, port, timeout=5000): self.qcm=QueuedConnectionManager() self.tcpConn=self.qcm.openTCPClientConnection(ip, port, timeout) @@ -29,7 +29,7 @@ class DirectDServer: self.qcr=QueuedConnectionReader(self.qcm, 0) self.qcr.addConnection(self.tcpConn) self.cw=ConnectionWriter(self.qcm, 0) - while 1: + while 0: s=raw_input("send: ") d=Datagram.Datagram() d.addString(s) @@ -45,5 +45,6 @@ class DirectDServer: #self.registerForChannel(self.ourChannel) def foo(): - dds = DirectDServer() - dds.connect("127.0.0.1", 8000) + dd = DirectD() + dd.connect("127.0.0.1", 8001) + dd.connect("127.0.0.1", 8002)