Bug 1261307: Convert Unix socket IPC code to |UniquePtr|, r=nfroyd

This commit is contained in:
Thomas Zimmermann 2016-04-05 13:40:11 +02:00
Родитель 24b3a392ed
Коммит d0fbe5c8f1
7 изменённых файлов: 39 добавлений и 16 удалений

Просмотреть файл

@ -79,7 +79,7 @@ private:
/**
* Connector object used to create the connection we are currently using.
*/
nsAutoPtr<UnixSocketConnector> mConnector;
UniquePtr<UnixSocketConnector> mConnector;
/**
* Number of valid bytes in |mPeerAddress|.

Просмотреть файл

@ -10,6 +10,7 @@
#include "DataSocket.h"
#include "ListenSocketConsumer.h"
#include "mozilla/RefPtr.h"
#include "mozilla/unused.h"
#include "nsISupportsImpl.h" // for MOZ_COUNT_CTOR, MOZ_COUNT_DTOR
#include "nsXULAppAPI.h"
#include "UnixSocketConnector.h"
@ -76,7 +77,7 @@ private:
/**
* Connector object used to create the connection we are currently using.
*/
nsAutoPtr<UnixSocketConnector> mConnector;
UniquePtr<UnixSocketConnector> mConnector;
/**
* If true, do not requeue whatever task we're running
@ -125,7 +126,7 @@ ListenSocketIO::~ListenSocketIO()
UnixSocketConnector*
ListenSocketIO::GetConnector() const
{
return mConnector;
return mConnector.get();
}
void
@ -360,27 +361,28 @@ ListenSocket::Listen(ConnectionOrientedSocket* aCOSocket)
// We first prepare the connection-oriented socket with a
// socket connector and a socket I/O class.
nsAutoPtr<UnixSocketConnector> connector;
nsresult rv = mIO->GetConnector()->Duplicate(*connector.StartAssignment());
UniquePtr<UnixSocketConnector> connector;
nsresult rv = mIO->GetConnector()->Duplicate(connector);
if (NS_FAILED(rv)) {
return rv;
}
nsAutoPtr<ConnectionOrientedSocketIO> io;
rv = aCOSocket->PrepareAccept(connector,
ConnectionOrientedSocketIO* io;
rv = aCOSocket->PrepareAccept(connector.get(),
mIO->GetConsumerThread(), mIO->GetIOLoop(),
*io.StartAssignment());
io);
if (NS_FAILED(rv)) {
return rv;
}
connector.forget(); // now owned by |io|
Unused << connector.release(); // now owned by |io|
// Then we start listening for connection requests.
SetConnectionStatus(SOCKET_LISTENING);
mIO->GetIOLoop()->PostTask(
FROM_HERE, new ListenSocketIO::ListenTask(mIO, io.forget()));
FROM_HERE, new ListenSocketIO::ListenTask(mIO, io));
return NS_OK;
}

Просмотреть файл

@ -403,7 +403,7 @@ SocketDeleteInstanceTask::~SocketDeleteInstanceTask()
void
SocketDeleteInstanceTask::Run()
{
mIO = nullptr; // delete instance
mIO.reset(); // delete instance
}
//

Просмотреть файл

@ -10,7 +10,6 @@
#define mozilla_ipc_SocketBase_h
#include "base/message_loop.h"
#include "nsAutoPtr.h"
#include "mozilla/UniquePtr.h"
namespace mozilla {
@ -523,7 +522,7 @@ public:
void Run() override;
private:
nsAutoPtr<SocketIOBase> mIO;
UniquePtr<SocketIOBase> mIO;
};
//

Просмотреть файл

@ -89,7 +89,7 @@ private:
/**
* I/O buffer for received data
*/
nsAutoPtr<UnixSocketRawData> mBuffer;
UniquePtr<UnixSocketRawData> mBuffer;
};
StreamSocketIO::StreamSocketIO(MessageLoop* aConsumerLoop,
@ -182,7 +182,7 @@ StreamSocketIO::QueryReceiveBuffer(UnixSocketIOBuffer** aBuffer)
MOZ_ASSERT(aBuffer);
if (!mBuffer) {
mBuffer = new UnixSocketRawData(MAX_READ_SIZE);
mBuffer = MakeUnique<UnixSocketRawData>(MAX_READ_SIZE);
}
*aBuffer = mBuffer.get();
@ -234,7 +234,7 @@ void
StreamSocketIO::ConsumeBuffer()
{
GetConsumerThread()->PostTask(FROM_HERE,
new ReceiveTask(this, mBuffer.forget()));
new ReceiveTask(this, mBuffer.release()));
}
void

Просмотреть файл

@ -20,5 +20,19 @@ UnixSocketConnector::~UnixSocketConnector()
MOZ_COUNT_DTOR(UnixSocketConnector);
}
nsresult
UnixSocketConnector::Duplicate(UniquePtr<UnixSocketConnector>& aConnector)
{
UnixSocketConnector* connectorPtr;
auto rv = Duplicate(connectorPtr);
if (NS_FAILED(rv)) {
return rv;
}
aConnector = Move(UniquePtr<UnixSocketConnector>(connectorPtr));
return NS_OK;
}
}
}

Просмотреть файл

@ -84,6 +84,14 @@ public:
*/
virtual nsresult Duplicate(UnixSocketConnector*& aConnector) = 0;
/**
* Copies the instance of |UnixSocketConnector|. I/O thread only.
*
* @param[in] aConnector Returns a new instance of the connector class
* @return NS_OK on success, or an XPCOM error code otherwise
*/
nsresult Duplicate(UniquePtr<UnixSocketConnector>& aConnector);
protected:
UnixSocketConnector();
};