Permalink
Browse files

node: use shared_ptr to manage Sockets

  • Loading branch information...
aberaud committed Dec 2, 2017
1 parent f9d48cd commit d2f91af946ebcf9ba83279057db0deb2ed388325
Showing with 5 additions and 5 deletions.
  1. +2 −2 include/opendht/node.h
  2. +3 −3 src/node.cpp
View
@@ -117,7 +117,7 @@ struct Node {
*/
Tid openSocket(SocketCb&& cb);
Socket* getSocket(Tid id);
Sp<Socket> getSocket(Tid id);
/**
* Closes a socket so that no further data will be red on that socket.
@@ -167,7 +167,7 @@ struct Node {
using TransactionDist = std::uniform_int_distribution<decltype(transaction_id)>;
std::map<Tid, Sp<net::Request>> requests_ {};
std::map<Tid, Socket> sockets_;
std::map<Tid, Sp<Socket>> sockets_;
};
}
View
@@ -134,18 +134,18 @@ Node::openSocket(SocketCb&& cb)
if (++transaction_id == 0)
transaction_id = 1;
auto sock = Socket(std::move(cb));
auto sock = std::make_shared<Socket>(std::move(cb));
auto s = sockets_.emplace(transaction_id, std::move(sock));
if (not s.second)
s.first->second = std::move(sock);
return transaction_id;
}
Socket*
Sp<Socket>
Node::getSocket(Tid id)
{
auto it = sockets_.find(id);
return it == sockets_.end() ? nullptr : &it->second;
return it == sockets_.end() ? nullptr : it->second;
}
void

0 comments on commit d2f91af

Please sign in to comment.