mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1158876: Move |DataSocket::ReceiveSocketData| into sub classes, r=kmachulis
|ReceiveSocketData| receives socket data on the main thread. This is a specific detail of the current socket classes, which should not be required by future implementations. This patch moves the receive method and the corresponding runnable into socket classes.
This commit is contained in:
parent
bd2114ae82
commit
f348be8538
@ -134,11 +134,16 @@ public:
|
|||||||
AddWatchers(WRITE_WATCHER, false);
|
AddWatchers(WRITE_WATCHER, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
DataSocket* GetDataSocket()
|
BluetoothSocket* GetBluetoothSocket()
|
||||||
{
|
{
|
||||||
return mConsumer.get();
|
return mConsumer.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DataSocket* GetDataSocket()
|
||||||
|
{
|
||||||
|
return GetBluetoothSocket();
|
||||||
|
}
|
||||||
|
|
||||||
SocketBase* GetSocketBase()
|
SocketBase* GetSocketBase()
|
||||||
{
|
{
|
||||||
return GetDataSocket();
|
return GetDataSocket();
|
||||||
@ -159,6 +164,8 @@ public:
|
|||||||
RefPtr<BluetoothSocket> mConsumer;
|
RefPtr<BluetoothSocket> mConsumer;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
class ReceiveRunnable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* libevent triggered functions that reads data from socket when available and
|
* libevent triggered functions that reads data from socket when available and
|
||||||
* guarenteed non-blocking. Only to be called on IO thread.
|
* guarenteed non-blocking. Only to be called on IO thread.
|
||||||
@ -517,11 +524,47 @@ DroidSocketImpl::QueryReceiveBuffer(
|
|||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* |ReceiveRunnable| transfers data received on the I/O thread
|
||||||
|
* to an instance of |BluetoothSocket| on the main thread.
|
||||||
|
*/
|
||||||
|
class DroidSocketImpl::ReceiveRunnable final
|
||||||
|
: public SocketIORunnable<DroidSocketImpl>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
ReceiveRunnable(DroidSocketImpl* aIO, UnixSocketBuffer* aBuffer)
|
||||||
|
: SocketIORunnable<DroidSocketImpl>(aIO)
|
||||||
|
, mBuffer(aBuffer)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
NS_IMETHOD Run() override
|
||||||
|
{
|
||||||
|
MOZ_ASSERT(NS_IsMainThread());
|
||||||
|
|
||||||
|
DroidSocketImpl* io = SocketIORunnable<DroidSocketImpl>::GetIO();
|
||||||
|
|
||||||
|
if (NS_WARN_IF(io->IsShutdownOnMainThread())) {
|
||||||
|
// Since we've already explicitly closed and the close
|
||||||
|
// happened before this, this isn't really an error.
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
BluetoothSocket* bluetoothSocket = io->GetBluetoothSocket();
|
||||||
|
MOZ_ASSERT(bluetoothSocket);
|
||||||
|
|
||||||
|
bluetoothSocket->ReceiveSocketData(mBuffer);
|
||||||
|
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
nsAutoPtr<UnixSocketBuffer> mBuffer;
|
||||||
|
};
|
||||||
|
|
||||||
void
|
void
|
||||||
DroidSocketImpl::ConsumeBuffer()
|
DroidSocketImpl::ConsumeBuffer()
|
||||||
{
|
{
|
||||||
NS_DispatchToMainThread(
|
NS_DispatchToMainThread(new ReceiveRunnable(this, mBuffer.forget()));
|
||||||
new SocketIOReceiveRunnable<DroidSocketImpl>(this, mBuffer.forget()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -34,13 +34,19 @@ public:
|
|||||||
|
|
||||||
void CloseSocket() override;
|
void CloseSocket() override;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method to be called whenever data is received. This is only called on the
|
||||||
|
* main thread.
|
||||||
|
*
|
||||||
|
* @param aBuffer Data received from the socket.
|
||||||
|
*/
|
||||||
|
void ReceiveSocketData(nsAutoPtr<mozilla::ipc::UnixSocketBuffer>& aBuffer);
|
||||||
|
|
||||||
void SendSocketData(mozilla::ipc::UnixSocketIOBuffer* aBuffer) override;
|
void SendSocketData(mozilla::ipc::UnixSocketIOBuffer* aBuffer) override;
|
||||||
|
|
||||||
virtual void OnConnectSuccess() override;
|
virtual void OnConnectSuccess() override;
|
||||||
virtual void OnConnectError() override;
|
virtual void OnConnectError() override;
|
||||||
virtual void OnDisconnect() override;
|
virtual void OnDisconnect() override;
|
||||||
virtual void ReceiveSocketData(
|
|
||||||
nsAutoPtr<mozilla::ipc::UnixSocketBuffer>& aBuffer) override;
|
|
||||||
|
|
||||||
inline void GetAddress(nsAString& aDeviceAddress)
|
inline void GetAddress(nsAString& aDeviceAddress)
|
||||||
{
|
{
|
||||||
|
@ -35,6 +35,8 @@ public:
|
|||||||
~BluetoothSocketIO();
|
~BluetoothSocketIO();
|
||||||
|
|
||||||
void GetSocketAddr(nsAString& aAddrStr) const;
|
void GetSocketAddr(nsAString& aAddrStr) const;
|
||||||
|
|
||||||
|
BluetoothSocket* GetBluetoothSocket();
|
||||||
DataSocket* GetDataSocket();
|
DataSocket* GetDataSocket();
|
||||||
SocketBase* GetSocketBase();
|
SocketBase* GetSocketBase();
|
||||||
|
|
||||||
@ -88,6 +90,8 @@ public:
|
|||||||
void DiscardBuffer();
|
void DiscardBuffer();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
class ReceiveRunnable;
|
||||||
|
|
||||||
void FireSocketError();
|
void FireSocketError();
|
||||||
|
|
||||||
// Set up flags on file descriptor.
|
// Set up flags on file descriptor.
|
||||||
@ -169,10 +173,16 @@ BluetoothSocket::BluetoothSocketIO::GetSocketAddr(nsAString& aAddrStr) const
|
|||||||
mConnector->GetSocketAddr(mAddr, aAddrStr);
|
mConnector->GetSocketAddr(mAddr, aAddrStr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BluetoothSocket*
|
||||||
|
BluetoothSocket::BluetoothSocketIO::GetBluetoothSocket()
|
||||||
|
{
|
||||||
|
return mConsumer.get();
|
||||||
|
}
|
||||||
|
|
||||||
DataSocket*
|
DataSocket*
|
||||||
BluetoothSocket::BluetoothSocketIO::GetDataSocket()
|
BluetoothSocket::BluetoothSocketIO::GetDataSocket()
|
||||||
{
|
{
|
||||||
return mConsumer.get();
|
return GetBluetoothSocket();
|
||||||
}
|
}
|
||||||
|
|
||||||
SocketBase*
|
SocketBase*
|
||||||
@ -500,11 +510,47 @@ BluetoothSocket::BluetoothSocketIO::QueryReceiveBuffer(
|
|||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* |ReceiveRunnable| transfers data received on the I/O thread
|
||||||
|
* to an instance of |BluetoothSocket| on the main thread.
|
||||||
|
*/
|
||||||
|
class BluetoothSocket::BluetoothSocketIO::ReceiveRunnable final
|
||||||
|
: public SocketIORunnable<BluetoothSocketIO>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
ReceiveRunnable(BluetoothSocketIO* aIO, UnixSocketBuffer* aBuffer)
|
||||||
|
: SocketIORunnable<BluetoothSocketIO>(aIO)
|
||||||
|
, mBuffer(aBuffer)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
NS_IMETHOD Run() override
|
||||||
|
{
|
||||||
|
MOZ_ASSERT(NS_IsMainThread());
|
||||||
|
|
||||||
|
BluetoothSocketIO* io = SocketIORunnable<BluetoothSocketIO>::GetIO();
|
||||||
|
|
||||||
|
if (NS_WARN_IF(io->IsShutdownOnMainThread())) {
|
||||||
|
// Since we've already explicitly closed and the close
|
||||||
|
// happened before this, this isn't really an error.
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
BluetoothSocket* bluetoothSocket = io->GetBluetoothSocket();
|
||||||
|
MOZ_ASSERT(bluetoothSocket);
|
||||||
|
|
||||||
|
bluetoothSocket->ReceiveSocketData(mBuffer);
|
||||||
|
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
nsAutoPtr<UnixSocketBuffer> mBuffer;
|
||||||
|
};
|
||||||
|
|
||||||
void
|
void
|
||||||
BluetoothSocket::BluetoothSocketIO::ConsumeBuffer()
|
BluetoothSocket::BluetoothSocketIO::ConsumeBuffer()
|
||||||
{
|
{
|
||||||
NS_DispatchToMainThread(
|
NS_DispatchToMainThread(new ReceiveRunnable(this, mBuffer.forget()));
|
||||||
new SocketIOReceiveRunnable<BluetoothSocketIO>(this, mBuffer.forget()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -44,14 +44,20 @@ public:
|
|||||||
virtual void OnConnectSuccess() override;
|
virtual void OnConnectSuccess() override;
|
||||||
virtual void OnConnectError() override;
|
virtual void OnConnectError() override;
|
||||||
virtual void OnDisconnect() override;
|
virtual void OnDisconnect() override;
|
||||||
virtual void ReceiveSocketData(
|
|
||||||
nsAutoPtr<mozilla::ipc::UnixSocketBuffer>& aBuffer) override;
|
|
||||||
|
|
||||||
inline void GetAddress(nsAString& aDeviceAddress)
|
inline void GetAddress(nsAString& aDeviceAddress)
|
||||||
{
|
{
|
||||||
GetSocketAddr(aDeviceAddress);
|
GetSocketAddr(aDeviceAddress);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method to be called whenever data is received. This is only called on the
|
||||||
|
* main thread.
|
||||||
|
*
|
||||||
|
* @param aBuffer Data received from the socket.
|
||||||
|
*/
|
||||||
|
void ReceiveSocketData(nsAutoPtr<mozilla::ipc::UnixSocketBuffer>& aBuffer);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Queue data to be sent to the socket on the IO thread. Can only be called on
|
* Queue data to be sent to the socket on the IO thread. Can only be called on
|
||||||
* originating thread.
|
* originating thread.
|
||||||
|
@ -28,14 +28,6 @@ class DataSocket : public SocketBase
|
|||||||
public:
|
public:
|
||||||
virtual ~DataSocket();
|
virtual ~DataSocket();
|
||||||
|
|
||||||
/**
|
|
||||||
* Function to be called whenever data is received. This is only called on the
|
|
||||||
* main thread.
|
|
||||||
*
|
|
||||||
* @param aBuffer Data received from the socket.
|
|
||||||
*/
|
|
||||||
virtual void ReceiveSocketData(nsAutoPtr<UnixSocketBuffer>& aBuffer) = 0;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Queue data to be sent to the socket on the IO thread. Can only be called on
|
* Queue data to be sent to the socket on the IO thread. Can only be called on
|
||||||
* originating thread.
|
* originating thread.
|
||||||
@ -45,48 +37,6 @@ public:
|
|||||||
virtual void SendSocketData(UnixSocketIOBuffer* aBuffer) = 0;
|
virtual void SendSocketData(UnixSocketIOBuffer* aBuffer) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
//
|
|
||||||
// Runnables
|
|
||||||
//
|
|
||||||
|
|
||||||
/**
|
|
||||||
* |SocketReceiveRunnable| transfers data received on the I/O thread
|
|
||||||
* to an instance of |DataSocket| on the main thread.
|
|
||||||
*/
|
|
||||||
template <typename T>
|
|
||||||
class SocketIOReceiveRunnable final : public SocketIORunnable<T>
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
SocketIOReceiveRunnable(T* aIO, UnixSocketBuffer* aBuffer)
|
|
||||||
: SocketIORunnable<T>(aIO)
|
|
||||||
, mBuffer(aBuffer)
|
|
||||||
{ }
|
|
||||||
|
|
||||||
NS_IMETHOD Run() override
|
|
||||||
{
|
|
||||||
MOZ_ASSERT(NS_IsMainThread());
|
|
||||||
|
|
||||||
T* io = SocketIORunnable<T>::GetIO();
|
|
||||||
|
|
||||||
if (io->IsShutdownOnMainThread()) {
|
|
||||||
NS_WARNING("mConsumer is null, aborting receive!");
|
|
||||||
// Since we've already explicitly closed and the close happened before
|
|
||||||
// this, this isn't really an error. Since we've warned, return OK.
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
DataSocket* dataSocket = io->GetDataSocket();
|
|
||||||
MOZ_ASSERT(dataSocket);
|
|
||||||
|
|
||||||
dataSocket->ReceiveSocketData(mBuffer);
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
nsAutoPtr<UnixSocketBuffer> mBuffer;
|
|
||||||
};
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// DataSocketIO
|
// DataSocketIO
|
||||||
//
|
//
|
||||||
|
@ -27,6 +27,7 @@ class StreamSocketIO final
|
|||||||
public:
|
public:
|
||||||
class ConnectTask;
|
class ConnectTask;
|
||||||
class DelayedConnectTask;
|
class DelayedConnectTask;
|
||||||
|
class ReceiveRunnable;
|
||||||
|
|
||||||
StreamSocketIO(MessageLoop* mIOLoop,
|
StreamSocketIO(MessageLoop* mIOLoop,
|
||||||
StreamSocket* aStreamSocket,
|
StreamSocket* aStreamSocket,
|
||||||
@ -39,7 +40,9 @@ public:
|
|||||||
const nsACString& aAddress);
|
const nsACString& aAddress);
|
||||||
~StreamSocketIO();
|
~StreamSocketIO();
|
||||||
|
|
||||||
void GetSocketAddr(nsAString& aAddrStr) const;
|
void GetSocketAddr(nsAString& aAddrStr) const;
|
||||||
|
|
||||||
|
StreamSocket* GetStreamSocket();
|
||||||
DataSocket* GetDataSocket();
|
DataSocket* GetDataSocket();
|
||||||
SocketBase* GetSocketBase();
|
SocketBase* GetSocketBase();
|
||||||
|
|
||||||
@ -190,6 +193,12 @@ StreamSocketIO::GetSocketAddr(nsAString& aAddrStr) const
|
|||||||
mConnector->GetSocketAddr(mAddr, aAddrStr);
|
mConnector->GetSocketAddr(mAddr, aAddrStr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
StreamSocket*
|
||||||
|
StreamSocketIO::GetStreamSocket()
|
||||||
|
{
|
||||||
|
return mStreamSocket.get();
|
||||||
|
}
|
||||||
|
|
||||||
DataSocket*
|
DataSocket*
|
||||||
StreamSocketIO::GetDataSocket()
|
StreamSocketIO::GetDataSocket()
|
||||||
{
|
{
|
||||||
@ -521,11 +530,47 @@ StreamSocketIO::QueryReceiveBuffer(UnixSocketIOBuffer** aBuffer)
|
|||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* |ReceiveRunnable| transfers data received on the I/O thread
|
||||||
|
* to an instance of |StreamSocket| on the main thread.
|
||||||
|
*/
|
||||||
|
class StreamSocketIO::ReceiveRunnable final
|
||||||
|
: public SocketIORunnable<StreamSocketIO>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
ReceiveRunnable(StreamSocketIO* aIO, UnixSocketBuffer* aBuffer)
|
||||||
|
: SocketIORunnable<StreamSocketIO>(aIO)
|
||||||
|
, mBuffer(aBuffer)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
NS_IMETHOD Run() override
|
||||||
|
{
|
||||||
|
MOZ_ASSERT(NS_IsMainThread());
|
||||||
|
|
||||||
|
StreamSocketIO* io = SocketIORunnable<StreamSocketIO>::GetIO();
|
||||||
|
|
||||||
|
if (NS_WARN_IF(io->IsShutdownOnMainThread())) {
|
||||||
|
// Since we've already explicitly closed and the close
|
||||||
|
// happened before this, this isn't really an error.
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
StreamSocket* streamSocket = io->GetStreamSocket();
|
||||||
|
MOZ_ASSERT(streamSocket);
|
||||||
|
|
||||||
|
streamSocket->ReceiveSocketData(mBuffer);
|
||||||
|
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
nsAutoPtr<UnixSocketBuffer> mBuffer;
|
||||||
|
};
|
||||||
|
|
||||||
void
|
void
|
||||||
StreamSocketIO::ConsumeBuffer()
|
StreamSocketIO::ConsumeBuffer()
|
||||||
{
|
{
|
||||||
NS_DispatchToMainThread(
|
NS_DispatchToMainThread(new ReceiveRunnable(this, mBuffer.forget()));
|
||||||
new SocketIOReceiveRunnable<StreamSocketIO>(this, mBuffer.forget()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -22,6 +22,14 @@ class StreamSocket : public DataSocket
|
|||||||
public:
|
public:
|
||||||
StreamSocket();
|
StreamSocket();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method to be called whenever data is received. This is only called on the
|
||||||
|
* main thread.
|
||||||
|
*
|
||||||
|
* @param aBuffer Data received from the socket.
|
||||||
|
*/
|
||||||
|
virtual void ReceiveSocketData(nsAutoPtr<UnixSocketBuffer>& aBuffer) = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Queue data to be sent to the socket on the IO thread. Can only be called on
|
* Queue data to be sent to the socket on the IO thread. Can only be called on
|
||||||
* originating thread.
|
* originating thread.
|
||||||
|
Loading…
Reference in New Issue
Block a user