Skip to content

Commit

Permalink
Fix #11
Browse files Browse the repository at this point in the history
  • Loading branch information
WagnerMarcos committed Nov 24, 2020
1 parent d8295f0 commit c5c8e0d
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 10 deletions.
2 changes: 1 addition & 1 deletion common_src/resource.cpp
Original file line number Diff line number Diff line change
@@ -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();
Expand Down
7 changes: 3 additions & 4 deletions common_src/socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 0 additions & 2 deletions common_src/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 3 additions & 2 deletions common_src/socketError.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
#include <errno.h>
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 {}
Expand Down
3 changes: 2 additions & 1 deletion server_src/protectedResources.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ void ProtectedResources::post_resource(Resource& r){
std::lock_guard<std::mutex> 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<std::mutex> l(m);
std::map<std::string, Resource>::iterator it;
it = resources.find(resource_name);
Expand Down

0 comments on commit c5c8e0d

Please sign in to comment.