From c5c8e0d204d6a0c5671bdf0ac1d72c5da6681114 Mon Sep 17 00:00:00 2001 From: wagnermarcos Date: Tue, 24 Nov 2020 10:40:01 -0300 Subject: [PATCH] Fix #11 --- common_src/resource.cpp | 2 +- common_src/socket.cpp | 7 +++---- common_src/socket.h | 2 -- common_src/socketError.h | 5 +++-- server_src/protectedResources.cpp | 3 ++- 5 files changed, 9 insertions(+), 10 deletions(-) diff --git a/common_src/resource.cpp b/common_src/resource.cpp index 999e84c..b4d3531 100644 --- a/common_src/resource.cpp +++ b/common_src/resource.cpp @@ -1,7 +1,7 @@ #include "resource.h" Resource& Resource::operator=(const Resource& r){ - if(this == &r) + if (this == &r) return *this; method = r.method.data(); path = r.path.data(); diff --git a/common_src/socket.cpp b/common_src/socket.cpp index 03fb17e..f7b6222 100644 --- a/common_src/socket.cpp +++ b/common_src/socket.cpp @@ -67,7 +67,7 @@ Socket Socket::accept(){ if (errno == 22) throw AcceptorClosed("Se cerrĂ³ el socket aceptador."); else - throw SocketError(); + throw SocketError("Error en socket.accept()."); } return std::move(Socket(accepted_fd)); } @@ -126,10 +126,9 @@ int Socket::receive(char *buffer, size_t buf_l, int r = 0; r = ::recv(fd, &buffer[bytes_recv], buf_l - bytes_recv, 0); if (r < 0){ - sckt_open = false; - return ERROR; + throw SocketError("Error en socket.receive()"); }else if (r == 0){ - sckt_open = false; + false; }else{ bytes_recv += r; } diff --git a/common_src/socket.h b/common_src/socket.h index 4c2f3a9..df5bafa 100644 --- a/common_src/socket.h +++ b/common_src/socket.h @@ -19,10 +19,8 @@ class Socket{ Socket(); ~Socket(); Socket(Socket&& socket); - // int socket_init(); void shutdown_read(); void shutdown_writing(); - // void close(); int bind_and_listen(const char *service); Socket accept(); int connect(const char *host_name, const char *service); diff --git a/common_src/socketError.h b/common_src/socketError.h index c5379ad..0f09743 100644 --- a/common_src/socketError.h +++ b/common_src/socketError.h @@ -6,9 +6,10 @@ #include class SocketError : public std::exception { public: - SocketError(){ + SocketError(std::string msg){ _errno = errno; - error_msg = std::string(strerror(_errno)); + error_msg = msg + "\nstrerror(errno): "; + error_msg += std::string(strerror(_errno)); } virtual ~SocketError() noexcept {} diff --git a/server_src/protectedResources.cpp b/server_src/protectedResources.cpp index 0460054..3b38ae1 100644 --- a/server_src/protectedResources.cpp +++ b/server_src/protectedResources.cpp @@ -4,7 +4,8 @@ void ProtectedResources::post_resource(Resource& r){ std::lock_guard l(m); resources[r.get_resource_path()] = r; } -void ProtectedResources::get_body(const std::string &resource_name, std::string& body){ +void ProtectedResources::get_body(const std::string &resource_name, + std::string& body){ std::lock_guard l(m); std::map::iterator it; it = resources.find(resource_name);