1
0
mirror of https://github.com/haiwen/libsearpc.git synced 2025-09-16 23:08:14 +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,19 +338,27 @@ int searpc_named_pipe_client_connect(SearpcNamedPipeClient *client)
#else // !defined(WIN32)
SearpcNamedPipe pipe_fd;
pipe_fd = CreateFile(
client->path, // pipe name
GENERIC_READ | // read and write access
GENERIC_WRITE,
0, // no sharing
NULL, // default security attributes
OPEN_EXISTING, // opens existing pipe
0, // default attributes
NULL); // no template file
if (pipe_fd == INVALID_HANDLE_VALUE) {
G_WARNING_WITH_LAST_ERROR("Failed to connect to named pipe");
return -1;
for (;;) {
pipe_fd = CreateFile(
client->path, // pipe name
GENERIC_READ | // read and write access
GENERIC_WRITE,
0, // no sharing
NULL, // default security attributes
OPEN_EXISTING, // opens existing pipe
0, // default attributes
NULL); // no template file
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;