mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-01 09:23:03 -04:00
now properly closes connections. client waits for server to finish before exiting.
This commit is contained in:
parent
abbbb21a8e
commit
865a04075b
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -30,7 +30,7 @@ public:
|
||||
|
||||
QueuedConnectionManager *qManager;
|
||||
QueuedConnectionReader *qReader;
|
||||
ConnectionWriter *qWriter;
|
||||
ConnectionWriter *cWriter;
|
||||
NetAddress server;
|
||||
};
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user