mirror of https://github.com/aria2/aria2
Peer: Use std::unique_ptr for res_
parent
6d2dd2ab18
commit
b759725a61
|
@ -53,7 +53,6 @@ Peer::Peer(std::string ipaddr, uint16_t port, bool incoming):
|
||||||
firstContactTime_(global::wallclock()),
|
firstContactTime_(global::wallclock()),
|
||||||
dropStartTime_(0),
|
dropStartTime_(0),
|
||||||
seeder_(false),
|
seeder_(false),
|
||||||
res_(nullptr),
|
|
||||||
incoming_(incoming),
|
incoming_(incoming),
|
||||||
localPeer_(false),
|
localPeer_(false),
|
||||||
disconnectedGracefully_(false)
|
disconnectedGracefully_(false)
|
||||||
|
@ -73,8 +72,7 @@ void Peer::usedBy(cuid_t cuid)
|
||||||
|
|
||||||
void Peer::allocateSessionResource(int32_t pieceLength, int64_t totalLength)
|
void Peer::allocateSessionResource(int32_t pieceLength, int64_t totalLength)
|
||||||
{
|
{
|
||||||
delete res_;
|
res_ = make_unique<PeerSessionResource>(pieceLength, totalLength);
|
||||||
res_ = new PeerSessionResource(pieceLength, totalLength);
|
|
||||||
res_->getNetStat().downloadStart();
|
res_->getNetStat().downloadStart();
|
||||||
updateSeeder();
|
updateSeeder();
|
||||||
}
|
}
|
||||||
|
@ -87,8 +85,7 @@ void Peer::reconfigureSessionResource(int32_t pieceLength, int64_t totalLength)
|
||||||
|
|
||||||
void Peer::releaseSessionResource()
|
void Peer::releaseSessionResource()
|
||||||
{
|
{
|
||||||
delete res_;
|
res_.reset();
|
||||||
res_ = nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Peer::setPeerId(const unsigned char* peerId)
|
void Peer::setPeerId(const unsigned char* peerId)
|
||||||
|
|
|
@ -74,7 +74,7 @@ private:
|
||||||
|
|
||||||
bool seeder_;
|
bool seeder_;
|
||||||
|
|
||||||
PeerSessionResource* res_;
|
std::unique_ptr<PeerSessionResource> res_;
|
||||||
|
|
||||||
// If true, port is assumed not to be a listening port.
|
// If true, port is assumed not to be a listening port.
|
||||||
bool incoming_;
|
bool incoming_;
|
||||||
|
@ -129,7 +129,7 @@ public:
|
||||||
// Returns true iff res_ != 0.
|
// Returns true iff res_ != 0.
|
||||||
bool isActive() const
|
bool isActive() const
|
||||||
{
|
{
|
||||||
return res_ != nullptr;
|
return res_.get() != nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setPeerId(const unsigned char* peerId);
|
void setPeerId(const unsigned char* peerId);
|
||||||
|
|
Loading…
Reference in New Issue