fix problem with Windows pipe writing
This commit is contained in:
parent
c9e84f9f67
commit
63ec520885
|
@ -1,9 +1,10 @@
|
||||||
#lang racket
|
#lang racket/base
|
||||||
|
|
||||||
;; Implements a "cat.exe" executable under Windows for the
|
;; Implements a "cat.exe" executable under Windows for the
|
||||||
;; "subprocess.rktl" test.
|
;; "subprocess.rktl" test.
|
||||||
|
|
||||||
(require racket/port)
|
(require racket/port
|
||||||
|
racket/cmdline)
|
||||||
|
|
||||||
(define files
|
(define files
|
||||||
(command-line
|
(command-line
|
||||||
|
|
|
@ -273,6 +273,7 @@ typedef struct Scheme_FD {
|
||||||
# ifdef WINDOWS_FILE_HANDLES
|
# ifdef WINDOWS_FILE_HANDLES
|
||||||
Win_FD_Input_Thread *th; /* input mode */
|
Win_FD_Input_Thread *th; /* input mode */
|
||||||
Win_FD_Output_Thread *oth; /* output mode */
|
Win_FD_Output_Thread *oth; /* output mode */
|
||||||
|
int unblocked; /* whether non-blocking mode is installed */
|
||||||
# endif
|
# endif
|
||||||
} Scheme_FD;
|
} Scheme_FD;
|
||||||
|
|
||||||
|
@ -6127,7 +6128,7 @@ static long flush_fd(Scheme_Output_Port *op,
|
||||||
if (nonblocking) {
|
if (nonblocking) {
|
||||||
/* Unless we're still trying to flush old data, write to the
|
/* Unless we're still trying to flush old data, write to the
|
||||||
pipe and have the other thread start flushing it. */
|
pipe and have the other thread start flushing it. */
|
||||||
DWORD old, nonblock = PIPE_NOWAIT;
|
DWORD nonblock = PIPE_NOWAIT;
|
||||||
int ok, flushed;
|
int ok, flushed;
|
||||||
|
|
||||||
if (fop->oth) {
|
if (fop->oth) {
|
||||||
|
@ -6159,12 +6160,19 @@ static long flush_fd(Scheme_Output_Port *op,
|
||||||
behaviors by trying to write less each iteration when the
|
behaviors by trying to write less each iteration when the
|
||||||
write fails. (Yuck.) */
|
write fails. (Yuck.) */
|
||||||
while (1) {
|
while (1) {
|
||||||
GetNamedPipeHandleState((HANDLE)fop->fd, &old, NULL, NULL, NULL, NULL, 0);
|
if (!fop->unblocked) {
|
||||||
SetNamedPipeHandleState((HANDLE)fop->fd, &nonblock, NULL, NULL);
|
ok = SetNamedPipeHandleState((HANDLE)fop->fd, &nonblock, NULL, NULL);
|
||||||
ok = WriteFile((HANDLE)fop->fd, bufstr XFORM_OK_PLUS offset, towrite, &winwrote, NULL);
|
if (ok)
|
||||||
if (!ok)
|
fop->unblocked = 1;
|
||||||
errsaved = GetLastError();
|
else
|
||||||
SetNamedPipeHandleState((HANDLE)fop->fd, &old, NULL, NULL);
|
errsaved = GetLastError();
|
||||||
|
} else
|
||||||
|
ok = 1;
|
||||||
|
if (ok) {
|
||||||
|
ok = WriteFile((HANDLE)fop->fd, bufstr XFORM_OK_PLUS offset, towrite, &winwrote, NULL);
|
||||||
|
if (!ok)
|
||||||
|
errsaved = GetLastError();
|
||||||
|
}
|
||||||
|
|
||||||
if ((ok && !winwrote)
|
if ((ok && !winwrote)
|
||||||
|| (!ok && (errsaved == ERROR_NOT_ENOUGH_MEMORY))) {
|
|| (!ok && (errsaved == ERROR_NOT_ENOUGH_MEMORY))) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user