@@ -106,9 +106,8 @@ ReadThread(_In_ LPVOID lpParameter)
106
106
}
107
107
108
108
if (!ReadFile (WINHANDLE (pio ), pio -> read_details .buf ,
109
- pio -> read_details .buf_size , & read_status .transferred , NULL )) {
110
- read_status .error = GetLastError ();
111
- debug ("ReadThread - ReadFile failed %d, io:%p" , GetLastError (), pio );
109
+ pio -> read_details .buf_size , & read_status .transferred , NULL )) {
110
+ read_status .error = GetLastError ();
112
111
return -1 ;
113
112
}
114
113
@@ -127,13 +126,11 @@ ReadThread(_In_ LPVOID lpParameter)
127
126
} else {
128
127
if (!ReadFile (WINHANDLE (pio ), pio -> read_details .buf ,
129
128
pio -> read_details .buf_size , & read_status .transferred , NULL )) {
130
- read_status .error = GetLastError ();
131
- debug ("ReadThread - ReadFile failed %d, io:%p" , GetLastError (), pio );
129
+ read_status .error = GetLastError ();
132
130
return -1 ;
133
131
}
134
132
}
135
- if (0 == QueueUserAPC (ReadAPCProc , main_thread , (ULONG_PTR )pio )) {
136
- debug3 ("TermRead thread - ERROR QueueUserAPC failed %d, io:%p" , GetLastError (), pio );
133
+ if (0 == QueueUserAPC (ReadAPCProc , main_thread , (ULONG_PTR )pio )) {
137
134
pio -> read_details .pending = FALSE;
138
135
pio -> read_details .error = GetLastError ();
139
136
DebugBreak ();
@@ -256,8 +253,12 @@ syncio_close(struct w32_io* pio)
256
253
257
254
/* If io is pending, let worker threads exit. */
258
255
if (pio -> read_details .pending ) {
259
- /* For console - the read thread is blocked so terminate it. */
260
- if (FILETYPE (pio ) == FILE_TYPE_CHAR && in_raw_mode )
256
+ /*
257
+ Terminate the read thread at the below situations:
258
+ 1. For console - the read thread is blocked by the while loop on raw mode
259
+ 2. Function ReadFile on Win7 machine dees not return when no content to read in non-interactive mode.
260
+ */
261
+ if (FILETYPE (pio ) == FILE_TYPE_CHAR && (IsWin7OrLess () || in_raw_mode ))
261
262
TerminateThread (pio -> read_overlapped .hEvent , 0 );
262
263
else
263
264
WaitForSingleObject (pio -> read_overlapped .hEvent , INFINITE );
0 commit comments