Bug 1170466: Inherit |ConnectionOrientedSocketIO| from |UnixSocketWatcher|, r=kmachulis

Inheriting |ConncetionOrientedSocketIO| from |UnixSocketWatcher| will
allow for sharing common I/O code of the sub-class.
This commit is contained in:
Thomas Zimmermann 2015-06-03 11:53:50 +02:00
Родитель 2b7bbbe4e4
Коммит bc636a00f4
4 изменённых файлов: 49 добавлений и 16 удалений

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

@ -13,7 +13,6 @@
#include "mozilla/ipc/BluetoothDaemonConnectionConsumer.h"
#include "mozilla/ipc/DataSocket.h"
#include "mozilla/ipc/UnixSocketConnector.h"
#include "mozilla/ipc/UnixSocketWatcher.h"
#include "nsTArray.h"
#include "nsXULAppAPI.h"
@ -201,9 +200,7 @@ BluetoothDaemonPDUConsumer::~BluetoothDaemonPDUConsumer()
// BluetoothDaemonConnectionIO
//
class BluetoothDaemonConnectionIO final
: public UnixSocketWatcher
, public ConnectionOrientedSocketIO
class BluetoothDaemonConnectionIO final : public ConnectionOrientedSocketIO
{
public:
BluetoothDaemonConnectionIO(nsIThread* aConsumerThread,
@ -262,8 +259,10 @@ BluetoothDaemonConnectionIO::BluetoothDaemonConnectionIO(
ConnectionStatus aConnectionStatus,
BluetoothDaemonConnection* aConnection,
BluetoothDaemonPDUConsumer* aConsumer)
: UnixSocketWatcher(aIOLoop, aFd, aConnectionStatus)
, ConnectionOrientedSocketIO(aConsumerThread)
: ConnectionOrientedSocketIO(aConsumerThread,
aIOLoop,
aFd,
aConnectionStatus)
, mConnection(aConnection)
, mConsumer(aConsumer)
, mShuttingDownOnIOThread(false)

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

@ -14,8 +14,19 @@ namespace ipc {
//
ConnectionOrientedSocketIO::ConnectionOrientedSocketIO(
nsIThread* aConsumerThread)
nsIThread* aConsumerThread,
MessageLoop* aIOLoop,
int aFd,
ConnectionStatus aConnectionStatus)
: DataSocketIO(aConsumerThread)
, UnixSocketWatcher(aIOLoop, aFd, aConnectionStatus)
{ }
ConnectionOrientedSocketIO::ConnectionOrientedSocketIO(
nsIThread* aConsumerThread,
MessageLoop* aIOLoop)
: DataSocketIO(aConsumerThread)
, UnixSocketWatcher(aIOLoop)
{ }
ConnectionOrientedSocketIO::~ConnectionOrientedSocketIO()

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

@ -9,6 +9,7 @@
#include <sys/socket.h>
#include "DataSocket.h"
#include "mozilla/ipc/UnixSocketWatcher.h"
class MessageLoop;
@ -23,15 +24,38 @@ class UnixSocketConnector;
* |ListenSocket| uses these classes to handle accepted sockets.
*/
class ConnectionOrientedSocketIO : public DataSocketIO
class ConnectionOrientedSocketIO
: public DataSocketIO
, public UnixSocketWatcher
{
public:
ConnectionOrientedSocketIO(nsIThread* aConsumerThread);
virtual ~ConnectionOrientedSocketIO();
virtual nsresult Accept(int aFd,
const struct sockaddr* aAddress,
socklen_t aAddressLength) = 0;
protected:
/**
* Constructs an instance of |ConnectionOrientedSocketIO|
*
* @param aConsumerThread The socket's consumer thread.
* @param aIOLoop The socket's I/O loop.
* @param aFd The socket file descriptor.
* @param aConnectionStatus The connection status for |aFd|.
*/
ConnectionOrientedSocketIO(nsIThread* aConsumerThread,
MessageLoop* aIOLoop,
int aFd, ConnectionStatus aConnectionStatus);
/**
* Constructs an instance of |ConnectionOrientedSocketIO|
*
* @param aConsumerThread The socket's consumer thread.
* @param aIOLoop The socket's I/O loop.
*/
ConnectionOrientedSocketIO(nsIThread* aConsumerThread,
MessageLoop* aIOLoop);
};
class ConnectionOrientedSocket : public DataSocket

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

@ -20,9 +20,7 @@ namespace ipc {
// StreamSocketIO
//
class StreamSocketIO final
: public UnixSocketWatcher
, public ConnectionOrientedSocketIO
class StreamSocketIO final : public ConnectionOrientedSocketIO
{
public:
class ConnectTask;
@ -140,8 +138,7 @@ StreamSocketIO::StreamSocketIO(nsIThread* aConsumerThread,
MessageLoop* aIOLoop,
StreamSocket* aStreamSocket,
UnixSocketConnector* aConnector)
: UnixSocketWatcher(aIOLoop)
, ConnectionOrientedSocketIO(aConsumerThread)
: ConnectionOrientedSocketIO(aConsumerThread, aIOLoop)
, mStreamSocket(aStreamSocket)
, mConnector(aConnector)
, mShuttingDownOnIOThread(false)
@ -157,8 +154,10 @@ StreamSocketIO::StreamSocketIO(nsIThread* aConsumerThread,
int aFd, ConnectionStatus aConnectionStatus,
StreamSocket* aStreamSocket,
UnixSocketConnector* aConnector)
: UnixSocketWatcher(aIOLoop, aFd, aConnectionStatus)
, ConnectionOrientedSocketIO(aConsumerThread)
: ConnectionOrientedSocketIO(aConsumerThread,
aIOLoop,
aFd,
aConnectionStatus)
, mStreamSocket(aStreamSocket)
, mConnector(aConnector)
, mShuttingDownOnIOThread(false)