Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Faylor <me@cgf.cx>2002-12-14 21:01:08 +0300
committerChristopher Faylor <me@cgf.cx>2002-12-14 21:01:08 +0300
commit3627f682fe535c3b04b1a3fc02637d2061e9e1c8 (patch)
tree5c1b3bdc0a1772b41f63108eaaecfdf9022f71f4
parent85ecb9be00c71d3bc2bc66c2c166d7a8245a8c1d (diff)
* 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.
-rw-r--r--winsup/cygwin/ChangeLog9
-rw-r--r--winsup/cygwin/fhandler.cc102
2 files changed, 57 insertions, 54 deletions
diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog
index 484ca0f11..a73b99016 100644
--- a/winsup/cygwin/ChangeLog
+++ b/winsup/cygwin/ChangeLog
@@ -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>
* dcrt0.cc (dll_crt0_1): Call well known SID initializer function.
diff --git a/winsup/cygwin/fhandler.cc b/winsup/cygwin/fhandler.cc
index b1b53e31d..a96f99c69 100644
--- a/winsup/cygwin/fhandler.cc
+++ b/winsup/cygwin/fhandler.cc
@@ -254,13 +254,24 @@ fhandler_base::raw_read (void *ptr, size_t& ulen)
{
#define bytes_read ((ssize_t) ulen)
+ HANDLE h = NULL; /* grumble */
+ int prio = 0; /* ditto */
DWORD len = ulen;
+
(ssize_t) ulen = -1;
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);
if (read_state)
- SetEvent (read_state);
+ {
+ SetEvent (read_state);
+ (void) SetThreadPriority (h, prio);
+ }
if (!res)
{
/* Some errors are not really errors. Detect such cases here. */
@@ -497,7 +508,6 @@ done:
void
fhandler_base::read (void *in_ptr, size_t& len)
{
- size_t in_len = len;
char *ptr = (char *) in_ptr;
ssize_t copied_chars = 0;
int c;
@@ -514,53 +524,31 @@ fhandler_base::read (void *in_ptr, size_t& len)
if (copied_chars && is_slow ())
{
len = (size_t) copied_chars;
- return;
+ goto out;
}
- 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)
+ if (!len)
{
len = (size_t) copied_chars;
- return;
- }
-
- if (get_r_binary ())
- {
- debug_printf ("returning %d chars, binary mode", len);
- return;
+ goto out;
}
-#if 0
- char *ctrlzpos;
- /* Scan buffer for a control-z and shorten the buffer to that length */
+ raw_read (ptr + copied_chars, len);
+ if (!copied_chars)
+ /* nothing */;
+ else if ((ssize_t) len > 0)
+ len += copied_chars;
+ else
+ len = copied_chars;
- 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
+ if (get_r_binary () || len <= 0)
+ goto out;
/* Scan buffer and turn \r\n into \n */
- char *src = (char *) ptr;
- char *dst = (char *) ptr;
- char *end = src + len - 1;
+ char *src, *dst, *end;
+ src = (char *) ptr;
+ dst = (char *) ptr;
+ end = src + len - 1;
/* Read up to the last but one char - the last char needs special handling */
while (src < end)
@@ -570,25 +558,29 @@ fhandler_base::read (void *in_ptr, size_t& len)
*dst++ = *src++;
}
- len = dst - (char *) ptr;
-
- /* if last char is a '\r' then read one more to see if we should
- translate this one too */
- if (len < in_len && *src == '\r')
+ /* If not beyond end and last char is a '\r' then read one more
+ to see if we should translate this one too */
+ if (src > end)
+ /* nothing */;
+ else if (*src != '\r')
+ *dst++ = *src;
+ else
{
- size_t clen = 1;
- raw_read (&c, clen);
- if (clen <= 0)
+ char c1;
+ size_t c1len = 1;
+ raw_read (&c1, c1len);
+ if (c1len <= 0)
/* nothing */;
- else if (c != '\n')
- set_readahead_valid (1, c);
+ else if (c1 == '\n')
+ *dst++ = '\n';
else
{
- *dst++ = '\n';
- len++;
+ set_readahead_valid (1, c1);
+ *dst++ = *src;
}
}
+ len = dst - (char *) ptr;
#ifndef NOSTRACE
if (strace.active)
@@ -608,7 +600,9 @@ fhandler_base::read (void *in_ptr, size_t& len)
}
#endif
- debug_printf ("returning %d chars, text mode", len);
+out:
+ debug_printf ("returning %d, %s mode", len,
+ get_r_binary () ? "binary" : "text");
return;
}