mirror of
https://github.com/savoirfairelinux/opendht.git
synced 2026-11-08 04:21:51 +00:00
network engine: move socket management to Node
This commit is contained in:
1 parent
bdb0bef0ee
commit
be7494961c
5 files changed
+83
-78
No files matched your search
@@ -104,9 +104,38 @@ Node::setExpired()
|
||||
r->setExpired();
|
||||
}
|
||||
requests_.clear();
|
||||
sockets_.clear();
|
||||
}
|
||||
|
||||
|
||||
Sp<net::Socket>
|
||||
Node::openSocket(const net::TransId& tid, net::SocketCb&& cb)
|
||||
{
|
||||
auto s = sockets_.emplace(tid, std::make_shared<net::Socket>(tid, cb));
|
||||
//if (not s.second)
|
||||
// DHT_LOG.e(id, "[node %s] socket (tid: %d) already opened!", id.toString().c_str(), tid.toInt());
|
||||
//else
|
||||
// DHT_LOG.w("Opened socket (tid: %d), %lu opened", s.first->second->id, sockets_.size());
|
||||
return s.first->second;
|
||||
}
|
||||
|
||||
|
||||
Sp<net::Socket>
|
||||
Node::getSocket(const net::TransId& tid) const
|
||||
{
|
||||
auto it = sockets_.find(tid);
|
||||
return it == sockets_.end() ? nullptr : it->second;
|
||||
}
|
||||
|
||||
void
|
||||
Node::closeSocket(const Sp<net::Socket>& socket)
|
||||
{
|
||||
if (socket) {
|
||||
sockets_.erase(socket->id);
|
||||
//DHT_LOG.w("Closing socket (tid: %d), %lu remaining", socket->id, sockets_.size());
|
||||
}
|
||||
}
|
||||
|
||||
std::string
|
||||
Node::toString() const
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user