Use std::make_shared

pull/454/head
Tatsuhiro Tsujikawa 2015-06-11 21:25:19 +09:00
parent 2448a8660b
commit 2bbec1086d
4 changed files with 8 additions and 4 deletions

View File

@ -62,7 +62,7 @@ public:
// Receives LPD message and returns LpdMessage which contains
// sender(peer) and infohash. If no data is available on socket,
// returns std::shared_ptr<LpdMessage>(). If received data is bad,
// then returns std::shared_ptr<LpdMessage>(new LpdMessage())
// they are just skipped.
std::unique_ptr<LpdMessage> receiveMessage();
const std::shared_ptr<SocketCore>& getSocket() const

View File

@ -364,7 +364,7 @@ std::shared_ptr<SocketCore> SocketCore::acceptConnection() const
if(fd == (sock_t) -1) {
throw DL_ABORT_EX(fmt(EX_SOCKET_ACCEPT, errorMsg(errNum).c_str()));
}
auto sock = std::shared_ptr<SocketCore>(new SocketCore(fd, sockType_));
auto sock = std::make_shared<SocketCore>(fd, sockType_);
sock->setNonBlockingMode();
return sock;
}

View File

@ -111,9 +111,13 @@ private:
void setSockOpt(int level, int optname, void* optval, socklen_t optlen);
SocketCore(sock_t sockfd, int sockType);
public:
SocketCore(int sockType = SOCK_STREAM);
// Formally, private constructor, but made public to use with
// std::make_shared.
SocketCore(sock_t sockfd, int sockType);
~SocketCore();
sock_t getSockfd() const { return sockfd_; }

View File

@ -877,7 +877,7 @@ nextParam
template<typename T>
std::shared_ptr<T> copy(const std::shared_ptr<T>& a)
{
return std::shared_ptr<T>(new T(*a.get()));
return std::make_shared<T>(*a.get());
}
// This is a bit different from cookie_helper::domainMatch(). If