From cd6078479123cd2cfe62df2d838633c143649edf Mon Sep 17 00:00:00 2001 From: Leandro Lucarella Date: Wed, 5 Nov 2003 15:02:09 +0000 Subject: [PATCH] Todavia no compila pero lo subo igual por las dudas. --- Server/include/plaqui/server/httpheaders.h | 63 ++++++++ Server/include/plaqui/server/httpmessage.h | 91 ++++++++++++ Server/include/plaqui/server/httprequest.h | 127 ++++++++++++++++ Server/include/plaqui/server/httpresponse.h | 102 +++++++++++++ Server/src/httpheaders.cpp | 99 +++++++++++++ Server/src/httpmessage.cpp | 111 ++++++++++++++ Server/src/httprequest.cpp | 151 ++++++++++++++++++++ Server/src/tcpserver.cpp | 5 +- 8 files changed, 746 insertions(+), 3 deletions(-) create mode 100644 Server/include/plaqui/server/httpheaders.h create mode 100644 Server/include/plaqui/server/httpmessage.h create mode 100644 Server/include/plaqui/server/httprequest.h create mode 100644 Server/include/plaqui/server/httpresponse.h create mode 100644 Server/src/httpheaders.cpp create mode 100644 Server/src/httpmessage.cpp create mode 100644 Server/src/httprequest.cpp diff --git a/Server/include/plaqui/server/httpheaders.h b/Server/include/plaqui/server/httpheaders.h new file mode 100644 index 0000000..bc4ce02 --- /dev/null +++ b/Server/include/plaqui/server/httpheaders.h @@ -0,0 +1,63 @@ +// 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: dom oct 26 18:42:18 ART 2003 +// Autores: Leandro Lucarella +//---------------------------------------------------------------------------- +// +// $Id$ +// + +#ifndef PLAQUI_HTTPHEADERS_H +#define PLAQUI_HTTPHEADERS_H + +#include +#include + +namespace PlaQui { + +namespace Server { + + /// Cabeceras HTTP. + class HTTPHeaders: public std::map { + + public: + + /** + * Destructor. + */ + virtual ~HTTPHeaders(void); + + /** + * Obtiene los datos de las cabeceras HTTP desde un texto. + */ + friend std::istream& operator>>(std::istream& is, + const HTTPHeaders& h); + + /** + * Convierte las cabeceras HTTP a texto. + */ + friend std::ostream& operator<<(std::ostream& os, + const HTTPHeaders& h); + + +} + +#endif // PLAQUI_HTTPHEADERS_H diff --git a/Server/include/plaqui/server/httpmessage.h b/Server/include/plaqui/server/httpmessage.h new file mode 100644 index 0000000..cd583e7 --- /dev/null +++ b/Server/include/plaqui/server/httpmessage.h @@ -0,0 +1,91 @@ +// 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: dom oct 26 20:20:44 ART 2003 +// Autores: Leandro Lucarella +//---------------------------------------------------------------------------- +// +// $Id$ +// + +#ifndef PLAQUI_HTTPMESSAGE_H +#define PLAQUI_HTTPMESSAGE_H + +#include + +namespace PlaQui { + +namespace Server { + + /// Pedido HTTP. + class HTTPMessage { + + // Atributos. + + protected: + + /// Version HTTP. + std::string version; + + /// Cabeceras HTTP. + HTTPHeaders headers; + + /// Cuerpo del mensaje. + std::string body; + + // Métodos. + + public: + + /** + * Destructor. + */ + virtual ~HTTPMessage(void); + + /** + * Constructor. + */ + HTTPMessage(const std::string& http_version = "1.1"); + + /** + * Constructor. + */ + HTTPMessage(const std::string& body, + const std::string& http_version = "1.1"); + + /** + * Obtiene los datos del pedido HTTP desde un texto. + */ + friend std::istream& operator>>(std::istream& is, + const HTTPMessage& m); + + /** + * Convierte el pedido HTTP en texto. + */ + friend std::ostream& operator<<(std::ostream& os, + const HTTPMessage& m); + + }; + +} + +} + +#endif // PLAQUI_HTTPMESSAGE_H diff --git a/Server/include/plaqui/server/httprequest.h b/Server/include/plaqui/server/httprequest.h new file mode 100644 index 0000000..0f21452 --- /dev/null +++ b/Server/include/plaqui/server/httprequest.h @@ -0,0 +1,127 @@ +// 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: dom oct 26 18:54:30 ART 2003 +// Autores: Leandro Lucarella +//---------------------------------------------------------------------------- +// +// $Id$ +// + +#ifndef PLAQUI_HTTPREQUEST_H +#define PLAQUI_HTTPREQUEST_H + +#include "httpmessage.h" +#include + +namespace PlaQui { + +namespace Server { + + /// Pedido HTTP. + class HTTPRequest: public HTTPMessage { + + // Constantes. + + protected: + + /// Caracteres dígitos para URIs (RFC 2396). + static const std::string CHARS_DIGIT; + + /// Caracteres alfabéticos en minúsculas para URIs (RFC 2396). + static const std::string CHARS_LOWALPHA; + + /// Caracteres alfabéticos en mayúsculas para URIs (RFC 2396). + static const std::string CHARS_UPALPHA; + + /// Caracteres alfabéticos para URIs (RFC 2396). + static const std::string CHARS_ALPHA; + + /// Caracteres alfabnuméricos para URIs (RFC 2396). + static const std::string CHARS_ALPHANUM; + + /// Caracteres reservados para URIs (RFC 2396). + static const std::string CHARS_RESERVED; + + /// Caracteres de marca para URIs (RFC 2396). + static const std::string CHARS_MARK; + + /// Caracteres no reservados para URIs (RFC 2396). + static const std::string CHARS_UNRESERVED; + + /// Caracteres no hexa para URIs (RFC 2396). + static const std::string CHARS_HEX; + + // Tipos. + + public: + + /// Tipo de métodos HTTP reconocidos. + typedef enum {GET, POST} HTTPMethod; + + // Atributos. + + protected: + + /// Método HTTP. + HTTPMethod method; + + /// URI. + std::string uri; + + /// Query string. + std::string query; + + // Métodos. + + public: + + /** + * Destructor. + */ + virtual ~HTTPRequest(void); + + /** + * Constructor. + */ + HTTPRequest(const std::string& uri = "/", + const HTTPMethod& method = GET, + const std::string& query = "", + const std::string& http = "1.1"); + + /** + * Obtiene los datos del pedido HTTP desde un texto. + */ + friend std::istream& operator>>(std::istream& is, + const HTTPRequest& req); + + /** + * Convierte el pedido HTTP en texto. + */ + friend std::ostream& operator<<(std::ostream& os, + const HTTPRequest& req); + + }; + +} + +} + +#endif // PLAQUI_HTTPREQUEST_H diff --git a/Server/include/plaqui/server/httpresponse.h b/Server/include/plaqui/server/httpresponse.h new file mode 100644 index 0000000..936d2a3 --- /dev/null +++ b/Server/include/plaqui/server/httpresponse.h @@ -0,0 +1,102 @@ +// 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: dom oct 26 18:54:17 ART 2003 +// Autores: Leandro Lucarella +//---------------------------------------------------------------------------- +// +// $Id$ +// + +#ifndef PLAQUI_HTTPRESPONSE_H +#define PLAQUI_HTTPRESPONSE_H + +#include "httpmessage.h" +#include + +namespace PlaQui { + +namespace Server { + + /// Respuesta HTTP. + class HTTPResponse: public HTTPMessage { + + // Atributos. + + protected: + + /// Código de estado. + unsigned status_code; + + /// Descripción del código (razón). + std::string reason; + + // Métodos. + + public: + + /** + * Destructor. + */ + virtual ~HTTPResponse(void); + + /** + * Constructor. + */ + HTTPResponse(const std::string& version = "1.1"); + + /** + * Constructor. + */ + HTTPResponse(const Serializable& body, + const std::string& version = "1.1"); + + /** + * Constructor. + */ + HTTPResponse(unsigned status_code, const std::string& reason, + const std::string& version = "1.1"); + + /** + * Constructor. + */ + HTTPResponse(unsigned status_code, const std::string& reason, + const std::string& body, + const std::string& version = "1.1"); + + /** + * Obtiene los datos de la respuesta HTTP desde un texto. + */ + friend std::istream& operator>>(std::istream& is, + const HTTPResponse& resp); + + /** + * Convierte la respuesta HTTP en texto. + */ + friend std::ostream& operator<<(std::ostream& os, + const HTTPResponse& resp); + + }; + +} + +} + +#endif // PLAQUI_HTTPRESPONSE_H diff --git a/Server/src/httpheaders.cpp b/Server/src/httpheaders.cpp new file mode 100644 index 0000000..d0736b2 --- /dev/null +++ b/Server/src/httpheaders.cpp @@ -0,0 +1,99 @@ +// 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 Nov 1 00:46:53 ART 2003 +// Autores: Leandro Lucarella +//---------------------------------------------------------------------------- +// +// $Id$ +// + +#include "plaqui/server/httpheaders.h" +//#include +#ifdef DEBUG +# include +#endif // DEBUG + +PlaQui::Server::HTTPHeaders::~HTTPHeaders(void) { +#ifdef DEBUG + std::cerr << __FILE__ << ": destructor." << std::endl; +#endif // DEBUG +} +/* +PlaQui::Server::HTTPMessage::HTTPMessage(const std::string& http_version): + http_version(http_version) { +#ifdef DEBUG + std::cerr << __FILE__ << ": http_version = " << http_version << std::endl; +#endif // DEBUG +} + +PlaQui::Server::HTTPMessage::HTTPMessage(const std::string& _body, + const std::string& http_version): + http_version(http_version) { +#ifdef DEBUG + std::cerr << __FILE__ << ": http_version = " << http_version + << " | body = " << body << std::endl; +#endif // DEBUG + set_body(_body); +} +*/ +ostream& operator<<(std::ostream& os, PlaQui::Server::HTTPMessage) { +#ifdef DEBUG + std::cerr << __FILE__ << ": operator<<()" << std::endl; +#endif // DEBUG + for (HTTPMessage::const_iterator i = begin(); i != end(); ++i) { + os << i->first << ": " << i->second << std::flush; + return os << headers << "\r\l" // Fin de cabeceras +} + +istream& operator>>(std::istream& is, PlaQui::Server::HTTPMessage) { +#ifdef DEBUG + std::cerr << __FILE__ << ": operator>>()" << std::endl; +#endif // DEBUG + char buf[BUFSIZ]; + bool is_header = true; + stringstream body_ss; + while (is.getline(buf, BUFSIZ)) { + std::string sbuf = buf; + if (sbuf.length()) + if (is_header) { + // TODO esto va al operator>> de HTTPHeaders. + std::string::size_type pos = sbuf.find(":"); + if (pos == std::string::npos) { + // FIXME poner mejores excepciones. + throw "Wrong header"; + } + headers[sbuf.substr(0, pos)] = sbuf.substr(pos + 1); + } else { + body_ss << buf << std::endl; + } + } else { + if (is_header) { + is_header = false; + } else { + body_ss << buf << std::endl; + } + } + } + // TODO El body debería leer solo el content-length. + body = body_ss.str(); + return is; +} + diff --git a/Server/src/httpmessage.cpp b/Server/src/httpmessage.cpp new file mode 100644 index 0000000..625d82e --- /dev/null +++ b/Server/src/httpmessage.cpp @@ -0,0 +1,111 @@ +// 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: dom oct 26 22:02:09 ART 2003 +// Autores: Leandro Lucarella +//---------------------------------------------------------------------------- +// +// $Id$ +// + +#include "plaqui/server/httpmessage.h" +#include +#ifdef DEBUG +# include +#endif // DEBUG + +PlaQui::Server::HTTPMessage::~HTTPMessage(void) { +#ifdef DEBUG + std::cerr << __FILE__ << ": destructor." << std::endl; +#endif // DEBUG +} + +PlaQui::Server::HTTPMessage::HTTPMessage(const std::string& http_version): + http_version(http_version) { +#ifdef DEBUG + std::cerr << __FILE__ << ": http_version = " << http_version << std::endl; +#endif // DEBUG +} + +PlaQui::Server::HTTPMessage::HTTPMessage(const std::string& _body, + const std::string& http_version): + http_version(http_version) { +#ifdef DEBUG + std::cerr << __FILE__ << ": http_version = " << http_version + << " | body = " << body << std::endl; +#endif // DEBUG + set_body(_body); +} + +void PlaQui::Server::HTTPMessage::set_body(const std::string& _body) { + body = _body; + if (body.length()) { + stringstream ss; // TODO ver forma mas linda de convertir + ss << body.length(); + headers["Content-Length"] = ss.str(); + } +} + +const std::string& PlaQui::Server::HTTPMessage::get_body(void) { + return body; +} + +ostream& operator<<(std::ostream& os, PlaQui::Server::HTTPMessage) { +#ifdef DEBUG + std::cerr << __FILE__ << ": operator<<()" << std::endl; +#endif // DEBUG + return os << headers << "\r\l" // Fin de cabeceras + << body << std::flush; +} + +istream& operator>>(std::istream& is, PlaQui::Server::HTTPMessage) { +#ifdef DEBUG + std::cerr << __FILE__ << ": operator>>()" << std::endl; +#endif // DEBUG + char buf[BUFSIZ]; + bool is_header = true; + stringstream body_ss; + while (is.getline(buf, BUFSIZ)) { + std::string sbuf = buf; + if (sbuf.length()) + if (is_header) { + // TODO esto va al operator>> de HTTPHeaders. + std::string::size_type pos = sbuf.find(":"); + if (pos == std::string::npos) { + // FIXME poner mejores excepciones. + throw "Wrong header"; + } + headers[sbuf.substr(0, pos)] = sbuf.substr(pos + 1); + } else { + body_ss << buf << std::endl; + } + } else { + if (is_header) { + is_header = false; + } else { + body_ss << buf << std::endl; + } + } + } + // TODO si el body es un serializable, deberia auto deserializarse. + body = body_ss.str(); + return is; +} + diff --git a/Server/src/httprequest.cpp b/Server/src/httprequest.cpp new file mode 100644 index 0000000..4c28a51 --- /dev/null +++ b/Server/src/httprequest.cpp @@ -0,0 +1,151 @@ +// 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: dom oct 26 22:11:03 ART 2003 +// Autores: Leandro Lucarella +//---------------------------------------------------------------------------- +// +// $Id$ +// + +#include "plaqui/server/httprequest.h" +#include "plaqui/server/string.h" +#ifdef DEBUG +# include +#endif // DEBUG + +PlaQui::Server::HTTPRequest::~HTTPRequest(void) { +#ifdef DEBUG + std::cerr << __FILE__ << ": destructor." << std::endl; +#endif // DEBUG +} + +PlaQui::Server::HTTPRequest::HTTPRequest(const std::string& version): + PlaQui::Server::HTTPMessage(version) { +#ifdef DEBUG + std::cerr << __FILE__ << ": http_version = " << http_version << std::endl; +#endif // DEBUG +} + +PlaQui::Server::HTTPRequest::HTTPRequest(const Serializable& body, + const std::string& version): + PlaQui::Server::HTTPMessage(body, version) { +#ifdef DEBUG + std::cerr << __FILE__ << ": http_version = " << http_version + << " | body = " << body.serialize() << std::endl; +#endif // DEBUG +} + +PlaQui::Server::HTTPRequest::HTTPRequest(const std::string& uri, + const PlaQui::Server::HTTPRequest::HTTPMethod& method, + std::string& query, std::string& version): + PlaQui::Server::HTTPMessage(body, version) { +#ifdef DEBUG + std::cerr << __FILE__ << ": http_version = " << http_version + << " | body = " << body.serialize() << std::endl; +#endif // DEBUG +} + +void PlaQui::Server::HTTPRequest::serialize(std::ostream& os) { +#ifdef DEBUG + std::cerr << __FILE__ << ": serialize()" << std::endl; +#endif // DEBUG + os << method << " " << uri; + if (query_string.length()) { + os << "?" << query; + } + os << "HTTP/" << version << "\r\l" << std::flush; // TODO ver que este bien el \r\l + HTTPMessage::serilize(os); + if (headers.size()) { + headers.serilize(os); + } + os << "\r\l" << std::flush; + if (body.size()) { + body.serilize(os); + } +} + +void PlaQui::Server::HTTPRequest::unserialize(std::istream& is) { + const unsigned BUFFER_SIZE = 4096; + char buf[BUFFER_SIZE]; + // Obtengo primera línea (request) + is.getline(buf, BUFFER_SIZE); +#ifdef DEBUG + std::cerr << "Recibiendo linea: " << buf << std::endl; +#endif // DEBUG + String line = buf; + // Si es la primera línea, es el request. + if (line.length() < 3) { + // FIXME - poner excepciones lindas. + throw "HTTP/1.1 501 Method Not Implemented"; + } + // Averiguo método. + std::string::size_type pos = line.find_first_of(String::SPACE_CHARS); + String met = line.substr(0, pos); + if (met.to_upper() == "GET") { + method = GET; + } else if (met.to_upper() == "POST") { + method = POST; + } else { + // FIXME - poner excepciones lindas. + throw "HTTP/1.1 501 Method Not Implemented"; + } + // Si tiene sólo el método, no es válido. + line = line.substr(pos + 1); + iine.trim(); + if (!line.length()) { + // FIXME - poner excepciones lindas. + throw "HTTP/1.1 400 Bad Request"; + } + // Si tiene más espacios, tengo la URI y el protocolo (o un error). + pos = line.find_first_of(String::SPACE_CHARS); + if (pos != std::string::npos) { + // Si el resto es un protocolo válido, agrego más variables. + String protocol = line.substr(pos + 1); + protocol = protocol.trim(); + if (protocol.to_upper() == "HTTP/1.0") { + version = "1.0"; + } else if (protocol.to_upper() == "HTTP/1.1") { + version = "1.1"; + // Si no es un error. + } else { + // FIXME - poner excepciones lindas. + throw "HTTP/1.1 400 Bad Request"; + } + line = line.substr(0, pos); + } + // Agrego la URI y sus derivados. + if (!line.length() || (line[0] != '/')) { + // FIXME || request.find_first_not_of(";/?:@&=+$,")) { + // FIXME - poner excepciones lindas. + throw "HTTP/1.1 400 Bad Request"; + } + // Si tiene un query string. + pos = request.find("?"); + if (pos != std::string::npos) { + query = line.substr(pos + 1); + } else { + query = ""; + } + uri = line.substr(0, pos); + // Fin de request, obtengo cabeceras y cuerpo. + HTTPMessage::unserialize(is); +} + diff --git a/Server/src/tcpserver.cpp b/Server/src/tcpserver.cpp index a7b3dc7..861b6ee 100644 --- a/Server/src/tcpserver.cpp +++ b/Server/src/tcpserver.cpp @@ -65,7 +65,6 @@ void PlaQui::Server::TCPServer::on_connection_finished( << connection << ")" << std::endl; #endif // DEBUG Glib::Mutex::Lock lock(connections_mutex); - // XXX connections_mutex.lock(); connections.remove(connection); #ifdef DEBUG std::cerr << __FILE__ << ": lista de conexiones" << std::endl; @@ -74,7 +73,6 @@ void PlaQui::Server::TCPServer::on_connection_finished( std::cerr << "\t " << *i << std::endl; } #endif // DEBUG - // XXX connections_mutex.unlock(); } /// \todo TODO: ver tema de timeout o como salir de un accept(). @@ -91,6 +89,7 @@ void PlaQui::Server::TCPServer::real_run(void) { << std::endl; #endif // DEBUG Glib::Mutex::Lock lock(connections_mutex); + // XXX connections_mutex.lock(); connections.push_back(connection); #ifdef DEBUG std::cerr << __FILE__ << ": real_run(): lista de conexiones" << std::endl; @@ -99,6 +98,7 @@ void PlaQui::Server::TCPServer::real_run(void) { std::cerr << "\t " << *i << std::endl; } #endif // DEBUG + // XXX connections_mutex.unlock(); // Si pongo el mutex antes del run(), muere. // Conecto la señal para cuando termina una conexión, borrarla. connection->signal_finished().connect( SigC::bind( @@ -106,7 +106,6 @@ void PlaQui::Server::TCPServer::real_run(void) { &TCPServer::on_connection_finished), connection)); connection->run(); - //connections_mutex.unlock(); // Si pongo el mutex antes del run(), muere. } } -- 2.43.0