2014-07-31 15:55:27 +04:00
|
|
|
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
|
|
|
|
/* vim: set ts=2 et sw=2 tw=80: */
|
|
|
|
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef mozilla_ipc_SocketBase_h
|
|
|
|
#define mozilla_ipc_SocketBase_h
|
|
|
|
|
2014-07-31 15:55:29 +04:00
|
|
|
#include "base/message_loop.h"
|
2014-07-31 15:55:27 +04:00
|
|
|
#include "nsAutoPtr.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace ipc {
|
|
|
|
|
|
|
|
//
|
2015-04-23 14:48:47 +03:00
|
|
|
// UnixSocketBuffer
|
2014-07-31 15:55:27 +04:00
|
|
|
//
|
|
|
|
|
2015-04-23 14:48:47 +03:00
|
|
|
/**
|
|
|
|
* |UnixSocketBuffer| implements a FIFO buffer that stores raw socket
|
|
|
|
* data, either for sending on a socket or received from a socket.
|
|
|
|
*/
|
|
|
|
class UnixSocketBuffer
|
2014-07-31 15:55:27 +04:00
|
|
|
{
|
|
|
|
public:
|
2015-04-23 14:48:47 +03:00
|
|
|
virtual ~UnixSocketBuffer();
|
|
|
|
|
2014-10-21 12:52:12 +04:00
|
|
|
const uint8_t* GetData() const
|
|
|
|
{
|
|
|
|
return mData + mOffset;
|
|
|
|
}
|
2014-07-31 15:55:27 +04:00
|
|
|
|
2014-10-21 12:52:12 +04:00
|
|
|
size_t GetSize() const
|
|
|
|
{
|
|
|
|
return mSize - mOffset;
|
|
|
|
}
|
2014-09-08 13:44:00 +04:00
|
|
|
|
2014-10-21 12:52:12 +04:00
|
|
|
const uint8_t* Consume(size_t aLen);
|
2014-09-08 13:44:00 +04:00
|
|
|
|
2014-10-21 12:52:12 +04:00
|
|
|
nsresult Read(void* aValue, size_t aLen);
|
2014-09-08 13:44:00 +04:00
|
|
|
|
2014-10-21 12:52:12 +04:00
|
|
|
nsresult Read(int8_t& aValue)
|
2014-09-08 13:44:00 +04:00
|
|
|
{
|
2014-10-21 12:52:12 +04:00
|
|
|
return Read(&aValue, sizeof(aValue));
|
2014-09-08 13:44:00 +04:00
|
|
|
}
|
|
|
|
|
2014-10-21 12:52:12 +04:00
|
|
|
nsresult Read(uint8_t& aValue)
|
|
|
|
{
|
|
|
|
return Read(&aValue, sizeof(aValue));
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult Read(int16_t& aValue)
|
|
|
|
{
|
|
|
|
return Read(&aValue, sizeof(aValue));
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult Read(uint16_t& aValue)
|
|
|
|
{
|
|
|
|
return Read(&aValue, sizeof(aValue));
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult Read(int32_t& aValue)
|
|
|
|
{
|
|
|
|
return Read(&aValue, sizeof(aValue));
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult Read(uint32_t& aValue)
|
|
|
|
{
|
|
|
|
return Read(&aValue, sizeof(aValue));
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t* Append(size_t aLen);
|
|
|
|
|
|
|
|
nsresult Write(const void* aValue, size_t aLen);
|
|
|
|
|
|
|
|
nsresult Write(int8_t aValue)
|
|
|
|
{
|
|
|
|
return Write(&aValue, sizeof(aValue));
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult Write(uint8_t aValue)
|
|
|
|
{
|
|
|
|
return Write(&aValue, sizeof(aValue));
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult Write(int16_t aValue)
|
2014-09-08 13:44:00 +04:00
|
|
|
{
|
2014-10-21 12:52:12 +04:00
|
|
|
return Write(&aValue, sizeof(aValue));
|
2014-09-08 13:44:00 +04:00
|
|
|
}
|
|
|
|
|
2014-10-21 12:52:12 +04:00
|
|
|
nsresult Write(uint16_t aValue)
|
2014-09-08 13:44:00 +04:00
|
|
|
{
|
2014-10-21 12:52:12 +04:00
|
|
|
return Write(&aValue, sizeof(aValue));
|
|
|
|
}
|
2014-09-08 13:44:00 +04:00
|
|
|
|
2014-10-21 12:52:12 +04:00
|
|
|
nsresult Write(int32_t aValue)
|
|
|
|
{
|
|
|
|
return Write(&aValue, sizeof(aValue));
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult Write(uint32_t aValue)
|
|
|
|
{
|
|
|
|
return Write(&aValue, sizeof(aValue));
|
2014-09-08 13:44:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2015-06-08 11:20:17 +03:00
|
|
|
UnixSocketBuffer();
|
2014-10-21 12:52:12 +04:00
|
|
|
|
2015-06-08 11:20:17 +03:00
|
|
|
/**
|
|
|
|
* Sets the raw memory. The caller is responsible for freeing
|
|
|
|
* this memory.
|
|
|
|
*
|
|
|
|
* @param aData A pointer to the buffer's raw memory.
|
|
|
|
* @param aOffset The start of valid bytes in |aData|.
|
|
|
|
* @param aSize The number of valid bytes in |aData|.
|
|
|
|
* @param aAvailableSpace The number of bytes in |aData|.
|
2014-10-21 12:52:12 +04:00
|
|
|
*/
|
2015-06-08 11:20:17 +03:00
|
|
|
void ResetBuffer(uint8_t* aData,
|
|
|
|
size_t aOffset, size_t aSize, size_t aAvailableSpace)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aData || !aAvailableSpace);
|
|
|
|
MOZ_ASSERT((aOffset + aSize) <= aAvailableSpace);
|
|
|
|
|
|
|
|
mOffset = aOffset;
|
|
|
|
mSize = aSize;
|
|
|
|
mAvailableSpace = aAvailableSpace;
|
|
|
|
mData = aData;
|
|
|
|
}
|
2014-10-21 12:52:12 +04:00
|
|
|
|
2015-06-08 11:20:17 +03:00
|
|
|
/**
|
|
|
|
* Retrieves the memory buffer.
|
|
|
|
*
|
|
|
|
* @return A pointer to the buffer's raw memory.
|
2014-10-21 12:52:12 +04:00
|
|
|
*/
|
2015-06-08 11:20:17 +03:00
|
|
|
uint8_t* GetBuffer()
|
|
|
|
{
|
|
|
|
return mData;
|
|
|
|
}
|
2014-10-21 12:52:12 +04:00
|
|
|
|
2014-09-08 13:44:00 +04:00
|
|
|
size_t GetLeadingSpace() const
|
|
|
|
{
|
2014-09-08 13:44:02 +04:00
|
|
|
return mOffset;
|
2014-09-08 13:44:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
size_t GetTrailingSpace() const
|
|
|
|
{
|
2014-10-21 12:52:12 +04:00
|
|
|
return mAvailableSpace - mSize;
|
2014-09-08 13:44:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
size_t GetAvailableSpace() const
|
|
|
|
{
|
|
|
|
return mAvailableSpace;
|
|
|
|
}
|
|
|
|
|
|
|
|
void* GetTrailingBytes()
|
|
|
|
{
|
2014-10-21 12:52:12 +04:00
|
|
|
return mData + mSize;
|
2014-09-08 13:44:00 +04:00
|
|
|
}
|
|
|
|
|
2014-10-21 12:52:12 +04:00
|
|
|
uint8_t* GetData(size_t aOffset)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aOffset <= mSize);
|
|
|
|
|
|
|
|
return mData + aOffset;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetRange(size_t aOffset, size_t aSize)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT((aOffset + aSize) <= mAvailableSpace);
|
|
|
|
|
|
|
|
mOffset = aOffset;
|
|
|
|
mSize = mOffset + aSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CleanupLeadingSpace();
|
|
|
|
|
2014-09-08 13:44:00 +04:00
|
|
|
private:
|
2014-09-08 13:44:02 +04:00
|
|
|
size_t mSize;
|
|
|
|
size_t mOffset;
|
2014-09-08 13:44:00 +04:00
|
|
|
size_t mAvailableSpace;
|
2015-06-08 11:20:17 +03:00
|
|
|
uint8_t* mData;
|
2014-07-31 15:55:27 +04:00
|
|
|
};
|
|
|
|
|
2015-04-23 14:48:47 +03:00
|
|
|
//
|
|
|
|
// UnixSocketIOBuffer
|
|
|
|
//
|
|
|
|
|
|
|
|
/**
|
|
|
|
* |UnixSocketIOBuffer| is a |UnixSocketBuffer| that supports being
|
|
|
|
* received on a socket or being send on a socket. Network protocols
|
|
|
|
* might differ in their exact usage of Unix socket functions and
|
|
|
|
* |UnixSocketIOBuffer| provides a protocol-neutral interface.
|
|
|
|
*/
|
|
|
|
class UnixSocketIOBuffer : public UnixSocketBuffer
|
|
|
|
{
|
|
|
|
public:
|
2015-07-21 09:06:29 +03:00
|
|
|
UnixSocketIOBuffer();
|
2015-04-23 14:48:47 +03:00
|
|
|
virtual ~UnixSocketIOBuffer();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Receives data from aFd at the end of the buffer. The returned value
|
|
|
|
* is the number of newly received bytes, or 0 if the peer shut down
|
|
|
|
* its connection, or a negative value on errors.
|
|
|
|
*/
|
|
|
|
virtual ssize_t Receive(int aFd) = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sends data to aFd from the beginning of the buffer. The returned value
|
|
|
|
* is the number of bytes written, or a negative value on error.
|
|
|
|
*/
|
|
|
|
virtual ssize_t Send(int aFd) = 0;
|
|
|
|
};
|
|
|
|
|
2014-10-21 12:52:12 +04:00
|
|
|
//
|
|
|
|
// UnixSocketRawData
|
|
|
|
//
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class UnixSocketRawData final : public UnixSocketIOBuffer
|
2014-10-21 12:52:12 +04:00
|
|
|
{
|
|
|
|
public:
|
2015-06-08 11:20:17 +03:00
|
|
|
/**
|
|
|
|
* This constructor copies aData of aSize bytes length into the
|
2014-10-21 12:52:12 +04:00
|
|
|
* new instance of |UnixSocketRawData|.
|
2015-06-08 11:20:17 +03:00
|
|
|
*
|
|
|
|
* @param aData The buffer to copy.
|
|
|
|
* @param aSize The number of bytes in |aData|.
|
2014-10-21 12:52:12 +04:00
|
|
|
*/
|
|
|
|
UnixSocketRawData(const void* aData, size_t aSize);
|
|
|
|
|
2015-06-08 11:20:17 +03:00
|
|
|
/**
|
|
|
|
* This constructor reserves aSize bytes of space. Currently
|
2014-10-21 12:52:12 +04:00
|
|
|
* it's only possible to fill this buffer by calling |Receive|.
|
2015-06-08 11:20:17 +03:00
|
|
|
*
|
|
|
|
* @param aSize The number of bytes to allocate.
|
2014-10-21 12:52:12 +04:00
|
|
|
*/
|
|
|
|
UnixSocketRawData(size_t aSize);
|
|
|
|
|
2015-06-08 11:20:17 +03:00
|
|
|
/**
|
|
|
|
* The destructor releases the buffer's raw memory.
|
|
|
|
*/
|
|
|
|
~UnixSocketRawData();
|
|
|
|
|
2014-10-21 12:52:12 +04:00
|
|
|
/**
|
|
|
|
* Receives data from aFd at the end of the buffer. The returned value
|
|
|
|
* is the number of newly received bytes, or 0 if the peer shut down
|
|
|
|
* its connection, or a negative value on errors.
|
|
|
|
*/
|
2015-04-23 14:48:47 +03:00
|
|
|
ssize_t Receive(int aFd) override;
|
2014-10-21 12:52:12 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sends data to aFd from the beginning of the buffer. The returned value
|
|
|
|
* is the number of bytes written, or a negative value on error.
|
|
|
|
*/
|
2015-04-23 14:48:47 +03:00
|
|
|
ssize_t Send(int aFd) override;
|
2014-10-21 12:52:12 +04:00
|
|
|
};
|
|
|
|
|
2014-07-31 15:55:27 +04:00
|
|
|
enum SocketConnectionStatus {
|
|
|
|
SOCKET_DISCONNECTED = 0,
|
|
|
|
SOCKET_LISTENING = 1,
|
|
|
|
SOCKET_CONNECTING = 2,
|
|
|
|
SOCKET_CONNECTED = 3
|
|
|
|
};
|
|
|
|
|
|
|
|
//
|
2014-10-21 12:52:11 +04:00
|
|
|
// SocketBase
|
2014-07-31 15:55:27 +04:00
|
|
|
//
|
|
|
|
|
2014-10-21 12:52:11 +04:00
|
|
|
class SocketBase
|
2014-07-31 15:55:27 +04:00
|
|
|
{
|
|
|
|
public:
|
2014-10-21 12:52:11 +04:00
|
|
|
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(SocketBase)
|
2014-07-31 15:55:27 +04:00
|
|
|
|
|
|
|
SocketConnectionStatus GetConnectionStatus() const;
|
|
|
|
|
|
|
|
int GetSuggestedConnectDelayMs() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Queues the internal representation of socket for deletion. Can be called
|
2015-06-02 11:01:58 +03:00
|
|
|
* from consumer thread.
|
2014-07-31 15:55:27 +04:00
|
|
|
*/
|
2015-05-20 11:50:43 +03:00
|
|
|
virtual void Close() = 0;
|
2014-07-31 15:55:27 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Callback for socket connect/accept success. Called after connect/accept has
|
2015-06-02 11:01:58 +03:00
|
|
|
* finished. Will be run on consumer thread before any reads take place.
|
2014-07-31 15:55:27 +04:00
|
|
|
*/
|
|
|
|
virtual void OnConnectSuccess() = 0;
|
|
|
|
|
|
|
|
/**
|
2015-06-02 11:01:58 +03:00
|
|
|
* Callback for socket connect/accept error. Will be run on consumer thread.
|
2014-07-31 15:55:27 +04:00
|
|
|
*/
|
|
|
|
virtual void OnConnectError() = 0;
|
|
|
|
|
|
|
|
/**
|
2015-06-02 11:01:58 +03:00
|
|
|
* Callback for socket disconnect. Will be run on consumer thread.
|
2014-07-31 15:55:27 +04:00
|
|
|
*/
|
|
|
|
virtual void OnDisconnect() = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called by implementation to notify consumer of success.
|
|
|
|
*/
|
|
|
|
void NotifySuccess();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called by implementation to notify consumer of error.
|
|
|
|
*/
|
|
|
|
void NotifyError();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called by implementation to notify consumer of disconnect.
|
|
|
|
*/
|
|
|
|
void NotifyDisconnect();
|
|
|
|
|
|
|
|
protected:
|
2014-10-21 12:52:11 +04:00
|
|
|
SocketBase();
|
2015-03-02 12:23:52 +03:00
|
|
|
virtual ~SocketBase();
|
2014-07-31 15:55:27 +04:00
|
|
|
|
|
|
|
void SetConnectionStatus(SocketConnectionStatus aConnectionStatus);
|
|
|
|
|
|
|
|
private:
|
|
|
|
uint32_t CalculateConnectDelayMs() const;
|
|
|
|
|
|
|
|
SocketConnectionStatus mConnectionStatus;
|
|
|
|
PRIntervalTime mConnectTimestamp;
|
|
|
|
uint32_t mConnectDelayMs;
|
|
|
|
};
|
|
|
|
|
2015-04-29 12:19:28 +03:00
|
|
|
//
|
|
|
|
// SocketIOBase
|
|
|
|
//
|
|
|
|
|
|
|
|
/**
|
|
|
|
* |SocketIOBase| is a base class for Socket I/O classes that
|
|
|
|
* perform operations on the I/O thread.
|
|
|
|
*/
|
|
|
|
class SocketIOBase
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual ~SocketIOBase();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implemented by socket I/O classes to return the current instance of
|
|
|
|
* |SocketBase|.
|
|
|
|
*
|
|
|
|
* @return The current instance of |SocketBase|
|
|
|
|
*/
|
|
|
|
virtual SocketBase* GetSocketBase() = 0;
|
|
|
|
|
2015-04-29 12:19:28 +03:00
|
|
|
/**
|
|
|
|
* Implemented by socket I/O classes to signal that the socket I/O class has
|
|
|
|
* been shut down.
|
|
|
|
*
|
|
|
|
* @return True if the socket I/O class has been shut down, false otherwise.
|
|
|
|
*/
|
|
|
|
virtual bool IsShutdownOnIOThread() const = 0;
|
|
|
|
|
2015-04-29 12:19:28 +03:00
|
|
|
/**
|
|
|
|
* Implemented by socket I/O classes to signal that socket class has
|
|
|
|
* been shut down.
|
|
|
|
*
|
|
|
|
* @return True if the socket class has been shut down, false otherwise.
|
|
|
|
*/
|
2015-06-02 11:01:58 +03:00
|
|
|
virtual bool IsShutdownOnConsumerThread() const = 0;
|
2015-04-29 12:19:28 +03:00
|
|
|
|
2015-04-29 12:19:28 +03:00
|
|
|
/**
|
|
|
|
* Signals to the socket I/O classes that it has been shut down.
|
|
|
|
*/
|
|
|
|
virtual void ShutdownOnIOThread() = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Signals to the socket I/O classes that the socket class has been
|
|
|
|
* shut down.
|
|
|
|
*/
|
2015-06-02 11:01:58 +03:00
|
|
|
virtual void ShutdownOnConsumerThread() = 0;
|
2015-04-29 12:19:28 +03:00
|
|
|
|
2015-06-02 11:01:57 +03:00
|
|
|
/**
|
|
|
|
* Returns the consumer thread.
|
|
|
|
*
|
|
|
|
* @return A pointer to the consumer thread.
|
|
|
|
*/
|
2015-06-09 10:50:10 +03:00
|
|
|
MessageLoop* GetConsumerThread() const;
|
2015-06-02 11:01:57 +03:00
|
|
|
|
|
|
|
/**
|
2015-06-09 10:50:10 +03:00
|
|
|
* @return True if the current thread is the consumer thread, or false
|
2015-06-02 11:01:57 +03:00
|
|
|
* otherwise.
|
|
|
|
*/
|
|
|
|
bool IsConsumerThread() const;
|
|
|
|
|
2015-04-29 12:19:28 +03:00
|
|
|
protected:
|
2015-06-09 10:50:10 +03:00
|
|
|
SocketIOBase(MessageLoop* aConsumerLoop);
|
2015-06-02 11:01:57 +03:00
|
|
|
|
|
|
|
private:
|
2015-06-09 10:50:10 +03:00
|
|
|
MessageLoop* mConsumerLoop;
|
2015-04-29 12:19:28 +03:00
|
|
|
};
|
|
|
|
|
2014-07-31 15:55:28 +04:00
|
|
|
//
|
2015-06-09 10:50:10 +03:00
|
|
|
// Socket tasks
|
2014-07-31 15:55:28 +04:00
|
|
|
//
|
|
|
|
|
2015-06-09 10:50:10 +03:00
|
|
|
/* |SocketTask| is a task for sending a message from
|
2015-06-02 11:01:58 +03:00
|
|
|
* the I/O thread to the consumer thread.
|
2014-07-31 15:55:28 +04:00
|
|
|
*/
|
|
|
|
template <typename T>
|
2015-06-09 10:50:10 +03:00
|
|
|
class SocketTask : public Task
|
2014-07-31 15:55:28 +04:00
|
|
|
{
|
|
|
|
public:
|
2015-06-09 10:50:10 +03:00
|
|
|
virtual ~SocketTask()
|
2014-07-31 15:55:28 +04:00
|
|
|
{ }
|
|
|
|
|
|
|
|
T* GetIO() const
|
|
|
|
{
|
|
|
|
return mIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2015-06-09 10:50:10 +03:00
|
|
|
SocketTask(T* aIO)
|
|
|
|
: mIO(aIO)
|
2014-07-31 15:55:28 +04:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(aIO);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
T* mIO;
|
|
|
|
};
|
|
|
|
|
2015-04-29 12:19:28 +03:00
|
|
|
/**
|
2015-06-09 10:50:10 +03:00
|
|
|
* |SocketEventTask| reports the connection state on the
|
2015-06-02 11:01:58 +03:00
|
|
|
* I/O thread back to the consumer thread.
|
2014-07-31 15:55:28 +04:00
|
|
|
*/
|
2015-06-09 10:50:10 +03:00
|
|
|
class SocketEventTask final : public SocketTask<SocketIOBase>
|
2014-07-31 15:55:28 +04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
enum SocketEvent {
|
|
|
|
CONNECT_SUCCESS,
|
|
|
|
CONNECT_ERROR,
|
|
|
|
DISCONNECT
|
|
|
|
};
|
|
|
|
|
2015-06-09 10:50:10 +03:00
|
|
|
SocketEventTask(SocketIOBase* aIO, SocketEvent aEvent);
|
2015-07-21 09:06:29 +03:00
|
|
|
~SocketEventTask();
|
2014-07-31 15:55:28 +04:00
|
|
|
|
2015-06-09 10:50:10 +03:00
|
|
|
void Run() override;
|
2014-07-31 15:55:28 +04:00
|
|
|
|
|
|
|
private:
|
|
|
|
SocketEvent mEvent;
|
|
|
|
};
|
|
|
|
|
2015-04-29 12:19:28 +03:00
|
|
|
/**
|
2015-06-09 10:50:10 +03:00
|
|
|
* |SocketRequestClosingTask| closes an instance of |SocketBase|
|
|
|
|
* on the consumer thread.
|
2015-04-29 12:19:28 +03:00
|
|
|
*/
|
2015-06-09 10:50:10 +03:00
|
|
|
class SocketRequestClosingTask final : public SocketTask<SocketIOBase>
|
2014-07-31 15:55:28 +04:00
|
|
|
{
|
|
|
|
public:
|
2015-06-09 10:50:10 +03:00
|
|
|
SocketRequestClosingTask(SocketIOBase* aIO);
|
2015-07-21 09:06:29 +03:00
|
|
|
~SocketRequestClosingTask();
|
2014-07-31 15:55:28 +04:00
|
|
|
|
2015-06-09 10:50:10 +03:00
|
|
|
void Run() override;
|
2014-07-31 15:55:28 +04:00
|
|
|
};
|
2014-07-31 15:55:28 +04:00
|
|
|
|
2015-04-29 12:19:28 +03:00
|
|
|
/**
|
2015-06-09 10:50:10 +03:00
|
|
|
* |SocketDeleteInstanceTask| deletes an object on the consumer thread.
|
2014-07-31 15:55:29 +04:00
|
|
|
*/
|
2015-06-09 10:50:10 +03:00
|
|
|
class SocketDeleteInstanceTask final : public Task
|
2014-07-31 15:55:29 +04:00
|
|
|
{
|
|
|
|
public:
|
2015-06-09 10:50:10 +03:00
|
|
|
SocketDeleteInstanceTask(SocketIOBase* aIO);
|
2015-07-21 09:06:29 +03:00
|
|
|
~SocketDeleteInstanceTask();
|
2014-07-31 15:55:29 +04:00
|
|
|
|
2015-06-09 10:50:10 +03:00
|
|
|
void Run() override;
|
2014-07-31 15:55:29 +04:00
|
|
|
|
|
|
|
private:
|
2015-04-29 12:19:28 +03:00
|
|
|
nsAutoPtr<SocketIOBase> mIO;
|
2014-07-31 15:55:29 +04:00
|
|
|
};
|
|
|
|
|
2014-07-31 15:55:29 +04:00
|
|
|
//
|
|
|
|
// Socket I/O tasks
|
|
|
|
//
|
|
|
|
|
|
|
|
/* |SocketIOTask| holds a reference to a Socket I/O object. It's
|
|
|
|
* supposed to run on the I/O thread.
|
|
|
|
*/
|
2014-10-21 12:52:12 +04:00
|
|
|
template<typename Tio>
|
2014-07-31 15:55:29 +04:00
|
|
|
class SocketIOTask : public CancelableTask
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual ~SocketIOTask()
|
|
|
|
{ }
|
|
|
|
|
2014-10-21 12:52:12 +04:00
|
|
|
Tio* GetIO() const
|
2014-07-31 15:55:29 +04:00
|
|
|
{
|
|
|
|
return mIO;
|
|
|
|
}
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
void Cancel() override
|
2014-07-31 15:55:29 +04:00
|
|
|
{
|
|
|
|
mIO = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsCanceled() const
|
|
|
|
{
|
|
|
|
return !mIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2014-10-21 12:52:12 +04:00
|
|
|
SocketIOTask(Tio* aIO)
|
2015-04-29 12:19:28 +03:00
|
|
|
: mIO(aIO)
|
2014-07-31 15:55:29 +04:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(mIO);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2014-10-21 12:52:12 +04:00
|
|
|
Tio* mIO;
|
2014-07-31 15:55:29 +04:00
|
|
|
};
|
|
|
|
|
2015-04-29 12:19:28 +03:00
|
|
|
/**
|
|
|
|
* |SocketIOShutdownTask| signals shutdown to the socket I/O class on
|
2015-06-02 11:01:58 +03:00
|
|
|
* the I/O thread and sends it to the consumer thread for destruction.
|
2014-07-31 15:55:30 +04:00
|
|
|
*/
|
2015-04-29 12:19:28 +03:00
|
|
|
class SocketIOShutdownTask final : public SocketIOTask<SocketIOBase>
|
2014-07-31 15:55:30 +04:00
|
|
|
{
|
|
|
|
public:
|
2015-04-29 12:19:28 +03:00
|
|
|
SocketIOShutdownTask(SocketIOBase* aIO);
|
2015-07-21 09:06:29 +03:00
|
|
|
~SocketIOShutdownTask();
|
2014-07-31 15:55:30 +04:00
|
|
|
|
2015-04-29 12:19:28 +03:00
|
|
|
void Run() override;
|
2014-07-31 15:55:30 +04:00
|
|
|
};
|
|
|
|
|
2014-07-31 15:55:27 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|