Plasma Engine  2.0
Loading...
Searching...
No Matches
PipeChannel_Win.h
1#pragma once
2
3#include <Foundation/FoundationInternal.h>
4PL_FOUNDATION_INTERNAL_HEADER
5
6#if PL_ENABLED(PL_PLATFORM_WINDOWS_DESKTOP)
7
8# include <Foundation/Basics.h>
9# include <Foundation/Basics/Platform/Win/IncludeWindows.h>
10# include <Foundation/Communication/IpcChannel.h>
11
12struct IOContext
13{
14 OVERLAPPED Overlapped;
15 plIpcChannel* pChannel;
16};
17
18class PL_FOUNDATION_DLL plPipeChannel_win : public plIpcChannel
19{
20public:
21 plPipeChannel_win(plStringView sAddress, Mode::Enum mode);
22 ~plPipeChannel_win();
23
24private:
25 friend class plMessageLoop;
26 friend class plMessageLoop_win;
27
28 bool CreatePipe(plStringView sAddress);
29
30 // All functions from here on down are run from worker thread only
31 virtual void InternalConnect() override;
32 virtual void InternalDisconnect() override;
33 virtual void InternalSend() override;
34 virtual bool NeedWakeup() const override;
35
36 bool ProcessConnection();
37 bool ProcessIncomingMessages(DWORD uiBytesRead);
38 bool ProcessOutgoingMessages(DWORD uiBytesWritten);
39
40
41protected:
42 void OnIOCompleted(IOContext* pContext, DWORD uiBytesTransfered, DWORD uiError);
43
44private:
45 struct State
46 {
47 explicit State(plPipeChannel_win* pChannel);
48 ~State();
49 IOContext Context;
50 plAtomicInteger32 IsPending = false;
51 };
52
53 enum Constants
54 {
55 BUFFER_SIZE = 4096,
56 };
57
58 // Shared data
59 State m_InputState;
60 State m_OutputState;
61
62 // Setup in ctor
63 HANDLE m_hPipeHandle = INVALID_HANDLE_VALUE;
64
65 // Only accessed from worker thread
66 plUInt8 m_InputBuffer[BUFFER_SIZE];
67};
68
69#endif
Base class for a communication channel between processes.
Definition IpcChannel.h:44
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 bool NeedWakeup() const =0
Called by Send to determine whether the message loop need to be woken up.
virtual void InternalSend()=0
Called on worker thread to sent pending messages.
Internal sub-system used by plIpcChannel.
Definition MessageLoop.h:20
plStringView represent a read-only sub-string of a larger string, as it can store a dedicated string ...
Definition StringView.h:34