]> git.llucax.com Git - z.facultad/75.42/plaqui.git/blobdiff - Server/src/tcpserver.cpp
Se unlockea() el mutex despues de llamar a connection->run(). Si lo unlockeo()
[z.facultad/75.42/plaqui.git] / Server / src / tcpserver.cpp
index d2bb7fd58eed54a78be5b1a5ded52a25fbbf08d8..a7b3dc7e6db8fbe96c817ec068966896c14e0f1c 100644 (file)
 
 #include "plaqui/server/tcpserver.h"
 #include <sigc++/class_slot.h>
 
 #include "plaqui/server/tcpserver.h"
 #include <sigc++/class_slot.h>
+// FIXME - para probar mutex
+#include <glibmm/timer.h>
 #ifdef DEBUG
 #      include <iostream>
 #endif // DEBUG
 
 #ifdef DEBUG
 #      include <iostream>
 #endif // DEBUG
 
-const unsigned PlaQui::Server::TCPServer::MAX_PENDING_CONNECTIONS = 5;
+const unsigned PlaQui::Server::TCPServer::MAX_PENDING_CONNECTIONS = 10;
 
 PlaQui::Server::TCPServer::~TCPServer(void) {
 #ifdef DEBUG
 
 PlaQui::Server::TCPServer::~TCPServer(void) {
 #ifdef DEBUG
@@ -62,9 +64,8 @@ void PlaQui::Server::TCPServer::on_connection_finished(
        std::cerr << __FILE__ <<  ": on_connection_finished(connection = "
                << connection << ")" << std::endl;
 #endif // DEBUG
        std::cerr << __FILE__ <<  ": on_connection_finished(connection = "
                << connection << ")" << std::endl;
 #endif // DEBUG
-       connections_mutex.lock();
-       // FIXME pruebo el mutex.
-       sleep(5);
+       Glib::Mutex::Lock lock(connections_mutex);
+       // XXX connections_mutex.lock();
        connections.remove(connection);
 #ifdef DEBUG
        std::cerr << __FILE__ <<  ": lista de conexiones" << std::endl;
        connections.remove(connection);
 #ifdef DEBUG
        std::cerr << __FILE__ <<  ": lista de conexiones" << std::endl;
@@ -73,7 +74,7 @@ void PlaQui::Server::TCPServer::on_connection_finished(
                std::cerr << "\t " << *i << std::endl;
        }
 #endif // DEBUG
                std::cerr << "\t " << *i << std::endl;
        }
 #endif // DEBUG
-       connections_mutex.unlock();
+       // XXX connections_mutex.unlock();
 }
 
 /// \todo TODO: ver tema de timeout o como salir de un accept().
 }
 
 /// \todo TODO: ver tema de timeout o como salir de un accept().
@@ -89,9 +90,7 @@ void PlaQui::Server::TCPServer::real_run(void) {
                std::cerr << __FILE__ <<  ": real_run(): connection = " << connection
                        << std::endl;
 #endif // DEBUG
                std::cerr << __FILE__ <<  ": real_run(): connection = " << connection
                        << std::endl;
 #endif // DEBUG
-               connections_mutex.lock();
-               // FIXME pruebo el mutex.
-               sleep(5);
+               Glib::Mutex::Lock lock(connections_mutex);
                connections.push_back(connection);
 #ifdef DEBUG
                std::cerr << __FILE__ <<  ": real_run(): lista de conexiones" << std::endl;
                connections.push_back(connection);
 #ifdef DEBUG
                std::cerr << __FILE__ <<  ": real_run(): lista de conexiones" << std::endl;
@@ -100,7 +99,6 @@ void PlaQui::Server::TCPServer::real_run(void) {
                        std::cerr << "\t " << *i << std::endl;
                }
 #endif // DEBUG
                        std::cerr << "\t " << *i << std::endl;
                }
 #endif // DEBUG
-               connections_mutex.unlock();
                // Conecto la señal para cuando termina una conexión, borrarla.
                connection->signal_finished().connect(
                                SigC::bind<Connection*>(
                // Conecto la señal para cuando termina una conexión, borrarla.
                connection->signal_finished().connect(
                                SigC::bind<Connection*>(
@@ -108,6 +106,7 @@ void PlaQui::Server::TCPServer::real_run(void) {
                                                &TCPServer::on_connection_finished),
                                        connection));
                connection->run();
                                                &TCPServer::on_connection_finished),
                                        connection));
                connection->run();
+               //connections_mutex.unlock(); // Si pongo el mutex antes del run(), muere.
        }
 }
 
        }
 }