3 #include <winpr/thread.h>
4 #include <winpr/collections.h>
6 static DWORD WINAPI message_echo_pipe_client_thread(LPVOID arg)
13 wMessage message = { 0 };
16 if (!MessageQueue_Post(pipe->In, NULL, 0, (
void*)(
size_t)index, NULL))
19 if (!MessageQueue_Wait(pipe->Out))
22 if (!MessageQueue_Peek(pipe->Out, &message, TRUE))
25 if (message.id == WMQ_QUIT)
28 count = (int)(
size_t)message.wParam;
31 printf(
"Echo count mismatch: Actual: %d, Expected: %d\n", count, index);
36 MessageQueue_PostQuit(pipe->In, 0);
41 static DWORD WINAPI message_echo_pipe_server_thread(LPVOID arg)
43 wMessage message = { 0 };
46 while (MessageQueue_Wait(pipe->In))
48 if (MessageQueue_Peek(pipe->In, &message, TRUE))
50 if (message.id == WMQ_QUIT)
53 if (!MessageQueue_Dispatch(pipe->Out, &message))
61 int TestMessagePipe(
int argc,
char* argv[])
63 HANDLE ClientThread = NULL;
64 HANDLE ServerThread = NULL;
71 if (!(EchoPipe = MessagePipe_New()))
73 printf(
"failed to create message pipe\n");
78 CreateThread(NULL, 0, message_echo_pipe_client_thread, (
void*)EchoPipe, 0, NULL)))
80 printf(
"failed to create client thread\n");
85 CreateThread(NULL, 0, message_echo_pipe_server_thread, (
void*)EchoPipe, 0, NULL)))
87 printf(
"failed to create server thread\n");
91 (void)WaitForSingleObject(ClientThread, INFINITE);
92 (void)WaitForSingleObject(ServerThread, INFINITE);
98 MessagePipe_Free(EchoPipe);
100 (void)CloseHandle(ClientThread);
102 (void)CloseHandle(ServerThread);