ezEngine  Release 25.03
ezIpcChannel Class Referenceabstract

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< ConnectionStateGetConnectionState () 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< ezIpcChannelCreatePipeChannel (ezStringView sAddress, Mode::Enum mode)
 Creates an IPC communication channel using pipes. More...
 
static ezInternal::NewInstance< ezIpcChannelCreateNetworkChannel (ezStringView sAddress, Mode::Enum mode)
 

Public Attributes

ezEvent< const ezIpcChannelEvent &, ezMutexm_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::Enumm_iConnectionState = ConnectionState::Disconnected
 
ezString m_sAddress
 
const ezEnum< Modem_Mode
 
ezMessageLoopm_pOwner = nullptr
 
ezMutex m_OutputQueueMutex
 
ezDeque< ezContiguousMemoryStreamStoragem_OutputQueue
 
ezDynamicArray< ezUInt8 > m_MessageAccumulator
 Message is assembled in here.
 
ezMutex m_ReceiveCallbackMutex
 
ReceiveCallback m_ReceiveCallback
 
ezThreadSignal m_IncomingMessages
 

Friends

class ezMessageLoop
 

Detailed Description

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.

Member Enumeration Documentation

◆ Constants

enum ezIpcChannel::Constants : ezUInt32
protected
Enumerator
HEADER_SIZE 

Magic value and size ezUint32.

MAGIC_VALUE 

Magic value.

MAX_MESSAGE_SIZE 

Arbitrary message size limit.

Member Function Documentation

◆ CreatePipeChannel()

ezInternal::NewInstance< ezIpcChannel > ezIpcChannel::CreatePipeChannel ( ezStringView  sAddress,
Mode::Enum  mode 
)
static

Creates an IPC communication channel using pipes.

Parameters
szAddressName of the pipe, must be unique on a system and less than 200 characters.
modeWhether to run in client or server mode.

The documentation for this class was generated from the following files: