Windows
异步IPC
MSDN:https://docs.microsoft.com/zh-cn/windows/win32/sync/asynchronous-procedure-calls
// 创建IPC实例
ASYNCIPC_API int CreateInstance(PipeImplType name, INamedPipe** pipe);
// 初 始 化 日 志 库
ASYNCIPC_API void InitEasyLog(const char* process_name);
class INamedPipe
{
public:
virtual bool Create(const wchar_t* pipe_name, PipeType type, IPipeDelegate* delegate) = 0;
virtual void Exit() = 0;
virtual void Send(const char* msg) = 0;
};
class IPipeDelegate {
public:
virtual void OnCreate(bool) = 0;
virtual void OnConnected(bool) = 0;
virtual void OnSend(int size) = 0;
virtual void OnRecv(void* data, int size) = 0;
virtual void OnDisconnected() = 0;
};
#define ENABLE_ASYNCPIPE
INamedPipe* pipe_server_ = nullptr;
...
PipeCallback pipe_clllback;
PipeImplType name;
#ifdef ENABLE_ASYNCPIPE
name = PIPE_ASYNC;
#else
name = PIPE_OVERLAPPED;
#endif
CreateInstance(name, &pipe_server_);
pipe_server_->Create(kPipeName, PIPE_SERVER, &pipe_clllback);
...
pipe_server_->Send(text);
...
pipe_server_->Exit();
#define ENABLE_ASYNCPIPE
INamedPipe* pipe_client_ = nullptr;
PipeCallback pipe_clllback;
PipeImplType name;
#ifdef ENABLE_ASYNCPIPE
name = PIPE_ASYNC;
#else
name = PIPE_OVERLAPPED;
#endif
CreateInstance(name, &pipe_client_);
pipe_client_->Create(kPipeName, PIPE_CLIENT, &pipe_clllback);
// send msg
pipe_client_->Send(text);
// exit
pipe_client_->Exit();
1.server
2.server
3.