- if (pipehandle == INVALID_HANDLE_VALUE) {
- err = dupprintf("Unable to open named pipe '%s': %s",
- pipename, win_strerror(GetLastError()));
- ret = new_error_socket(err, plug);
- sfree(err);
- return ret;
+ if (pipehandle != INVALID_HANDLE_VALUE)
+ break;
+
+ if (GetLastError() != ERROR_PIPE_BUSY) {
+ err = dupprintf("Unable to open named pipe '%s': %s",
+ pipename, win_strerror(GetLastError()));
+ ret = new_error_socket(err, plug);
+ sfree(err);
+ return ret;
+ }
+
+ /*
+ * If we got ERROR_PIPE_BUSY, wait for the server to
+ * create a new pipe instance. (Since the server is
+ * expected to be winnps.c, which will do that immediately
+ * after a previous connection is accepted, that shouldn't
+ * take excessively long.)
+ */
+ if (!WaitNamedPipe(pipename, NMPWAIT_USE_DEFAULT_WAIT)) {
+ err = dupprintf("Error waiting for named pipe '%s': %s",
+ pipename, win_strerror(GetLastError()));
+ ret = new_error_socket(err, plug);
+ sfree(err);
+ return ret;
+ }