client (Win): when read stderr.txt, wait for write lock to be release first.

Apparently, on Win, there is still a write lock on stderr.txt,
and its buffer isn't flushed, until shortly after the app process exits.
This is bizarre, but so be it.
This commit is contained in:
David Anderson 2015-07-14 09:41:17 -07:00
parent 883ccab46b
commit f2d690029c
1 changed files with 24 additions and 0 deletions

View File

@ -322,6 +322,30 @@ int read_file_malloc(const char* path, char*& buf, size_t max_len, bool tail) {
int retval;
double size;
// Win: if another process has this file open for writing,
// wait for up to 5 seconds.
// This is because when a job exits, the write to stderr.txt
// sometimes (inexplicably) doesn't appear immediately
#ifdef _WIN32
for (int i=0; i<5; i++) {
HANDLE h = CreateFileA(
path,
GENERIC_WRITE,
0,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL
);
if (h != INVALID_HANDLE_VALUE) {
CloseHandle(h);
break;
}
boinc_sleep(1);
}
#endif
retval = file_size(path, size);
if (retval) return retval;