Skip to content

Commit

Permalink
Merge pull request #47 from DICL/fix-dfsrm
Browse files Browse the repository at this point in the history
The bug was that when client disconnect, socket pointer was not freed
  • Loading branch information
vicentebolea committed Mar 15, 2016
2 parents 9e7d0a5 + e7985c6 commit 97be0f3
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,4 @@ m4/ltoptions.m4
m4/ltsugar.m4
m4/ltversion.m4
m4/lt~obsolete.m4
m4/pkg.m4
12 changes: 12 additions & 0 deletions src/fs/dfsrm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ int main(int argc, char* argv[])

send_message(socket, &fr);
auto fd = read_fd(socket);
socket->close();
delete socket;

unsigned int block_seq = 0;
for (auto block_name : fd->nodes) {
Expand All @@ -110,19 +112,29 @@ int main(int argc, char* argv[])
auto msg = read_reply(tmp_socket);
if (msg->message != "OK") {
cerr << "[ERROR]: block " << block_name << "doesn't exist" << endl;
delete msg;
return EXIT_FAILURE;
}
delete msg;

tmp_socket->close();
delete tmp_socket;
}
delete fd;

FileDel file_del;
file_del.file_name = file_name;
socket = connect(file_hash_key);
send_message(socket, &file_del);
auto reply = read_reply(socket);
if (reply->message != "OK") {
cerr << "[ERROR]: file " << file_name << " does not exist" << endl;
delete reply;
return EXIT_FAILURE;
}
delete reply;
socket->close();
delete socket;
/*
if (reply->message != "OK") {
{
Expand Down
3 changes: 3 additions & 0 deletions src/network/server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ void Server::do_connect () {
// }}}
// on_accept {{{
void Server::on_accept (tcp::socket* sock) {
if (server != nullptr) delete server;
server = sock;
do_read();
}
Expand Down Expand Up @@ -89,6 +90,8 @@ void Server::read_coroutine (yield_context yield) {
if (ec == boost::asio::error::eof) {
logger->info ("Closing server socket to client");
server->close();
delete server;
server = nullptr;
node->on_disconnect();
} else {
logger->info ("Message arrived error=%s",
Expand Down
2 changes: 1 addition & 1 deletion src/network/server.hh
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Server: public AsyncChannel {
void do_read ();
void read_coroutine (boost::asio::yield_context);

tcp::socket *server;
tcp::socket *server = nullptr;
tcp::endpoint* endpoint = nullptr;
};

Expand Down

0 comments on commit 97be0f3

Please sign in to comment.