|
@@ -26,22 +26,8 @@
|
|
|
* Initializes the Maya conversion server.
|
|
* Initializes the Maya conversion server.
|
|
|
*/
|
|
*/
|
|
|
MayaConversionServer::
|
|
MayaConversionServer::
|
|
|
-MayaConversionServer() {
|
|
|
|
|
- _qManager = new QueuedConnectionManager();
|
|
|
|
|
- _qListener = new QueuedConnectionListener(_qManager, 0);
|
|
|
|
|
- _qReader = new QueuedConnectionReader(_qManager, 0);
|
|
|
|
|
- _cWriter = new ConnectionWriter(_qManager, 0);
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-/**
|
|
|
|
|
- * Cleans up the connection managers for the Maya conversion server.
|
|
|
|
|
- */
|
|
|
|
|
-MayaConversionServer::
|
|
|
|
|
-~MayaConversionServer() {
|
|
|
|
|
- delete _qManager;
|
|
|
|
|
- delete _qReader;
|
|
|
|
|
- delete _qListener;
|
|
|
|
|
- delete _cWriter;
|
|
|
|
|
|
|
+MayaConversionServer() : _qListener(&_qManager, 0), _qReader(&_qManager, 0),
|
|
|
|
|
+ _cWriter(&_qManager, 0) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -51,39 +37,39 @@ MayaConversionServer::
|
|
|
void MayaConversionServer::
|
|
void MayaConversionServer::
|
|
|
poll() {
|
|
poll() {
|
|
|
// Listen for new connections
|
|
// Listen for new connections
|
|
|
- _qListener->poll();
|
|
|
|
|
|
|
+ _qListener.poll();
|
|
|
|
|
|
|
|
// If we have a new connection from a client create a new connection pointer
|
|
// If we have a new connection from a client create a new connection pointer
|
|
|
// and add it to the reader list
|
|
// and add it to the reader list
|
|
|
- if (_qListener->new_connection_available()) {
|
|
|
|
|
|
|
+ if (_qListener.new_connection_available()) {
|
|
|
PT(Connection) rendezvous;
|
|
PT(Connection) rendezvous;
|
|
|
PT(Connection) connection;
|
|
PT(Connection) connection;
|
|
|
NetAddress address;
|
|
NetAddress address;
|
|
|
|
|
|
|
|
- if (_qListener->get_new_connection(rendezvous, address, connection)) {
|
|
|
|
|
- _qReader->add_connection(connection);
|
|
|
|
|
|
|
+ if (_qListener.get_new_connection(rendezvous, address, connection)) {
|
|
|
|
|
+ _qReader.add_connection(connection);
|
|
|
_clients.insert(connection);
|
|
_clients.insert(connection);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Check for reset clients
|
|
// Check for reset clients
|
|
|
- if (_qManager->reset_connection_available()) {
|
|
|
|
|
|
|
+ if (_qManager.reset_connection_available()) {
|
|
|
PT(Connection) connection;
|
|
PT(Connection) connection;
|
|
|
|
|
|
|
|
- if (_qManager->get_reset_connection(connection)) {
|
|
|
|
|
|
|
+ if (_qManager.get_reset_connection(connection)) {
|
|
|
_clients.erase(connection);
|
|
_clients.erase(connection);
|
|
|
- _qManager->close_connection(connection);
|
|
|
|
|
|
|
+ _qManager.close_connection(connection);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Poll the readers (created above) and if they have data process it
|
|
// Poll the readers (created above) and if they have data process it
|
|
|
- _qReader->poll();
|
|
|
|
|
|
|
+ _qReader.poll();
|
|
|
|
|
|
|
|
- if (_qReader->data_available()) {
|
|
|
|
|
|
|
+ if (_qReader.data_available()) {
|
|
|
// Grab the incoming data and unpack it
|
|
// Grab the incoming data and unpack it
|
|
|
NetDatagram datagram;
|
|
NetDatagram datagram;
|
|
|
|
|
|
|
|
- if (_qReader->get_data(datagram)) {
|
|
|
|
|
|
|
+ if (_qReader.get_data(datagram)) {
|
|
|
DatagramIterator data(datagram);
|
|
DatagramIterator data(datagram);
|
|
|
|
|
|
|
|
// First data should be the "argc" (argument count) from the client
|
|
// First data should be the "argc" (argument count) from the client
|
|
@@ -182,7 +168,7 @@ poll() {
|
|
|
response.add_bool(converted);
|
|
response.add_bool(converted);
|
|
|
|
|
|
|
|
// Send the response
|
|
// Send the response
|
|
|
- if (!_cWriter->send(response, datagram.get_connection())) {
|
|
|
|
|
|
|
+ if (!_cWriter.send(response, datagram.get_connection())) {
|
|
|
// Looks like we couldn't send the response
|
|
// Looks like we couldn't send the response
|
|
|
nout << "Could not send response to the client.\n";
|
|
nout << "Could not send response to the client.\n";
|
|
|
}
|
|
}
|
|
@@ -199,13 +185,13 @@ 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
|
|
|
|
|
|
|
|
Clients::iterator ci;
|
|
Clients::iterator ci;
|
|
|
for (ci = _clients.begin(); ci != _clients.end(); ++ci) {
|
|
for (ci = _clients.begin(); ci != _clients.end(); ++ci) {
|
|
|
- _qManager->close_connection(*ci);
|
|
|
|
|
|
|
+ _qManager.close_connection(*ci);
|
|
|
}
|
|
}
|
|
|
- } // qReader->data_available
|
|
|
|
|
|
|
+ } // qReader.data_available
|
|
|
} // poll
|
|
} // poll
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -214,7 +200,7 @@ poll() {
|
|
|
void MayaConversionServer::
|
|
void MayaConversionServer::
|
|
|
listen() {
|
|
listen() {
|
|
|
// Open a rendezvous port for receiving new connections from the client
|
|
// Open a rendezvous port for receiving new connections from the client
|
|
|
- PT(Connection) rend = _qManager->open_TCP_server_rendezvous(4242, 100);
|
|
|
|
|
|
|
+ PT(Connection) rend = _qManager.open_TCP_server_rendezvous(4242, 100);
|
|
|
|
|
|
|
|
if (rend.is_null()) {
|
|
if (rend.is_null()) {
|
|
|
nout << "Port opening failed!\n";
|
|
nout << "Port opening failed!\n";
|
|
@@ -224,7 +210,7 @@ listen() {
|
|
|
nout << "Server opened on port 4242, waiting for requests...\n";
|
|
nout << "Server opened on port 4242, waiting for requests...\n";
|
|
|
|
|
|
|
|
// Add this connection to the listeners list
|
|
// Add this connection to the listeners list
|
|
|
- _qListener->add_connection(rend);
|
|
|
|
|
|
|
+ _qListener.add_connection(rend);
|
|
|
|
|
|
|
|
// Main loop. Keep polling for connections, but don't eat up all the CPU.
|
|
// Main loop. Keep polling for connections, but don't eat up all the CPU.
|
|
|
while (true) {
|
|
while (true) {
|