1 // vim: set noexpandtab tabstop=4 shiftwidth=4:
2 //----------------------------------------------------------------------------
4 //----------------------------------------------------------------------------
5 // This file is part of PlaQui.
7 // PlaQui is free software; you can redistribute it and/or modify it under the
8 // terms of the GNU General Public License as published by the Free Software
9 // Foundation; either version 2 of the License, or (at your option) any later
12 // PlaQui is distributed in the hope that it will be useful, but WITHOUT ANY
13 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17 // You should have received a copy of the GNU General Public License along
18 // with PlaQui; if not, write to the Free Software Foundation, Inc., 59 Temple
19 // Place, Suite 330, Boston, MA 02111-1307 USA
20 //----------------------------------------------------------------------------
21 // Creado: Sat Oct 18 18:18:36 2003
22 // Autores: Leandro Lucarella <llucare@fi.uba.ar>
23 //----------------------------------------------------------------------------
28 #include "plaqui/server/tcpserver.h"
29 #include <sigc++/class_slot.h>
40 TCPServer::~TCPServer(void) {
42 cerr << __FILE__ << ": destructor." << endl;
46 TCPServer::TCPServer(int port): socket(sockbuf::sock_stream) {
48 cerr << __FILE__ << ": port = " << port << endl;
52 cerr << __FILE__ << ": escuchando en " << socket.localhost()
53 << ":" << socket.localport() << "." << endl;
55 socket.listen(MAX_PENDING_CONNECTIONS);
57 cerr << __FILE__ << ": [despues de listen()] escuchando en "
58 << socket.localhost() << ":" << socket.localport() << "." << endl;
62 void TCPServer::on_connection_finished(Connection* connection) {
64 cerr << __FILE__ << ": on_connection_finished(connection = "
65 << connection << ")" << endl;
67 Glib::Mutex::Lock lock(connections_mutex);
68 connections.remove(connection);
70 cerr << __FILE__ << ": lista de conexiones" << endl;
71 for (ConnectionList::const_iterator i = connections.begin();
72 i != connections.end(); i++) {
73 cerr << "\t " << *i << endl;
78 /// \todo TODO: ver tema de timeout o como salir de un accept().
79 void TCPServer::real_run(void) {
81 cerr << __FILE__ << ": real_run()" << endl;
83 Connection* connection;
85 // Forma grasa de salir del accept: crear conexion que salga al toque.
86 connection = new_connection(socket.accept());
88 cerr << __FILE__ << ": real_run(): connection = " << connection
91 Glib::Mutex::Lock lock(connections_mutex);
92 // XXX connections_mutex.lock();
93 connections.push_back(connection);
95 cerr << __FILE__ << ": real_run(): lista de conexiones" << endl;
96 for (ConnectionList::const_iterator i = connections.begin();
97 i != connections.end(); i++) {
98 cerr << "\t " << *i << endl;
101 // XXX connections_mutex.unlock(); // Si pongo el mutex antes del run(),
103 // Conecto la señal para cuando termina una conexión, borrarla.
104 connection->signal_finished().connect(
105 SigC::bind<Connection*>(
106 SigC::slot_class(*this,
107 &TCPServer::on_connection_finished),
113 } // namespace Server
115 } // namespace PlaQui