mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1083092: Introduce |mozilla::ipc::SocketBase|, r=shawnjohnjr
The new class |SocketBase| contains the notification mechanism of |SocketConsumerBase|. The latter still contains I/O methods.
This commit is contained in:
parent
bd338ebbc3
commit
8136d65793
@ -143,6 +143,11 @@ public:
|
||||
return mConsumer.get();
|
||||
}
|
||||
|
||||
SocketBase* GetSocketBase()
|
||||
{
|
||||
return GetConsumer();
|
||||
}
|
||||
|
||||
/**
|
||||
* Consumer pointer. Non-thread safe RefPtr, so should only be manipulated
|
||||
* directly from main thread. All non-main-thread accesses should happen with
|
||||
|
@ -143,6 +143,11 @@ public:
|
||||
return mConsumer.get();
|
||||
}
|
||||
|
||||
SocketBase* GetSocketBase()
|
||||
{
|
||||
return GetConsumer();
|
||||
}
|
||||
|
||||
/**
|
||||
* Consumer pointer. Non-thread safe RefPtr, so should only be manipulated
|
||||
* directly from main thread. All non-main-thread accesses should happen with
|
||||
|
@ -94,16 +94,16 @@ UnixSocketRawData::Send(int aFd)
|
||||
}
|
||||
|
||||
//
|
||||
// SocketConsumerBase
|
||||
// SocketBase
|
||||
//
|
||||
|
||||
SocketConsumerBase::~SocketConsumerBase()
|
||||
SocketBase::~SocketBase()
|
||||
{
|
||||
MOZ_ASSERT(mConnectionStatus == SOCKET_DISCONNECTED);
|
||||
}
|
||||
|
||||
SocketConnectionStatus
|
||||
SocketConsumerBase::GetConnectionStatus() const
|
||||
SocketBase::GetConnectionStatus() const
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
@ -111,7 +111,7 @@ SocketConsumerBase::GetConnectionStatus() const
|
||||
}
|
||||
|
||||
int
|
||||
SocketConsumerBase::GetSuggestedConnectDelayMs() const
|
||||
SocketBase::GetSuggestedConnectDelayMs() const
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
@ -119,7 +119,7 @@ SocketConsumerBase::GetSuggestedConnectDelayMs() const
|
||||
}
|
||||
|
||||
void
|
||||
SocketConsumerBase::NotifySuccess()
|
||||
SocketBase::NotifySuccess()
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
@ -129,7 +129,7 @@ SocketConsumerBase::NotifySuccess()
|
||||
}
|
||||
|
||||
void
|
||||
SocketConsumerBase::NotifyError()
|
||||
SocketBase::NotifyError()
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
@ -140,7 +140,7 @@ SocketConsumerBase::NotifyError()
|
||||
}
|
||||
|
||||
void
|
||||
SocketConsumerBase::NotifyDisconnect()
|
||||
SocketBase::NotifyDisconnect()
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
@ -151,7 +151,7 @@ SocketConsumerBase::NotifyDisconnect()
|
||||
}
|
||||
|
||||
uint32_t
|
||||
SocketConsumerBase::CalculateConnectDelayMs() const
|
||||
SocketBase::CalculateConnectDelayMs() const
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
@ -170,19 +170,25 @@ SocketConsumerBase::CalculateConnectDelayMs() const
|
||||
return connectDelayMs;
|
||||
}
|
||||
|
||||
SocketConsumerBase::SocketConsumerBase()
|
||||
SocketBase::SocketBase()
|
||||
: mConnectionStatus(SOCKET_DISCONNECTED)
|
||||
, mConnectTimestamp(0)
|
||||
, mConnectDelayMs(0)
|
||||
{ }
|
||||
|
||||
void
|
||||
SocketConsumerBase::SetConnectionStatus(
|
||||
SocketConnectionStatus aConnectionStatus)
|
||||
SocketBase::SetConnectionStatus(SocketConnectionStatus aConnectionStatus)
|
||||
{
|
||||
mConnectionStatus = aConnectionStatus;
|
||||
}
|
||||
|
||||
//
|
||||
// SocketConsumerBase
|
||||
//
|
||||
|
||||
SocketConsumerBase::~SocketConsumerBase()
|
||||
{ }
|
||||
|
||||
//
|
||||
// SocketIOBase
|
||||
//
|
||||
|
@ -106,15 +106,15 @@ enum SocketConnectionStatus {
|
||||
};
|
||||
|
||||
//
|
||||
// SocketConsumerBase
|
||||
// SocketBase
|
||||
//
|
||||
|
||||
class SocketConsumerBase
|
||||
class SocketBase
|
||||
{
|
||||
public:
|
||||
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(SocketConsumerBase)
|
||||
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(SocketBase)
|
||||
|
||||
virtual ~SocketConsumerBase();
|
||||
virtual ~SocketBase();
|
||||
|
||||
SocketConnectionStatus GetConnectionStatus() const;
|
||||
|
||||
@ -126,24 +126,6 @@ public:
|
||||
*/
|
||||
virtual void CloseSocket() = 0;
|
||||
|
||||
/**
|
||||
* Function to be called whenever data is received. This is only called on the
|
||||
* main thread.
|
||||
*
|
||||
* @param aMessage Data received from the socket.
|
||||
*/
|
||||
virtual void ReceiveSocketData(nsAutoPtr<UnixSocketRawData>& aMessage) = 0;
|
||||
|
||||
/**
|
||||
* Queue data to be sent to the socket on the IO thread. Can only be called on
|
||||
* originating thread.
|
||||
*
|
||||
* @param aMessage Data to be sent to socket
|
||||
*
|
||||
* @return true if data is queued, false otherwise (i.e. not connected)
|
||||
*/
|
||||
virtual bool SendSocketData(UnixSocketRawData* aMessage) = 0;
|
||||
|
||||
/**
|
||||
* Callback for socket connect/accept success. Called after connect/accept has
|
||||
* finished. Will be run on main thread, before any reads take place.
|
||||
@ -176,7 +158,7 @@ public:
|
||||
void NotifyDisconnect();
|
||||
|
||||
protected:
|
||||
SocketConsumerBase();
|
||||
SocketBase();
|
||||
|
||||
void SetConnectionStatus(SocketConnectionStatus aConnectionStatus);
|
||||
|
||||
@ -188,6 +170,34 @@ private:
|
||||
uint32_t mConnectDelayMs;
|
||||
};
|
||||
|
||||
//
|
||||
// SocketConsumerBase
|
||||
//
|
||||
|
||||
class SocketConsumerBase : public SocketBase
|
||||
{
|
||||
public:
|
||||
virtual ~SocketConsumerBase();
|
||||
|
||||
/**
|
||||
* Function to be called whenever data is received. This is only called on the
|
||||
* main thread.
|
||||
*
|
||||
* @param aMessage Data received from the socket.
|
||||
*/
|
||||
virtual void ReceiveSocketData(nsAutoPtr<UnixSocketRawData>& aMessage) = 0;
|
||||
|
||||
/**
|
||||
* Queue data to be sent to the socket on the IO thread. Can only be called on
|
||||
* originating thread.
|
||||
*
|
||||
* @param aMessage Data to be sent to socket
|
||||
*
|
||||
* @return true if data is queued, false otherwise (i.e. not connected)
|
||||
*/
|
||||
virtual bool SendSocketData(UnixSocketRawData* aMessage) = 0;
|
||||
};
|
||||
|
||||
//
|
||||
// Socket I/O runnables
|
||||
//
|
||||
@ -249,15 +259,15 @@ public:
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
SocketConsumerBase* consumer = io->GetConsumer();
|
||||
MOZ_ASSERT(consumer);
|
||||
SocketBase* base = io->GetSocketBase();
|
||||
MOZ_ASSERT(base);
|
||||
|
||||
if (mEvent == CONNECT_SUCCESS) {
|
||||
consumer->NotifySuccess();
|
||||
base->NotifySuccess();
|
||||
} else if (mEvent == CONNECT_ERROR) {
|
||||
consumer->NotifyError();
|
||||
base->NotifyError();
|
||||
} else if (mEvent == DISCONNECT) {
|
||||
consumer->NotifyDisconnect();
|
||||
base->NotifyDisconnect();
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
@ -325,10 +335,10 @@ public:
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
SocketConsumerBase* consumer = io->GetConsumer();
|
||||
MOZ_ASSERT(consumer);
|
||||
SocketBase* base = io->GetSocketBase();
|
||||
MOZ_ASSERT(base);
|
||||
|
||||
consumer->CloseSocket();
|
||||
base->CloseSocket();
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -31,6 +31,7 @@ public:
|
||||
|
||||
void GetSocketAddr(nsAString& aAddrStr) const;
|
||||
SocketConsumerBase* GetConsumer();
|
||||
SocketBase* GetSocketBase();
|
||||
|
||||
// Shutdown state
|
||||
//
|
||||
@ -157,6 +158,12 @@ UnixSocketConsumerIO::GetConsumer()
|
||||
return mConsumer.get();
|
||||
}
|
||||
|
||||
SocketBase*
|
||||
UnixSocketConsumerIO::GetSocketBase()
|
||||
{
|
||||
return GetConsumer();
|
||||
}
|
||||
|
||||
bool
|
||||
UnixSocketConsumerIO::IsShutdownOnMainThread() const
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user