![]() |
ezEngine
Release 25.03
|
Base class for a communication channel between processes. More...
#include <IpcChannel.h>
Classes | |
struct | ConnectionState |
struct | Mode |
Public Types | |
using | ReceiveCallback = ezDelegate< void(ezArrayPtr< const ezUInt8 > message)> |
Public Member Functions | |
void | Connect () |
Connects async. On success, m_Events will be broadcasted. | |
void | Disconnect () |
Disconnect async. On completion, m_Events will be broadcasted. | |
bool | IsConnected () const |
Returns whether we have a connection. | |
ezEnum< ConnectionState > | GetConnectionState () const |
Returns the current state of the connection. | |
bool | Send (ezArrayPtr< const ezUInt8 > data) |
Sends a message. pMsg can be destroyed after the call. | |
void | SetReceiveCallback (ReceiveCallback callback) |
ezResult | WaitForMessages (ezTime timeout) |
Block and wait for new messages and call ProcessMessages. | |
Static Public Member Functions | |
static ezInternal::NewInstance< ezIpcChannel > | CreatePipeChannel (ezStringView sAddress, Mode::Enum mode) |
Creates an IPC communication channel using pipes. More... | |
static ezInternal::NewInstance< ezIpcChannel > | CreateNetworkChannel (ezStringView sAddress, Mode::Enum mode) |
Public Attributes | |
ezEvent< const ezIpcChannelEvent &, ezMutex > | m_Events |
Will be sent from any thread. | |
Protected Types | |
enum | Constants : ezUInt32 { HEADER_SIZE = 8, MAGIC_VALUE = 'USED', MAX_MESSAGE_SIZE = 1024 * 1024 * 16 } |
Protected Member Functions | |
ezIpcChannel (ezStringView sAddress, Mode::Enum mode) | |
virtual bool | RequiresRegularTick () |
Override this and return true, if the surrounding infrastructure should call the 'Tick()' function. | |
virtual void | Tick () |
Can implement regular updates, e.g. for polling network state. | |
virtual void | InternalConnect ()=0 |
Called on worker thread after Connect was called. | |
virtual void | InternalDisconnect ()=0 |
Called on worker thread after Disconnect was called. | |
virtual void | InternalSend ()=0 |
Called on worker thread to sent pending messages. | |
virtual bool | NeedWakeup () const =0 |
Called by Send to determine whether the message loop need to be woken up. | |
void | SetConnectionState (ezEnum< ConnectionState > state) |
void | ReceiveData (ezArrayPtr< const ezUInt8 > data) |
Implementation needs to call this when new data has been received. data can be invalidated after the function. | |
void | FlushPendingOperations () |
Protected Attributes | |
ezThreadID | m_ThreadId = 0 |
ezAtomicInteger< ConnectionState::Enum > | m_iConnectionState = ConnectionState::Disconnected |
ezString | m_sAddress |
const ezEnum< Mode > | m_Mode |
ezMessageLoop * | m_pOwner = nullptr |
ezMutex | m_OutputQueueMutex |
ezDeque< ezContiguousMemoryStreamStorage > | m_OutputQueue |
ezDynamicArray< ezUInt8 > | m_MessageAccumulator |
Message is assembled in here. | |
ezMutex | m_ReceiveCallbackMutex |
ReceiveCallback | m_ReceiveCallback |
ezThreadSignal | m_IncomingMessages |
Friends | |
class | ezMessageLoop |
Base class for a communication channel between processes.
The channel allows for byte blobs to be send back and forth between two processes. A client should only try to connect to a server once the server has changed to ConnectionState::Connecting as this indicates the server is ready to be conneccted to.
Use ezIpcChannel:::CreatePipeChannel to create an IPC pipe instance. To send more complex messages accross, you can create a ezIpcProcessMessageProtocol on top of the channel.
|
protected |
|
static |
Creates an IPC communication channel using pipes.
szAddress | Name of the pipe, must be unique on a system and less than 200 characters. |
mode | Whether to run in client or server mode. |