* fhandler.cc (fhandler_base::raw_read): Reset priorities to minimize window
where thread termination may cause data loss. (fhandler_base::read): Always return at end of function. Just set len to copied_chars when len is zero. Return immediately after raw_read if len <= 0. Remove in_len setting and just check end instead. Fix CRLF handling at end of buffer.
This commit is contained in:
parent
85ecb9be00
commit
3627f682fe
@ -1,3 +1,12 @@
|
|||||||
|
2002-12-14 Christopher Faylor <cgf@redhat.com>
|
||||||
|
|
||||||
|
* fhandler.cc (fhandler_base::raw_read): Reset priorities to minimize
|
||||||
|
window where thread termination may cause data loss.
|
||||||
|
(fhandler_base::read): Always return at end of function. Just set len
|
||||||
|
to copied_chars when len is zero. Return immediately after raw_read if
|
||||||
|
len <= 0. Remove in_len setting and just check end instead. Fix CRLF
|
||||||
|
handling at end of buffer.
|
||||||
|
|
||||||
2002-12-14 Corinna Vinschen <corinna@vinschen.de>
|
2002-12-14 Corinna Vinschen <corinna@vinschen.de>
|
||||||
|
|
||||||
* dcrt0.cc (dll_crt0_1): Call well known SID initializer function.
|
* dcrt0.cc (dll_crt0_1): Call well known SID initializer function.
|
||||||
|
@ -254,13 +254,24 @@ fhandler_base::raw_read (void *ptr, size_t& ulen)
|
|||||||
{
|
{
|
||||||
#define bytes_read ((ssize_t) ulen)
|
#define bytes_read ((ssize_t) ulen)
|
||||||
|
|
||||||
|
HANDLE h = NULL; /* grumble */
|
||||||
|
int prio = 0; /* ditto */
|
||||||
DWORD len = ulen;
|
DWORD len = ulen;
|
||||||
|
|
||||||
(ssize_t) ulen = -1;
|
(ssize_t) ulen = -1;
|
||||||
if (read_state)
|
if (read_state)
|
||||||
SetEvent (read_state);
|
{
|
||||||
|
h = GetCurrentThread ();
|
||||||
|
prio = GetThreadPriority (h);
|
||||||
|
(void) SetThreadPriority (h, THREAD_PRIORITY_TIME_CRITICAL);
|
||||||
|
SetEvent (read_state);
|
||||||
|
}
|
||||||
BOOL res = ReadFile (get_handle (), ptr, len, (DWORD *) &ulen, 0);
|
BOOL res = ReadFile (get_handle (), ptr, len, (DWORD *) &ulen, 0);
|
||||||
if (read_state)
|
if (read_state)
|
||||||
SetEvent (read_state);
|
{
|
||||||
|
SetEvent (read_state);
|
||||||
|
(void) SetThreadPriority (h, prio);
|
||||||
|
}
|
||||||
if (!res)
|
if (!res)
|
||||||
{
|
{
|
||||||
/* Some errors are not really errors. Detect such cases here. */
|
/* Some errors are not really errors. Detect such cases here. */
|
||||||
@ -497,7 +508,6 @@ done:
|
|||||||
void
|
void
|
||||||
fhandler_base::read (void *in_ptr, size_t& len)
|
fhandler_base::read (void *in_ptr, size_t& len)
|
||||||
{
|
{
|
||||||
size_t in_len = len;
|
|
||||||
char *ptr = (char *) in_ptr;
|
char *ptr = (char *) in_ptr;
|
||||||
ssize_t copied_chars = 0;
|
ssize_t copied_chars = 0;
|
||||||
int c;
|
int c;
|
||||||
@ -514,53 +524,31 @@ fhandler_base::read (void *in_ptr, size_t& len)
|
|||||||
if (copied_chars && is_slow ())
|
if (copied_chars && is_slow ())
|
||||||
{
|
{
|
||||||
len = (size_t) copied_chars;
|
len = (size_t) copied_chars;
|
||||||
return;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (len)
|
if (!len)
|
||||||
{
|
|
||||||
raw_read (ptr + copied_chars, len);
|
|
||||||
if (!copied_chars)
|
|
||||||
/* nothing */;
|
|
||||||
else if ((ssize_t) len > 0)
|
|
||||||
len += copied_chars;
|
|
||||||
else
|
|
||||||
len = copied_chars;
|
|
||||||
}
|
|
||||||
else if (copied_chars <= 0)
|
|
||||||
{
|
{
|
||||||
len = (size_t) copied_chars;
|
len = (size_t) copied_chars;
|
||||||
return;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (get_r_binary ())
|
raw_read (ptr + copied_chars, len);
|
||||||
{
|
if (!copied_chars)
|
||||||
debug_printf ("returning %d chars, binary mode", len);
|
/* nothing */;
|
||||||
return;
|
else if ((ssize_t) len > 0)
|
||||||
}
|
len += copied_chars;
|
||||||
|
else
|
||||||
|
len = copied_chars;
|
||||||
|
|
||||||
#if 0
|
if (get_r_binary () || len <= 0)
|
||||||
char *ctrlzpos;
|
goto out;
|
||||||
/* Scan buffer for a control-z and shorten the buffer to that length */
|
|
||||||
|
|
||||||
ctrlzpos = (char *) memchr ((char *) ptr, 0x1a, copied_chars);
|
|
||||||
if (ctrlzpos)
|
|
||||||
{
|
|
||||||
lseek ((ctrlzpos - ((char *) ptr + copied_chars)), SEEK_CUR);
|
|
||||||
copied_chars = ctrlzpos - (char *) ptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (copied_chars == 0)
|
|
||||||
{
|
|
||||||
debug_printf ("returning 0 chars, text mode, CTRL-Z found");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Scan buffer and turn \r\n into \n */
|
/* Scan buffer and turn \r\n into \n */
|
||||||
char *src = (char *) ptr;
|
char *src, *dst, *end;
|
||||||
char *dst = (char *) ptr;
|
src = (char *) ptr;
|
||||||
char *end = src + len - 1;
|
dst = (char *) ptr;
|
||||||
|
end = src + len - 1;
|
||||||
|
|
||||||
/* Read up to the last but one char - the last char needs special handling */
|
/* Read up to the last but one char - the last char needs special handling */
|
||||||
while (src < end)
|
while (src < end)
|
||||||
@ -570,25 +558,29 @@ fhandler_base::read (void *in_ptr, size_t& len)
|
|||||||
*dst++ = *src++;
|
*dst++ = *src++;
|
||||||
}
|
}
|
||||||
|
|
||||||
len = dst - (char *) ptr;
|
/* If not beyond end and last char is a '\r' then read one more
|
||||||
|
to see if we should translate this one too */
|
||||||
/* if last char is a '\r' then read one more to see if we should
|
if (src > end)
|
||||||
translate this one too */
|
/* nothing */;
|
||||||
if (len < in_len && *src == '\r')
|
else if (*src != '\r')
|
||||||
|
*dst++ = *src;
|
||||||
|
else
|
||||||
{
|
{
|
||||||
size_t clen = 1;
|
char c1;
|
||||||
raw_read (&c, clen);
|
size_t c1len = 1;
|
||||||
if (clen <= 0)
|
raw_read (&c1, c1len);
|
||||||
|
if (c1len <= 0)
|
||||||
/* nothing */;
|
/* nothing */;
|
||||||
else if (c != '\n')
|
else if (c1 == '\n')
|
||||||
set_readahead_valid (1, c);
|
*dst++ = '\n';
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
*dst++ = '\n';
|
set_readahead_valid (1, c1);
|
||||||
len++;
|
*dst++ = *src;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
len = dst - (char *) ptr;
|
||||||
|
|
||||||
#ifndef NOSTRACE
|
#ifndef NOSTRACE
|
||||||
if (strace.active)
|
if (strace.active)
|
||||||
@ -608,7 +600,9 @@ fhandler_base::read (void *in_ptr, size_t& len)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
debug_printf ("returning %d chars, text mode", len);
|
out:
|
||||||
|
debug_printf ("returning %d, %s mode", len,
|
||||||
|
get_r_binary () ? "binary" : "text");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user