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 { ...@@ -288,49 +288,46 @@ class AsyncSocket : public AsyncTransport {
explicit AsyncSocket(AsyncSocket::UniquePtr); 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 * This passes in the correct destructor object, since AsyncSocket's
* destructor is protected and cannot be invoked directly. * destructor is protected and cannot be invoked directly.
*/ */
static std::shared_ptr<AsyncSocket> newSocket(EventBase* evb) { static UniquePtr newSocket(EventBase* evb) {
return std::shared_ptr<AsyncSocket>(new AsyncSocket(evb), Destructor()); 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, EventBase* evb,
const folly::SocketAddress& address, const folly::SocketAddress& address,
uint32_t connectTimeout = 0, uint32_t connectTimeout = 0,
bool useZeroCopy = false) { bool useZeroCopy = false) {
return std::shared_ptr<AsyncSocket>( return UniquePtr{new AsyncSocket(evb, address, connectTimeout, useZeroCopy),
new AsyncSocket(evb, address, connectTimeout, useZeroCopy), Destructor()};
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, EventBase* evb,
const std::string& ip, const std::string& ip,
uint16_t port, uint16_t port,
uint32_t connectTimeout = 0, uint32_t connectTimeout = 0,
bool useZeroCopy = false) { bool useZeroCopy = false) {
return std::shared_ptr<AsyncSocket>( return UniquePtr{
new AsyncSocket(evb, ip, port, connectTimeout, useZeroCopy), 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( static UniquePtr newSocket(EventBase* evb, NetworkSocket fd) {
EventBase* evb, return UniquePtr{new AsyncSocket(evb, fd), Destructor()};
NetworkSocket fd) {
return std::shared_ptr<AsyncSocket>(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