Commit 2f0542e4 authored by Chad Austin's avatar Chad Austin Committed by Facebook GitHub Bot

change AsyncSocket::newSocket to return a unique_ptr instead of shared_ptr

Summary: If the caller wants a shared_ptr, UniquePtr will implicitly promote.

Reviewed By: yfeldblum

Differential Revision: D22046594

fbshipit-source-id: 2e7d527d3ca33dae974c62db909df605c532ea44
parent c19c06e5
......@@ -288,49 +288,46 @@ class AsyncSocket : public AsyncTransport {
explicit AsyncSocket(AsyncSocket::UniquePtr);
/**
* Helper function to create a shared_ptr<AsyncSocket>.
* Helper function to create an AsyncSocket..
*
* This passes in the correct destructor object, since AsyncSocket's
* destructor is protected and cannot be invoked directly.
*/
static std::shared_ptr<AsyncSocket> newSocket(EventBase* evb) {
return std::shared_ptr<AsyncSocket>(new AsyncSocket(evb), Destructor());
static UniquePtr newSocket(EventBase* evb) {
return UniquePtr{new AsyncSocket(evb), Destructor()};
}
/**
* Helper function to create a shared_ptr<AsyncSocket>.
* Helper function to create an AsyncSocket.
*/
static std::shared_ptr<AsyncSocket> newSocket(
static UniquePtr newSocket(
EventBase* evb,
const folly::SocketAddress& address,
uint32_t connectTimeout = 0,
bool useZeroCopy = false) {
return std::shared_ptr<AsyncSocket>(
new AsyncSocket(evb, address, connectTimeout, useZeroCopy),
Destructor());
return UniquePtr{new AsyncSocket(evb, address, connectTimeout, useZeroCopy),
Destructor()};
}
/**
* Helper function to create a shared_ptr<AsyncSocket>.
* Helper function to create an AsyncSocket.
*/
static std::shared_ptr<AsyncSocket> newSocket(
static UniquePtr newSocket(
EventBase* evb,
const std::string& ip,
uint16_t port,
uint32_t connectTimeout = 0,
bool useZeroCopy = false) {
return std::shared_ptr<AsyncSocket>(
return UniquePtr{
new AsyncSocket(evb, ip, port, connectTimeout, useZeroCopy),
Destructor());
Destructor()};
}
/**
* Helper function to create a shared_ptr<AsyncSocket>.
* Helper function to create an AsyncSocket.
*/
static std::shared_ptr<AsyncSocket> newSocket(
EventBase* evb,
NetworkSocket fd) {
return std::shared_ptr<AsyncSocket>(new AsyncSocket(evb, fd), Destructor());
static UniquePtr newSocket(EventBase* evb, NetworkSocket fd) {
return UniquePtr{new AsyncSocket(evb, fd), Destructor()};
}
/**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment