Skip to content

Commit

Permalink
Corregido issue #3
Browse files Browse the repository at this point in the history
  • Loading branch information
SBen-IV committed Nov 23, 2020
1 parent f8bcd56 commit de7f373
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 9 deletions.
13 changes: 13 additions & 0 deletions common_src/RecursosProtected.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include "RecursosProtected.h"

RecursosProtected::RecursosProtected(const char* _archivo_raiz) :
recursos(_archivo_raiz) {}

std::string RecursosProtected::obtenerRespuesta(const std::string& metodo,
const std::string& recurso,
const std::string& contenido) {
std::lock_guard<std::mutex> lock(this->m);
return this->recursos.obtenerRespuesta(metodo, recurso, contenido);
}

RecursosProtected::~RecursosProtected() {}
21 changes: 21 additions & 0 deletions common_src/RecursosProtected.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#ifndef RECURSOSPROTECTED_H
#define RECURSOSPROTECTED_H

#include <mutex>
#include <string>

#include "Recursos.h"

class RecursosProtected {
private:
Recursos recursos;
std::mutex m;
public:
explicit RecursosProtected(const char* _archivo_raiz);
std::string obtenerRespuesta(const std::string& metodo,
const std::string& recurso,
const std::string& contenido);
~RecursosProtected();
};

#endif
4 changes: 2 additions & 2 deletions server_src/GestorDeClientes.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@

#include "ThCliente.h"
#include "../common_src/Socket.h"
#include "../common_src/Recursos.h"
#include "../common_src/RecursosProtected.h"

//GestroDeClientes se encarga de ir aceptando e inicializando los clientes
//que van llegando para ser atendidos.

class GestorDeClientes {
private:
Socket socket;
Recursos recursos;
RecursosProtected recursos;
std::atomic<bool> esta_conectado;
public:
GestorDeClientes(const char* puerto, const char* _archivo_raiz);
Expand Down
7 changes: 3 additions & 4 deletions server_src/ThCliente.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@
#define VACIO ""
#define TAM_BUFFER 5

ThCliente::ThCliente(Peer& _peer, Recursos& _recursos) :
esta_conectado(true),
recursos(_recursos),
peer(std::move(_peer)) {}
ThCliente::ThCliente(Peer& _peer, RecursosProtected& _recursos) :
esta_conectado(true), recursos(_recursos),
peer(std::move(_peer)) {}

void ThCliente::obtenerPetitorio(std::string& petitorio) {
char buffer[TAM_BUFFER] = VACIO;
Expand Down
6 changes: 3 additions & 3 deletions server_src/ThCliente.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@
#include "../common_src/Thread.h"
#include "../common_src/Peer.h"
#include "../common_src/Parser.h"
#include "../common_src/Recursos.h"
#include "../common_src/RecursosProtected.h"

//ThCliente hereda de Thread y se encarga de la comunicación con el cliente
//como un servidor.

class ThCliente : public Thread {
private:
std::atomic<bool> esta_conectado;
Recursos& recursos;
RecursosProtected& recursos;
Peer peer;
public:
ThCliente(Peer& _peer, Recursos& _recursos);
ThCliente(Peer& _peer, RecursosProtected& _recursos);
void run() override;
void stop() override;
bool termino() override;
Expand Down

0 comments on commit de7f373

Please sign in to comment.