eran redundantes y se mejoran algunos mensajes de DEBUG.
}
PlaQui::Server::ControlClient::ControlClient(std::string host, int port):
- PlaQui::Server::Connection(sockbuf::sock_stream) {
+ Connection(sockbuf::sock_stream) {
#ifdef DEBUG
std::cerr << __FILE__ << ": host" << host
<< " | port = " << port << std::endl;
}
PlaQui::Server::ControlServer::ControlServer(const sockbuf::sockdesc& sd):
- PlaQui::Server::ServerConnection(sd) {
+ ServerConnection(sd) {
#ifdef DEBUG
std::cerr << __FILE__ << ": sd = " << sd.sock << std::endl;
#endif // DEBUG
}
PlaQui::Server::Receiver::Receiver(int port, std::string host):
- PlaQui::Server::ServerConnection(sockbuf::sock_dgram) {
+ ServerConnection(sockbuf::sock_dgram) {
#ifdef DEBUG
std::cerr << __FILE__ << ": port = " << port
<< " | host = " << host << std::endl;
std::cerr << __FILE__ << ": req = " << req << " | host = " << host
<< " | port = " << port << std::endl;
#endif // DEBUG
- PlaQui::Server::String request(req);
+ String request(req);
(*this)["REMOTE_HOST"] = host;
std::stringstream ss;
ss << port;
throw "HTTP/1.1 501 Method Not Implemented";
}
// Averiguo método.
- std::string::size_type pos = request.find_first_of(
- PlaQui::Server::String::SPACE_CHARS);
- PlaQui::Server::String method = request.substr(0, pos);
+ std::string::size_type pos = request.find_first_of(String::SPACE_CHARS);
+ String method = request.substr(0, pos);
if ((method.to_upper() == "GET") || (method.to_upper() == "POST")) {
(*this)["REQUEST_METHOD"] = method;
} else {
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(PlaQui::Server::String::SPACE_CHARS);
+ pos = request.find_first_of(String::SPACE_CHARS);
if (pos != std::string::npos) {
// Si el resto es un protocolo válido, agrego más variables.
- PlaQui::Server::String protocol = request.substr(pos + 1);
+ String protocol = request.substr(pos + 1);
protocol = protocol.trim();
- if ((PlaQui::Server::String(protocol).to_upper() == "HTTP/1.0")
- || (PlaQui::Server::String(protocol).to_upper() == "HTTP/1.1")) {
+ if ((String(protocol).to_upper() == "HTTP/1.0")
+ || (String(protocol).to_upper() == "HTTP/1.1")) {
(*this)["SERVER_PROTOCOL"] = protocol;
// Si no es un error.
} else {
PlaQui::Server::Runnable::~Runnable(void) {
#ifdef DEBUG
- std::cerr << __FILE__ << ": destructor." << std::endl;
+ std::cerr << __FILE__ << ": destructor(this = " << this << ")"
+ << std::endl;
#endif // DEBUG
}
#endif // DEBUG
}
-void PlaQui::Server::Runnable::static_run(PlaQui::Server::Runnable* runner) {
+void PlaQui::Server::Runnable::static_run(Runnable* runner) {
#ifdef DEBUG
- std::cerr << __FILE__ << ": runner = " << runner << std::endl;
+ std::cerr << __FILE__ << ": static_run(runner = " << runner << ")"
+ << std::endl;
#endif // DEBUG
runner->real_run();
runner->signal_finished().emit();
void PlaQui::Server::Runnable::run(bool detach) {
#ifdef DEBUG
- std::cerr << __FILE__ << ": detach = " << detach << std::endl;
+ std::cerr << __FILE__ << ": run(detach = " << detach << ")" << std::endl;
#endif // DEBUG
// Si vamos a correr la tarea en un thread.
if (detach) {
// Corremos el thread en una funcion estática para poder destruirlo al
// finalizar, pasandole el puntero al objeto.
thread = Glib::Thread::create(
- SigC::bind<Runnable*>(
- SigC::slot(&PlaQui::Server::Runnable::static_run),
- this),
+ SigC::bind<Runnable*>(SigC::slot(&Runnable::static_run), this),
true);
// Si no corremos la tarea normalmente.
} else {
void PlaQui::Server::Runnable::finish(bool attach) {
#ifdef DEBUG
- std::cerr << __FILE__ << ": attach = " << attach << std::endl;
+ std::cerr << __FILE__ << ": finish(attach = " << attach << ")" << std::endl;
#endif // DEBUG
// TODO - necesita un mutex?
stop = true;
}
PlaQui::Server::Server::Server(int port):
- PlaQui::Server::TCPServer(port) {
+ TCPServer(port) {
#ifdef DEBUG
std::cerr << __FILE__ << ": port = " << port << std::endl;
#endif // DEBUG
return false;
}
-PlaQui::Server::Connection*
-PlaQui::Server::Server::new_connection(const sockbuf::sockdesc& sd) {
+PlaQui::Server::Connection* PlaQui::Server::Server::new_connection(
+ const sockbuf::sockdesc& sd) {
#ifdef DEBUG
std::cerr << __FILE__ << ": new_connection(sd = " << sd.sock << ")"
<< std::endl;
#endif // DEBUG
- PlaQui::Server::ControlServer* conn = new PlaQui::Server::ControlServer(sd);
+ ControlServer* connection = new ControlServer(sd);
// TODO verificar si el new se hace bien? no creo.
- conn->signal_command_received().connect(
- SigC::slot_class(*this,
- &PlaQui::Server::Server::on_control_command_received));
+ connection->signal_command_received().connect(
+ SigC::slot_class(*this, &Server::on_control_command_received));
// TODO:
- return conn;
+ return connection;
}
/// \todo Implementar.
}
PlaQui::Server::ServerConnection::ServerConnection(const sockbuf::sockdesc& sd):
- PlaQui::Server::Connection(sd) {
+ Connection(sd) {
#ifdef DEBUG
std::cerr << __FILE__ << ": sd = " << sd.sock << std::endl;
#endif // DEBUG
}
PlaQui::Server::ServerConnection::ServerConnection(sockbuf::type type):
- PlaQui::Server::Connection(type) {
+ Connection(type) {
#ifdef DEBUG
std::cerr << __FILE__ << ": type = " << type << std::endl;
#endif // DEBUG
}
void PlaQui::Server::TCPServer::on_connection_finished(
- PlaQui::Server::Connection* connection) {
+ Connection* connection) {
#ifdef DEBUG
std::cerr << __FILE__ << ": on_connection_finished(connection = "
<< connection << ")" << std::endl;
#endif // DEBUG
// TODO: poner lock.
connections.remove(connection);
+#ifdef DEBUG
+ std::cerr << __FILE__ << ": lista de conexiones" << std::endl;
+ for (ConnectionList::const_iterator i = connections.begin();
+ i != connections.end(); i++) {
+ std::cerr << "\t " << *i << std::endl;
+ }
+#endif // DEBUG
// TODO: sacar lock.
}
void PlaQui::Server::TCPServer::real_run(void) {
#ifdef DEBUG
- std::cerr << __FILE__ << ": real_run" << std::endl;
+ std::cerr << __FILE__ << ": real_run()" << std::endl;
#endif // DEBUG
- PlaQui::Server::Connection* conn;
+ Connection* connection;
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());
+ connection = new_connection(socket.accept());
+#ifdef DEBUG
+ std::cerr << __FILE__ << ": real_run(): connection = " << connection
+ << std::endl;
+#endif // DEBUG
// TODO: poner lock.
- connections.push_back(conn);
+ connections.push_back(connection);
+#ifdef DEBUG
+ std::cerr << __FILE__ << ": real_run(): lista de conexiones" << std::endl;
+ for (ConnectionList::const_iterator i = connections.begin();
+ i != connections.end(); i++) {
+ std::cerr << "\t " << *i << std::endl;
+ }
+#endif // DEBUG
// 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*>(
+ connection->signal_finished().connect(
+ SigC::bind<Connection*>(
SigC::slot_class(*this,
- &PlaQui::Server::TCPServer::on_connection_finished),
- conn));
- conn->run();
+ &TCPServer::on_connection_finished),
+ connection));
+ connection->run();
}
}
/// \todo debría conectarse en real_run() (?)
PlaQui::Server::Transmitter::Transmitter(std::string host, int port):
- PlaQui::Server::Connection(sockbuf::sock_dgram) {
+ Connection(sockbuf::sock_dgram) {
#ifdef DEBUG
std::cerr << __FILE__ << ": host = " << host
<< " | port = " << port << std::endl;