mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-03 10:22:45 -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();
|
qManager = new QueuedConnectionManager();
|
||||||
qReader = new QueuedConnectionReader(qManager, 0);
|
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
|
// We assume the server is local and on port 4242
|
||||||
server.set_host("localhost", 4242);
|
server.set_host("localhost", 4242);
|
||||||
}
|
}
|
||||||
@ -72,8 +72,18 @@ int main(int argc, char *argv[]) {
|
|||||||
nout << "sending datagram\n";
|
nout << "sending datagram\n";
|
||||||
|
|
||||||
// Send it and close the connection
|
// Send it and close the connection
|
||||||
prog.qWriter->send(datagram, con);
|
prog.cWriter->send(datagram, con);
|
||||||
prog.qManager->close_connection(con);
|
con->flush();
|
||||||
return 0;
|
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;
|
QueuedConnectionManager *qManager;
|
||||||
QueuedConnectionReader *qReader;
|
QueuedConnectionReader *qReader;
|
||||||
ConnectionWriter *qWriter;
|
ConnectionWriter *cWriter;
|
||||||
NetAddress server;
|
NetAddress server;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -161,7 +161,9 @@ MayaToEggServer() :
|
|||||||
qManager = new QueuedConnectionManager();
|
qManager = new QueuedConnectionManager();
|
||||||
qListener = new QueuedConnectionListener(qManager, 0);
|
qListener = new QueuedConnectionListener(qManager, 0);
|
||||||
qReader = new QueuedConnectionReader(qManager, 0);
|
qReader = new QueuedConnectionReader(qManager, 0);
|
||||||
|
cWriter = new ConnectionWriter(qManager, 0);
|
||||||
dummy = new MayaToEggConverter();
|
dummy = new MayaToEggConverter();
|
||||||
|
|
||||||
nout << "Initializing Maya...\n";
|
nout << "Initializing Maya...\n";
|
||||||
if (!dummy->open_api()) {
|
if (!dummy->open_api()) {
|
||||||
nout << "Unable to initialize Maya.\n";
|
nout << "Unable to initialize Maya.\n";
|
||||||
@ -178,6 +180,7 @@ MayaToEggServer::
|
|||||||
delete qManager;
|
delete qManager;
|
||||||
delete qReader;
|
delete qReader;
|
||||||
delete qListener;
|
delete qListener;
|
||||||
|
delete cWriter;
|
||||||
delete dummy;
|
delete dummy;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -326,8 +329,22 @@ poll() {
|
|||||||
// pointer and add it to the reader list
|
// pointer and add it to the reader list
|
||||||
if (qListener->new_connection_available()) {
|
if (qListener->new_connection_available()) {
|
||||||
PT(Connection) con;
|
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);
|
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
|
// Clean up the malloc'd pointer pointer
|
||||||
free(cargv);
|
free(cargv);
|
||||||
} // qReader->get_data
|
} // 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
|
} // qReader->data_available
|
||||||
} // poll
|
} // poll
|
||||||
|
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
#include "queuedConnectionManager.h"
|
#include "queuedConnectionManager.h"
|
||||||
#include "queuedConnectionListener.h"
|
#include "queuedConnectionListener.h"
|
||||||
#include "queuedConnectionReader.h"
|
#include "queuedConnectionReader.h"
|
||||||
|
#include "connectionWriter.h"
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Class : MayaToEggServer
|
// Class : MayaToEggServer
|
||||||
@ -39,11 +40,14 @@ public:
|
|||||||
QueuedConnectionManager *qManager;
|
QueuedConnectionManager *qManager;
|
||||||
QueuedConnectionListener *qListener;
|
QueuedConnectionListener *qListener;
|
||||||
QueuedConnectionReader *qReader;
|
QueuedConnectionReader *qReader;
|
||||||
|
ConnectionWriter *cWriter;
|
||||||
MayaToEggConverter *dummy;
|
MayaToEggConverter *dummy;
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
static bool dispatch_transform_type(const string &opt, const string &arg, void *var);
|
static bool dispatch_transform_type(const string &opt, const string &arg, void *var);
|
||||||
|
typedef pset< PT(Connection) > Clients;
|
||||||
|
Clients _clients;
|
||||||
|
|
||||||
int _verbose;
|
int _verbose;
|
||||||
bool _polygon_output;
|
bool _polygon_output;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user