|
@@ -55,7 +55,7 @@ LpdMessageReceiver::~LpdMessageReceiver() {}
|
|
|
bool LpdMessageReceiver::init(const std::string& localAddr)
|
|
|
{
|
|
|
try {
|
|
|
- socket_.reset(new SocketCore(SOCK_DGRAM));
|
|
|
+ socket_ = std::make_shared<SocketCore>(SOCK_DGRAM);
|
|
|
#ifdef __MINGW32__
|
|
|
// Binding multicast address fails under Windows.
|
|
|
socket_->bindWithFamily(multicastPort_, AF_INET);
|
|
@@ -77,9 +77,8 @@ bool LpdMessageReceiver::init(const std::string& localAddr)
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
-std::shared_ptr<LpdMessage> LpdMessageReceiver::receiveMessage()
|
|
|
+std::unique_ptr<LpdMessage> LpdMessageReceiver::receiveMessage()
|
|
|
{
|
|
|
- std::shared_ptr<LpdMessage> msg;
|
|
|
while(1) {
|
|
|
unsigned char buf[200];
|
|
|
std::pair<std::string, uint16_t> peerAddr;
|
|
@@ -87,11 +86,11 @@ std::shared_ptr<LpdMessage> LpdMessageReceiver::receiveMessage()
|
|
|
try {
|
|
|
length = socket_->readDataFrom(buf, sizeof(buf), peerAddr);
|
|
|
if(length == 0) {
|
|
|
- return msg;
|
|
|
+ return std::unique_ptr<LpdMessage>{};
|
|
|
}
|
|
|
} catch(RecoverableException& e) {
|
|
|
A2_LOG_INFO_EX("Failed to receive LPD message.", e);
|
|
|
- return msg;
|
|
|
+ return std::unique_ptr<LpdMessage>{};
|
|
|
}
|
|
|
HttpHeaderProcessor proc(HttpHeaderProcessor::SERVER_PARSER);
|
|
|
try {
|
|
@@ -103,7 +102,7 @@ std::shared_ptr<LpdMessage> LpdMessageReceiver::receiveMessage()
|
|
|
A2_LOG_INFO_EX("Failed to parse LPD message.", e);
|
|
|
continue;
|
|
|
}
|
|
|
- const std::shared_ptr<HttpHeader>& header = proc.getResult();
|
|
|
+ auto header = proc.getResult();
|
|
|
const std::string& infoHashString = header->find(HttpHeader::INFOHASH);
|
|
|
uint32_t port = 0;
|
|
|
if(!util::parseUIntNoThrow(port, header->find(HttpHeader::PORT)) ||
|
|
@@ -123,12 +122,11 @@ std::shared_ptr<LpdMessage> LpdMessageReceiver::receiveMessage()
|
|
|
infoHashString.c_str()));
|
|
|
continue;
|
|
|
}
|
|
|
- std::shared_ptr<Peer> peer(new Peer(peerAddr.first, port, false));
|
|
|
+ auto peer = std::make_shared<Peer>(peerAddr.first, port, false);
|
|
|
if(util::inPrivateAddress(peerAddr.first)) {
|
|
|
peer->setLocalPeer(true);
|
|
|
}
|
|
|
- msg.reset(new LpdMessage(peer, infoHash));
|
|
|
- return msg;
|
|
|
+ return make_unique<LpdMessage>(peer, infoHash);
|
|
|
}
|
|
|
}
|
|
|
|