From: Leandro Lucarella Date: Wed, 22 Oct 2003 07:31:08 +0000 (+0000) Subject: Se termina de migrar lo que habia hecho al nuevo modelo cliente-servidor, pero X-Git-Tag: svn_import~385 X-Git-Url: https://git.llucax.com/z.facultad/75.42/plaqui.git/commitdiff_plain/00cffd5f7c35a915c09d55e6292775e9e01bdeec?ds=sidebyside;hp=e6d0648eb6af32d0e8db4876430f20dcc7d8d920 Se termina de migrar lo que habia hecho al nuevo modelo cliente-servidor, pero tengo problemas para compilar el ejemplo en el directorio Server/tests (la lib aparentemente compila). --- diff --git a/Server/Doxyfile b/Server/Doxyfile index e01cc5e..d0fcea6 100644 --- a/Server/Doxyfile +++ b/Server/Doxyfile @@ -13,8 +13,8 @@ REPEAT_BRIEF = YES ALWAYS_DETAILED_SEC = NO INLINE_INHERITED_MEMB = NO FULL_PATH_NAMES = YES -STRIP_FROM_PATH = /home/luca/facultad/75.42/2003-2/final/Server/include \ - /home/luca/facultad/75.42/2003-2/final/Server/src +STRIP_FROM_PATH = /home/luca/facultad/75.42/2003-2/final/Server/include/ \ + /home/luca/facultad/75.42/2003-2/final/Server/ SHORT_NAMES = NO JAVADOC_AUTOBRIEF = YES MULTILINE_CPP_IS_BRIEF = YES diff --git a/Server/include/plaqui/server/connection.h b/Server/include/plaqui/server/connection.h index 5b777db..4cdf44b 100644 --- a/Server/include/plaqui/server/connection.h +++ b/Server/include/plaqui/server/connection.h @@ -51,7 +51,7 @@ namespace Server { /** * Destructor. */ - virtual ~Connection(void) {} + virtual ~Connection(void); /** * Constructor. diff --git a/Server/include/plaqui/server/controlclient.h b/Server/include/plaqui/server/controlclient.h index 8341a5f..73acdcf 100644 --- a/Server/include/plaqui/server/controlclient.h +++ b/Server/include/plaqui/server/controlclient.h @@ -41,7 +41,7 @@ namespace Server { private: /** - * Atiende la conexión. + * Realiza la conexión al servidor. */ virtual void real_run(void); @@ -50,7 +50,7 @@ namespace Server { /** * Destructor. */ - virtual ~ControlClient(void) {} + virtual ~ControlClient(void); /** * Constructor. diff --git a/Server/include/plaqui/server/controlserver.h b/Server/include/plaqui/server/controlserver.h index 8a646c6..f269e4b 100644 --- a/Server/include/plaqui/server/controlserver.h +++ b/Server/include/plaqui/server/controlserver.h @@ -50,7 +50,7 @@ namespace Server { /** * Destructor. */ - virtual ~ControlServer(void) {} + virtual ~ControlServer(void); /** * Constructor. diff --git a/Server/include/plaqui/server/receiver.h b/Server/include/plaqui/server/receiver.h index aa06544..de481f6 100644 --- a/Server/include/plaqui/server/receiver.h +++ b/Server/include/plaqui/server/receiver.h @@ -39,12 +39,19 @@ namespace Server { /// Conexión para recibir el estado de una planta. class Receiver: public ServerConnection { + private: + + /** + * Recibe la transmisión. + */ + virtual void real_run(void); + public: /** * Destructor. */ - virtual ~Receiver(void) {} + virtual ~Receiver(void); /** * Constructor. @@ -54,11 +61,6 @@ namespace Server { */ Receiver(int port = 7528, std::string host = "localhost"); - /** - * Recibe la transmisión. - */ - virtual void run(void); - }; } diff --git a/Server/include/plaqui/server/runnable.h b/Server/include/plaqui/server/runnable.h index 2d34e6c..7896090 100644 --- a/Server/include/plaqui/server/runnable.h +++ b/Server/include/plaqui/server/runnable.h @@ -52,12 +52,18 @@ namespace Server { /// Thread en el cual correr la tarea. Glib::Thread* thread; - /// Indica si se debe frinalizar la tarea. - bool stop; - /// Señal que indica que se finalizó la tarea. SignalFinished finished; + protected: + + /** + * Indica si se debe frinalizar la tarea. + * + * \todo Poner como privado y poner get() set() con locks. + */ + bool stop; + // Métodos. private: @@ -79,7 +85,7 @@ namespace Server { /** * Destructor. */ - virtual ~Runnable(void) {} + virtual ~Runnable(void); /** * Constructor. diff --git a/Server/include/plaqui/server/server.h b/Server/include/plaqui/server/server.h index f16e2df..3776cc7 100644 --- a/Server/include/plaqui/server/server.h +++ b/Server/include/plaqui/server/server.h @@ -67,19 +67,23 @@ namespace Server { // Métodos. - private: + protected: /** - * Entra en el loop para atender conexiones. + * Obtiene una nueva \ref Connection "conexión". + * + * \param sd Descriptor del socket de la nueva conexión. + * + * \return Nueva conexión. */ - virtual void real_run(void); + virtual Connection* new_connection(const sockbuf::sockdesc& sd); public: /** * Destructor. */ - virtual ~Server(void) {} + virtual ~Server(void); /** * Constructor. @@ -120,7 +124,7 @@ namespace Server { * * \todo Hacer un tipo Command abstracto o algo así. */ - void on_connection_command_received(void* command); + void on_control_command_received(void* command); }; diff --git a/Server/include/plaqui/server/serverconnection.h b/Server/include/plaqui/server/serverconnection.h index 91fa37f..1444343 100644 --- a/Server/include/plaqui/server/serverconnection.h +++ b/Server/include/plaqui/server/serverconnection.h @@ -62,7 +62,21 @@ namespace Server { /** * Destructor. */ - virtual ~ServerConnection(void) {} + virtual ~ServerConnection(void); + + /** + * Constructor. + * + * \param socket Descriptor de socket a usar en la conexión. + */ + ServerConnection(const sockbuf::sockdesc& sd); + + /** + * Constructor. + * + * \param type Tipo de socket a usar. + */ + ServerConnection(sockbuf::type type); /** * Obtiene la señal que avisa que se recibió un comando. diff --git a/Server/include/plaqui/server/tcpserver.h b/Server/include/plaqui/server/tcpserver.h index b379844..b3ecfa6 100644 --- a/Server/include/plaqui/server/tcpserver.h +++ b/Server/include/plaqui/server/tcpserver.h @@ -28,10 +28,9 @@ #ifndef PLAQUI_TCPSERVER_H #define PLAQUI_TCPSERVER_H -#include "plaqui/server/controlserver.h" -#include "plaqui/server/transmitter.h" +#include "plaqui/server/runnable.h" +#include "plaqui/server/connection.h" #include -#include #include namespace PlaQui { @@ -49,7 +48,7 @@ namespace Server { private: /// Lista de conexiones de control. - typedef std::list ConnectionList; + typedef std::list ConnectionList; // Atributos. @@ -86,7 +85,7 @@ namespace Server { /** * Destructor. */ - virtual ~TCPServer(void) {} + virtual ~TCPServer(void); /** * Constructor. diff --git a/Server/include/plaqui/server/transmitter.h b/Server/include/plaqui/server/transmitter.h index c3467a4..93b47e9 100644 --- a/Server/include/plaqui/server/transmitter.h +++ b/Server/include/plaqui/server/transmitter.h @@ -50,7 +50,7 @@ namespace Server { /** * Destructor. */ - virtual ~Transmitter(void) {} + virtual ~Transmitter(void); /** * Constructor. diff --git a/Server/src/Makefile b/Server/src/Makefile index f1a4b83..76ab99b 100644 --- a/Server/src/Makefile +++ b/Server/src/Makefile @@ -59,6 +59,10 @@ connection_h=$(runnable_h) $(INCLUDE_DIR)/connection.h objects+=connection.o connection.o: $(connection_h) connection.cpp +serverconnection_h=$(connection_h) $(INCLUDE_DIR)/serverconnection.h +objects+=serverconnection.o +serverconnection.o: $(serverconnection_h) serverconnection.cpp + controlclient_h=$(connection_h) $(INCLUDE_DIR)/controlclient.h objects+=controlclient.o controlclient.o: $(controlclient_h) controlclient.cpp @@ -75,7 +79,12 @@ transmitter_h=$(connection_h) $(INCLUDE_DIR)/transmitter.h objects+=transmitter.o transmitter.o: $(transmitter_h) transmitter.cpp -server_h=$(controlserver_h) $(transmitter_h) $(INCLUDE_DIR)/server.h +tcpserver_h=$(connection_h) $(INCLUDE_DIR)/tcpserver.h +objects+=tcpserver.o +tcpserver.o: $(tcpserver_h) tcpserver.cpp + +server_h=$(tcpserver) $(controlserver_h) $(transmitter_h) \ + $(INCLUDE_DIR)/server.h objects+=server.o server.o: $(server_h) server.cpp diff --git a/Server/src/controlclient.cpp b/Server/src/controlclient.cpp index 7138b44..99c5348 100644 --- a/Server/src/controlclient.cpp +++ b/Server/src/controlclient.cpp @@ -26,18 +26,31 @@ // #include "plaqui/server/controlclient.h" -// XXX -#include +#ifdef DEBUG +# include +#endif // DEBUG -using namespace PlaQui::Server; +PlaQui::Server::ControlClient::~ControlClient(void) { +#ifdef DEBUG + std::cerr << __FILE__ << ": destructor." << std::endl; +#endif // DEBUG +} -ControlClient::ControlClient(std::string host, int port): +PlaQui::Server::ControlClient::ControlClient(std::string host, int port): Connection(sockbuf::sock_stream) { +#ifdef DEBUG + std::cerr << __FILE__ << ": host" << host + << " | port = " << port << std::endl; +#endif // DEBUG // FIXME - poner en run(). socket->connect(host.c_str(), port); } -void ControlClient::real_run(void) { +void PlaQui::Server::ControlClient::real_run(void) { +#ifdef DEBUG + std::cerr << __FILE__ << ": real_run." << std::endl; +#endif // DEBUG +#ifdef DEBUG // FIXME - debería tirar una excepción? if (!socket->is_open()) { std::cerr << "No se pudo conectar a " << socket->peerhost() << @@ -45,6 +58,7 @@ void ControlClient::real_run(void) { } else { std::cerr << "Conectado a " << socket->peerhost() << ":" << socket->peerport() << "." << std::endl; +#endif // DEBUG } } diff --git a/Server/src/controlserver.cpp b/Server/src/controlserver.cpp index 544483f..64f4cfe 100644 --- a/Server/src/controlserver.cpp +++ b/Server/src/controlserver.cpp @@ -40,7 +40,7 @@ PlaQui::Server::ControlServer::~ControlServer(void) { } PlaQui::Server::ControlServer::ControlServer(const sockbuf::sockdesc& sd): - Connection(sd) { + PlaQui::Server::ServerConnection(sd) { #ifdef DEBUG std::cerr << __FILE__ << ": sd = " << sd.sock << std::endl; #endif // DEBUG diff --git a/Server/src/receiver.cpp b/Server/src/receiver.cpp index c492fe1..c64eaad 100644 --- a/Server/src/receiver.cpp +++ b/Server/src/receiver.cpp @@ -26,16 +26,30 @@ // #include "plaqui/server/receiver.h" +#ifdef DEBUG +# include +#endif // DEBUG -using namespace PlaQui::Server; +PlaQui::Server::Receiver::~Receiver(void) { +#ifdef DEBUG + std::cerr << __FILE__ << ": destructor." << std::endl; +#endif // DEBUG +} -Receiver::Receiver(int port, std::string host): - Connection(sockbuf::sock_dgram) { +PlaQui::Server::Receiver::Receiver(int port, std::string host): + PlaQui::Server::ServerConnection(sockbuf::sock_dgram) { +#ifdef DEBUG + std::cerr << __FILE__ << ": port = " << port + << " | host = " << host << std::endl; +#endif // DEBUG // FIXME - deberia ir en run(). socket->bind(port); } -void Receiver::run(void) { +void PlaQui::Server::Receiver::real_run(void) { +#ifdef DEBUG + std::cerr << __FILE__ << ": real_run." << std::endl; +#endif // DEBUG // FIXME - debería tirar una excepción? if (!socket->is_open()) { std::cerr << "No se pudo conectar a " << socket->peerhost() << diff --git a/Server/src/request.cpp b/Server/src/request.cpp index 92bb7e1..d17ca72 100644 --- a/Server/src/request.cpp +++ b/Server/src/request.cpp @@ -34,33 +34,40 @@ # include #endif // DEBUG -using namespace PlaQui::Server; +const std::string +PlaQui::Server::Request::CHARS_DIGIT = "0123456789"; -const std::string Request::CHARS_DIGIT = "0123456789"; +const std::string +PlaQui::Server::Request::CHARS_LOWALPHA = "abcdefghijklmnopqrstuvwxyz"; -const std::string Request::CHARS_LOWALPHA = "abcdefghijklmnopqrstuvwxyz"; +const std::string +PlaQui::Server::Request::CHARS_UPALPHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; -const std::string Request::CHARS_UPALPHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; +const std::string +PlaQui::Server::Request::CHARS_ALPHA = CHARS_LOWALPHA + CHARS_UPALPHA; -const std::string Request::CHARS_ALPHA = CHARS_LOWALPHA + CHARS_UPALPHA; +const std::string +PlaQui::Server::Request::CHARS_ALPHANUM = CHARS_DIGIT + CHARS_ALPHA; -const std::string Request::CHARS_ALPHANUM = CHARS_DIGIT + CHARS_ALPHA; +const std::string +PlaQui::Server::Request::CHARS_RESERVED = ";/?:@&=+$,"; -const std::string Request::CHARS_RESERVED = ";/?:@&=+$,"; +const std::string +PlaQui::Server::Request::CHARS_MARK = "-_.!~*'()"; -const std::string Request::CHARS_MARK = "-_.!~*'()"; +const std::string +PlaQui::Server::Request::CHARS_UNRESERVED = CHARS_ALPHANUM + CHARS_MARK; -const std::string Request::CHARS_UNRESERVED = CHARS_ALPHANUM + CHARS_MARK; +const std::string +PlaQui::Server::Request::CHARS_HEX = CHARS_DIGIT + std::string("abcdefABCDEF"); -const std::string Request::CHARS_HEX = CHARS_DIGIT + std::string("abcdefABCDEF"); - -void Request::set_request(const std::string& req, const std::string& host, - unsigned port) { +void PlaQui::Server::Request::set_request(const std::string& req, + const std::string& host, unsigned port) { #ifdef DEBUG std::cerr << __FILE__ << ": req = " << req << " | host = " << host << " | port = " << port << std::endl; #endif // DEBUG - String request(req); + PlaQui::Server::String request(req); (*this)["REMOTE_HOST"] = host; std::stringstream ss; ss << port; @@ -71,8 +78,9 @@ void Request::set_request(const std::string& req, const std::string& host, throw "HTTP/1.1 501 Method Not Implemented"; } // Averiguo método. - std::string::size_type pos = request.find_first_of(String::SPACE_CHARS); - String method = request.substr(0, pos); + std::string::size_type pos = request.find_first_of( + PlaQui::Server::String::SPACE_CHARS); + PlaQui::Server::String method = request.substr(0, pos); if ((method.to_upper() == "GET") || (method.to_upper() == "POST")) { (*this)["REQUEST_METHOD"] = method; } else { @@ -87,13 +95,13 @@ void Request::set_request(const std::string& req, const std::string& host, throw "HTTP/1.1 400 Bad Request"; } // Si tiene más espacios, tengo la URI y el protocolo (o un error). - pos = request.find_first_of(String::SPACE_CHARS); + pos = request.find_first_of(PlaQui::Server::String::SPACE_CHARS); if (pos != std::string::npos) { // Si el resto es un protocolo válido, agrego más variables. - String protocol = request.substr(pos + 1); + PlaQui::Server::String protocol = request.substr(pos + 1); protocol = protocol.trim(); - if ((String(protocol).to_upper() == "HTTP/1.0") - || (String(protocol).to_upper() == "HTTP/1.1")) { + if ((PlaQui::Server::String(protocol).to_upper() == "HTTP/1.0") + || (PlaQui::Server::String(protocol).to_upper() == "HTTP/1.1")) { (*this)["SERVER_PROTOCOL"] = protocol; // Si no es un error. } else { @@ -120,7 +128,7 @@ void Request::set_request(const std::string& req, const std::string& host, (*this)["SCRIPT_NAME"] = request.substr(0, pos); } -void Request::parse_header(const std::string& header) { +void PlaQui::Server::Request::parse_header(const std::string& header) { #ifdef DEBUG std::cerr << __FILE__ << ": header = " << header << std::endl; #endif // DEBUG diff --git a/Server/src/runnable.cpp b/Server/src/runnable.cpp index 66579ac..0c6b477 100644 --- a/Server/src/runnable.cpp +++ b/Server/src/runnable.cpp @@ -32,7 +32,16 @@ # include #endif // DEBUG +PlaQui::Server::Runnable::~Runnable(void) { +#ifdef DEBUG + std::cerr << __FILE__ << ": destructor." << std::endl; +#endif // DEBUG +} + PlaQui::Server::Runnable::Runnable(void): thread(0), stop(false) { +#ifdef DEBUG + std::cerr << __FILE__ << ": constructor." << std::endl; +#endif // DEBUG } void PlaQui::Server::Runnable::static_run(PlaQui::Server::Runnable* runner) { diff --git a/Server/src/server.cpp b/Server/src/server.cpp index 1206b1c..81285cb 100644 --- a/Server/src/server.cpp +++ b/Server/src/server.cpp @@ -30,36 +30,44 @@ # include #endif // DEBUG -using namespace PlaQui::Server; +PlaQui::Server::Server::~Server(void) { +#ifdef DEBUG + std::cerr << __FILE__ << ": destructor." << std::endl; +#endif // DEBUG +} -Server::Server(int port): - socket(sockbuf::sock_stream) { - socket.bind(port); +PlaQui::Server::Server::Server(int port): + PlaQui::Server::Server::TCPServer(port) { #ifdef DEBUG - std::cerr << "Escuchando en " << socket.localhost() << - ":" << socket.localport() << "." << std::endl; + std::cerr << __FILE__ << ": port = " << port << std::endl; #endif // DEBUG - socket.listen(); } -bool Server::start_transmission(std::string host, int port) { +/// \todo Implementar. +bool PlaQui::Server::Server::start_transmission(std::string host, int port) { +#ifdef DEBUG + std::cerr << __FILE__ << ": start_transmission(host = " << host + << " | port = " << port << ")" << std::endl; +#endif // DEBUG // TODO return false; } -bool Server::stop_transmission(std::string host, int port) { +/// \todo Implementar. +bool PlaQui::Server::Server::stop_transmission(std::string host, int port) { +#ifdef DEBUG + std::cerr << __FILE__ << ": stop_transmission(host = " << host + << " | port = " << port << ")" << std::endl; +#endif // DEBUG // TODO return false; } -void Server::real_run(void) { - // FIXME se tiene que ir a la clase para poder frenarlo desde afuera. - bool stop = false; - ControlServer* control_server; - while (!stop) { - control_server = new ControlServer(socket.accept()); - controllers.push_back(control_server); - control_server->run(); - } +/// \todo Implementar. +void PlaQui::Server::Server::on_control_command_received(void* command) { +#ifdef DEBUG + std::cerr << __FILE__ << ": on_control_command_received(command = " + << command << ")" << std::endl; +#endif // DEBUG } diff --git a/Server/src/serverconnection.cpp b/Server/src/serverconnection.cpp index 5e159c3..a5cbea3 100644 --- a/Server/src/serverconnection.cpp +++ b/Server/src/serverconnection.cpp @@ -37,21 +37,19 @@ PlaQui::Server::ServerConnection::~ServerConnection(void) { #endif // DEBUG } -/* PlaQui::Server::ServerConnection::ServerConnection(const sockbuf::sockdesc& sd): - socket(sd) { + PlaQui::Server::Connection(sd) { #ifdef DEBUG std::cerr << __FILE__ << ": sd = " << sd.sock << std::endl; #endif // DEBUG } PlaQui::Server::ServerConnection::ServerConnection(sockbuf::type type): - socket(type) { + PlaQui::Server::Connection(type) { #ifdef DEBUG std::cerr << __FILE__ << ": type = " << type << std::endl; #endif // DEBUG } -*/ PlaQui::Server::ServerConnection::SignalCommandReceived& PlaQui::Server::ServerConnection::signal_command_received(void) { diff --git a/Server/src/string.cpp b/Server/src/string.cpp index 24904a7..edc522c 100644 --- a/Server/src/string.cpp +++ b/Server/src/string.cpp @@ -32,25 +32,25 @@ # include #endif // DEBUG -using namespace PlaQui::Server; - -const std::string String::SPACE_CHARS = " \t\n\r"; +const std::string PlaQui::Server::String::SPACE_CHARS = " \t\n\r"; -String::String(const std::string& str): std::string(str.c_str()) { +PlaQui::Server::String::String(const std::string& str): + std::string(str.c_str()) { } -String& String::trim(const String& clist) { +PlaQui::Server::String& PlaQui::Server::String::trim( + const PlaQui::Server::String& clist) { erase(0, find_first_not_of(clist)); erase(find_last_not_of(clist) + 1); return *this; } -String& String::to_lower(void) { +PlaQui::Server::String& PlaQui::Server::String::to_lower(void) { std::transform(begin(), end(), begin(), tolower); return *this; } -String& String::to_upper(void) { +PlaQui::Server::String& PlaQui::Server::String::to_upper(void) { std::transform(begin(), end(), begin(), toupper); return *this; } diff --git a/Server/src/tcpserver.cpp b/Server/src/tcpserver.cpp new file mode 100644 index 0000000..82f1577 --- /dev/null +++ b/Server/src/tcpserver.cpp @@ -0,0 +1,90 @@ +// 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 +//---------------------------------------------------------------------------- +// +// $Id$ +// + +#include "plaqui/server/tcpserver.h" +#include // FIXME +#ifdef DEBUG +# include +#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( + SigC::slot_class(*this, + &PlaQui::Server::TCPServer::on_connection_finished), + conn)); + conn->run(); + } +} + diff --git a/Server/src/transmitter.cpp b/Server/src/transmitter.cpp index 37113cc..268f216 100644 --- a/Server/src/transmitter.cpp +++ b/Server/src/transmitter.cpp @@ -28,16 +28,30 @@ #include "plaqui/server/transmitter.h" #include #include +#ifdef DEBUG +# include +#endif // DEBUG -using namespace PlaQui::Server; +PlaQui::Server::Transmitter::~Transmitter(void) { +#ifdef DEBUG + std::cerr << __FILE__ << ": destructor." << std::endl; +#endif // DEBUG +} -Transmitter::Transmitter(std::string host, int port): - Connection(sockbuf::sock_dgram) { +/// \todo debría conectarse en real_run() (?) +PlaQui::Server::Transmitter::Transmitter(std::string host, int port): + PlaQui::Server::Connection(sockbuf::sock_dgram) { +#ifdef DEBUG + std::cerr << __FILE__ << ": host = " << host + << " | port = " << port << std::endl; +#endif // DEBUG // FIXME - deberia ir en run(). socket->connect(host.c_str(), port); } -void Transmitter::real_run(void) { +/// \todo debría dar una excepción (?) +void PlaQui::Server::Transmitter::real_run(void) { +#ifdef DEBUG // FIXME - debería tirar una excepción? if (!socket->is_open()) { std::cerr << "No se pudo conectar a " << socket->peerhost() << @@ -46,5 +60,6 @@ void Transmitter::real_run(void) { std::cerr << "Conectado a " << socket->peerhost() << ":" << socket->peerport() << "." << std::endl; } +#endif // DEBUG }