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:
@@ -338,6 +338,8 @@ int searpc_named_pipe_client_connect(SearpcNamedPipeClient *client)
|
|||||||
|
|
||||||
#else // !defined(WIN32)
|
#else // !defined(WIN32)
|
||||||
SearpcNamedPipe pipe_fd;
|
SearpcNamedPipe pipe_fd;
|
||||||
|
|
||||||
|
for (;;) {
|
||||||
pipe_fd = CreateFile(
|
pipe_fd = CreateFile(
|
||||||
client->path, // pipe name
|
client->path, // pipe name
|
||||||
GENERIC_READ | // read and write access
|
GENERIC_READ | // read and write access
|
||||||
@@ -348,10 +350,16 @@ int searpc_named_pipe_client_connect(SearpcNamedPipeClient *client)
|
|||||||
0, // default attributes
|
0, // default attributes
|
||||||
NULL); // no template file
|
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");
|
G_WARNING_WITH_LAST_ERROR("Failed to connect to named pipe");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
DWORD mode = PIPE_READMODE_MESSAGE;
|
DWORD mode = PIPE_READMODE_MESSAGE;
|
||||||
if (!SetNamedPipeHandleState(pipe_fd, &mode, NULL, NULL)) {
|
if (!SetNamedPipeHandleState(pipe_fd, &mode, NULL, NULL)) {
|
||||||
|
Reference in New Issue
Block a user