+// vim: set noexpandtab tabstop=4 shiftwidth=4:
+//----------------------------------------------------------------------------
+// PlaQui
+//----------------------------------------------------------------------------
+// This file is part of PlaQui.
+//
+// PlaQui is free software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the Free Software
+// Foundation; either version 2 of the License, or (at your option) any later
+// version.
+//
+// PlaQui is distributed in the hope that it will be useful, but WITHOUT ANY
+// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+// details.
+//
+// You should have received a copy of the GNU General Public License along
+// with PlaQui; if not, write to the Free Software Foundation, Inc., 59 Temple
+// Place, Suite 330, Boston, MA 02111-1307 USA
+//----------------------------------------------------------------------------
+// Creado: Sat Oct 18 18:18:36 2003
+// Autores: Leandro Lucarella <llucare@fi.uba.ar>
+//----------------------------------------------------------------------------
+//
+// $Id$
+//
+
+#include "plaqui/server/tcpserver.h"
+#include <sigc++/class_slot.h> // FIXME
+#ifdef DEBUG
+# include <iostream>
+#endif // DEBUG
+
+PlaQui::Server::TCPServer::~TCPServer(void) {
+#ifdef DEBUG
+ std::cerr << __FILE__ << ": destructor." << std::endl;
+#endif // DEBUG
+}
+
+PlaQui::Server::TCPServer::TCPServer(int port):
+ socket(sockbuf::sock_stream) {
+#ifdef DEBUG
+ std::cerr << __FILE__ << ": port = " << port << std::endl;
+#endif // DEBUG
+ socket.bind(port);
+#ifdef DEBUG
+ std::cerr << __FILE__ << ": escuchando en " << socket.localhost()
+ << ":" << socket.localport() << "." << std::endl;
+#endif // DEBUG
+ socket.listen();
+#ifdef DEBUG
+ std::cerr << __FILE__ << ": [despues de listen()] escuchando en "
+ << socket.localhost() << ":" << socket.localport() << "." << std::endl;
+#endif // DEBUG
+}
+
+void PlaQui::Server::TCPServer::on_connection_finished(
+ PlaQui::Server::Connection* connection) {
+#ifdef DEBUG
+ std::cerr << __FILE__ << ": on_connection_finished(connection = "
+ << connection << ")" << std::endl;
+#endif // DEBUG
+ // TODO: poner lock.
+ connections.remove(connection);
+ // TODO: sacar lock.
+}
+
+void PlaQui::Server::TCPServer::real_run(void) {
+#ifdef DEBUG
+ std::cerr << __FILE__ << ": real_run" << std::endl;
+#endif // DEBUG
+ PlaQui::Server::Connection* conn;
+ while (!stop) {
+ // TODO: ver tema de timeout o como salir de un accept().
+ // Forma grasa de salir del accept: crear conexion que salga al toque.
+ conn = new_connection(socket.accept());
+ // TODO: poner lock.
+ connections.push_back(conn);
+ // TODO: sacar lock.
+ // TODO: esto va en Server::new_connection()
+ // Conecto la señal para cuando termina una conexión, borrarla.
+ conn->signal_finished().connect(
+ SigC::bind<PlaQui::Server::Connection*>(
+ SigC::slot_class(*this,
+ &PlaQui::Server::TCPServer::on_connection_finished),
+ conn));
+ conn->run();
+ }
+}
+