diff --git a/pandatool/src/mayaprogs/mayaToEgg_client.cxx b/pandatool/src/mayaprogs/mayaToEgg_client.cxx index e1bef62126..70351caa7a 100755 --- a/pandatool/src/mayaprogs/mayaToEgg_client.cxx +++ b/pandatool/src/mayaprogs/mayaToEgg_client.cxx @@ -28,7 +28,7 @@ MayaToEggClient() : { qManager = new QueuedConnectionManager(); qReader = new QueuedConnectionReader(qManager, 0); - qWriter = new ConnectionWriter(qManager, 0); + cWriter = new ConnectionWriter(qManager, 0); // We assume the server is local and on port 4242 server.set_host("localhost", 4242); } @@ -72,8 +72,18 @@ int main(int argc, char *argv[]) { nout << "sending datagram\n"; // Send it and close the connection - prog.qWriter->send(datagram, con); - prog.qManager->close_connection(con); - return 0; + prog.cWriter->send(datagram, con); + con->flush(); + while (true) { + prog.qReader->data_available(); + if (prog.qManager->reset_connection_available()) { + PT(Connection) connection; + if (prog.qManager->get_reset_connection(connection)) { + prog.qManager->close_connection(con); + return 0; + } + } + Thread::sleep(0.1); + } } diff --git a/pandatool/src/mayaprogs/mayaToEgg_client.h b/pandatool/src/mayaprogs/mayaToEgg_client.h index c116230cb9..ce43a5a5e0 100755 --- a/pandatool/src/mayaprogs/mayaToEgg_client.h +++ b/pandatool/src/mayaprogs/mayaToEgg_client.h @@ -30,7 +30,7 @@ public: QueuedConnectionManager *qManager; QueuedConnectionReader *qReader; - ConnectionWriter *qWriter; + ConnectionWriter *cWriter; NetAddress server; }; diff --git a/pandatool/src/mayaprogs/mayaToEgg_server.cxx b/pandatool/src/mayaprogs/mayaToEgg_server.cxx index 87d8d4aa24..d6dd6a207d 100755 --- a/pandatool/src/mayaprogs/mayaToEgg_server.cxx +++ b/pandatool/src/mayaprogs/mayaToEgg_server.cxx @@ -161,7 +161,9 @@ MayaToEggServer() : qManager = new QueuedConnectionManager(); qListener = new QueuedConnectionListener(qManager, 0); qReader = new QueuedConnectionReader(qManager, 0); + cWriter = new ConnectionWriter(qManager, 0); dummy = new MayaToEggConverter(); + nout << "Initializing Maya...\n"; if (!dummy->open_api()) { nout << "Unable to initialize Maya.\n"; @@ -178,6 +180,7 @@ MayaToEggServer:: delete qManager; delete qReader; delete qListener; + delete cWriter; delete dummy; } @@ -326,8 +329,22 @@ poll() { // pointer and add it to the reader list if (qListener->new_connection_available()) { PT(Connection) con; - if (qListener->get_new_connection(con)) { + PT(Connection) rv; + NetAddress address; + if (qListener->get_new_connection(rv, address, con)) { + nout << "Got connection from " << address << "\n"; qReader->add_connection(con); + _clients.insert(con); + } + } + + // Check for reset clients + if (qManager->reset_connection_available()) { + PT(Connection) connection; + if (qManager->get_reset_connection(connection)) { + nout << "Lost connection from " << connection->get_address() << "\n"; + _clients.erase(connection); + qManager->close_connection(connection); } } @@ -402,6 +419,12 @@ poll() { // Clean up the malloc'd pointer pointer free(cargv); } // qReader->get_data + nout << "Closing connection...\n"; + + Clients::iterator ci; + for (ci = _clients.begin(); ci != _clients.end(); ++ci) { + qManager->close_connection(*ci); + } } // qReader->data_available } // poll diff --git a/pandatool/src/mayaprogs/mayaToEgg_server.h b/pandatool/src/mayaprogs/mayaToEgg_server.h index 623bd8c79f..e7bd4ac027 100755 --- a/pandatool/src/mayaprogs/mayaToEgg_server.h +++ b/pandatool/src/mayaprogs/mayaToEgg_server.h @@ -21,6 +21,7 @@ #include "queuedConnectionManager.h" #include "queuedConnectionListener.h" #include "queuedConnectionReader.h" +#include "connectionWriter.h" //////////////////////////////////////////////////////////////////// // Class : MayaToEggServer @@ -39,11 +40,14 @@ public: QueuedConnectionManager *qManager; QueuedConnectionListener *qListener; QueuedConnectionReader *qReader; + ConnectionWriter *cWriter; MayaToEggConverter *dummy; protected: static bool dispatch_transform_type(const string &opt, const string &arg, void *var); + typedef pset< PT(Connection) > Clients; + Clients _clients; int _verbose; bool _polygon_output;