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()),
|
||||
dropStartTime_(0),
|
||||
seeder_(false),
|
||||
res_(nullptr),
|
||||
incoming_(incoming),
|
||||
localPeer_(false),
|
||||
disconnectedGracefully_(false)
|
||||
|
@ -73,8 +72,7 @@ void Peer::usedBy(cuid_t cuid)
|
|||
|
||||
void Peer::allocateSessionResource(int32_t pieceLength, int64_t totalLength)
|
||||
{
|
||||
delete res_;
|
||||
res_ = new PeerSessionResource(pieceLength, totalLength);
|
||||
res_ = make_unique<PeerSessionResource>(pieceLength, totalLength);
|
||||
res_->getNetStat().downloadStart();
|
||||
updateSeeder();
|
||||
}
|
||||
|
@ -87,8 +85,7 @@ void Peer::reconfigureSessionResource(int32_t pieceLength, int64_t totalLength)
|
|||
|
||||
void Peer::releaseSessionResource()
|
||||
{
|
||||
delete res_;
|
||||
res_ = nullptr;
|
||||
res_.reset();
|
||||
}
|
||||
|
||||
void Peer::setPeerId(const unsigned char* peerId)
|
||||
|
|
|
@ -74,7 +74,7 @@ private:
|
|||
|
||||
bool seeder_;
|
||||
|
||||
PeerSessionResource* res_;
|
||||
std::unique_ptr<PeerSessionResource> res_;
|
||||
|
||||
// If true, port is assumed not to be a listening port.
|
||||
bool incoming_;
|
||||
|
@ -129,7 +129,7 @@ public:
|
|||
// Returns true iff res_ != 0.
|
||||
bool isActive() const
|
||||
{
|
||||
return res_ != nullptr;
|
||||
return res_.get() != nullptr;
|
||||
}
|
||||
|
||||
void setPeerId(const unsigned char* peerId);
|
||||
|
|
Loading…
Reference in New Issue