1
0
mirror of https://github.com/haiwen/libsearpc.git synced 2025-09-17 15:28:05 +00:00

Waiting with WaitNamedPipe() if a named pipe is busy (#62)

Co-authored-by: Dmitry Bolshakov <d.bolshakov@bi.zone>
This commit is contained in:
Dmitry Bolshakov
2023-02-24 07:03:43 +03:00
committed by GitHub
parent 15f6f0b9f4
commit 97e15aa5a9

View File

@@ -338,6 +338,8 @@ int searpc_named_pipe_client_connect(SearpcNamedPipeClient *client)
#else // !defined(WIN32)
SearpcNamedPipe pipe_fd;
for (;;) {
pipe_fd = CreateFile(
client->path, // pipe name
GENERIC_READ | // read and write access
@@ -348,10 +350,16 @@ int searpc_named_pipe_client_connect(SearpcNamedPipeClient *client)
0, // default attributes
NULL); // no template file
if (pipe_fd == INVALID_HANDLE_VALUE) {
if (pipe_fd != INVALID_HANDLE_VALUE) {
break;
}
/* wait with default timeout (approx. 50ms) */
if (GetLastError() != ERROR_PIPE_BUSY || !WaitNamedPipe(client->path, NMPWAIT_USE_DEFAULT_WAIT)) {
G_WARNING_WITH_LAST_ERROR("Failed to connect to named pipe");
return -1;
}
}
DWORD mode = PIPE_READMODE_MESSAGE;
if (!SetNamedPipeHandleState(pipe_fd, &mode, NULL, NULL)) {