aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Faylor <me@cgf.cx>2001-11-03 05:42:21 +0000
committerChristopher Faylor <me@cgf.cx>2001-11-03 05:42:21 +0000
commitc41570695a46cf3a4f1cf3f72db353c963f40f7e (patch)
treec46d10c143594b112016b62f07ddfa3d3d79a85f
parent243a041bd0164aa62813ac4ba5a1a02eb2db455b (diff)
downloadnewlib-c41570695a46cf3a4f1cf3f72db353c963f40f7e.zip
newlib-c41570695a46cf3a4f1cf3f72db353c963f40f7e.tar.gz
newlib-c41570695a46cf3a4f1cf3f72db353c963f40f7e.tar.bz2
* fhandler.cc (fhandler_base::read): Return just read ahead characters if slow
device. * fhandler.h (fhandler_base::set_eof): New virtual method. (fhandler_pipe::set_eof): New method. * pipe.cc (fhandler_pipe::fhandler_pipe): Clear saweof flag. (fhandler_pipe::read): Return immediately if hit eof. (fhandler_pipe::hit_eof): Return true if saweof flag is set. * select.cc (peek_pipe): Don't call PeekNamedPipe if we couldn't grab the guard mutex.
-rw-r--r--winsup/cygwin/ChangeLog12
-rw-r--r--winsup/cygwin/fhandler.cc3
-rw-r--r--winsup/cygwin/fhandler.h38
-rw-r--r--winsup/cygwin/pipe.cc8
-rw-r--r--winsup/cygwin/select.cc21
5 files changed, 36 insertions, 46 deletions
diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog
index a519205..bc752f6 100644
--- a/winsup/cygwin/ChangeLog
+++ b/winsup/cygwin/ChangeLog
@@ -1,3 +1,15 @@
+2001-11-03 Christopher Faylor <cgf@redhat.com>
+
+ * fhandler.cc (fhandler_base::read): Return just read ahead characters
+ if slow device.
+ * fhandler.h (fhandler_base::set_eof): New virtual method.
+ (fhandler_pipe::set_eof): New method.
+ * pipe.cc (fhandler_pipe::fhandler_pipe): Clear saweof flag.
+ (fhandler_pipe::read): Return immediately if hit eof.
+ (fhandler_pipe::hit_eof): Return true if saweof flag is set.
+ * select.cc (peek_pipe): Don't call PeekNamedPipe if we couldn't grab
+ the guard mutex.
+
2001-11-02 Egor Duda <deo@logos-m.ru>
* dll_init.h (class dll_list): Reorder functions to avoid compiler
diff --git a/winsup/cygwin/fhandler.cc b/winsup/cygwin/fhandler.cc
index 1db9a7b..c2431d6 100644
--- a/winsup/cygwin/fhandler.cc
+++ b/winsup/cygwin/fhandler.cc
@@ -479,6 +479,9 @@ fhandler_base::read (void *in_ptr, size_t in_len)
len--;
}
+ if (copied_chars && is_slow ())
+ return copied_chars;
+
if (len)
{
int readlen = raw_read (ptr + copied_chars, len);
diff --git a/winsup/cygwin/fhandler.h b/winsup/cygwin/fhandler.h
index fa753cd..a98bec4 100644
--- a/winsup/cygwin/fhandler.h
+++ b/winsup/cygwin/fhandler.h
@@ -13,41 +13,6 @@ details. */
#include <sys/ioctl.h>
-/* Classes
-
- Code is located in fhandler.cc unless another file name is given.
-
- fhandler_base normal I/O
-
- fhandler_disk_file
- fhandler_serial Adds vmin and vtime.
- fhandler_dev_null Not really I/O
- fhandler_dev_zero Faked
-
- fhandler_dev_raw (fhandler_raw.cc)
- fhandler_dev_floppy (fhandler_floppy.cc)
- fhandler_dev_tape (fhandler_tape.cc)
-
- fhandler_pipe
- fhandler_socket (fhandler_socket.cc)
-
- fhandler_tty_slave (tty.cc)
- fhandler_pty_master (tty.cc)
- fhandler_tty_master (tty.cc)
-
- fhandler_console Out with ansi control. (console.cc)
-
- fhandler_windows Windows messages I/O (fhandler_windows.cc)
-
- fhandler_dev_random /dev/[u]random implementation (fhandler_random.cc)
-
- fhandler_dev_mem /dev/mem implementation (fhandler_mem.cc)
-
- fhandler_dev_clipboard /dev/clipboard implementation (fhandler_clipboard.cc)
-
- fhandler_proc Interesting possibility, not implemented yet
-*/
-
enum
{
FH_RBINARY = 0x00001000, /* binary read mode */
@@ -372,6 +337,7 @@ class fhandler_base
}
void operator delete (void *);
virtual HANDLE get_guard () const {return NULL;}
+ virtual void set_eof () {}
};
class fhandler_socket: public fhandler_base
@@ -425,6 +391,7 @@ class fhandler_socket: public fhandler_base
class fhandler_pipe: public fhandler_base
{
HANDLE guard;
+ bool saweof;
HANDLE writepipe_exists;
DWORD orig_pid;
unsigned id;
@@ -441,6 +408,7 @@ class fhandler_pipe: public fhandler_base
int dup (fhandler_base *child);
void fixup_after_fork (HANDLE);
bool hit_eof ();
+ void set_eof () {saweof = true;}
friend int make_pipe (int fildes[2], unsigned int psize, int mode);
HANDLE get_guard () const {return guard;}
};
diff --git a/winsup/cygwin/pipe.cc b/winsup/cygwin/pipe.cc
index 904dbd2..87d226b 100644
--- a/winsup/cygwin/pipe.cc
+++ b/winsup/cygwin/pipe.cc
@@ -26,7 +26,7 @@ static unsigned pipecount;
static const NO_COPY char pipeid_fmt[] = "stupid_pipe.%u.%u";
fhandler_pipe::fhandler_pipe (DWORD devtype)
- : fhandler_base (devtype), guard (NULL), writepipe_exists(0),
+ : fhandler_base (devtype), guard (NULL), saweof (false), writepipe_exists(0),
orig_pid (0), id (0)
{
}
@@ -52,8 +52,10 @@ fhandler_pipe::set_close_on_exec (int val)
int __stdcall
fhandler_pipe::read (void *in_ptr, size_t in_len)
{
+ if (hit_eof ())
+ return 0;
int res = this->fhandler_base::read (in_ptr, in_len);
- ReleaseMutex (guard);
+ (void) ReleaseMutex (guard);
return res;
}
@@ -72,6 +74,8 @@ fhandler_pipe::hit_eof ()
{
char buf[80];
HANDLE ev;
+ if (saweof)
+ return 1;
if (!orig_pid)
return false;
__small_sprintf (buf, pipeid_fmt, orig_pid, id);
diff --git a/winsup/cygwin/select.cc b/winsup/cygwin/select.cc
index 78d1aaa..e2bd711 100644
--- a/winsup/cygwin/select.cc
+++ b/winsup/cygwin/select.cc
@@ -389,9 +389,9 @@ peek_pipe (select_record *s, int ignra)
fhandler_base *fh = s->fh;
HANDLE h;
- HANDLE guard_mutex = fh->get_guard ();
set_handle_or_return_if_not_open (h, s);
+ HANDLE guard_mutex = fh->get_guard ();
/* Don't perform complicated tests if we don't need to. */
if (!s->read_selected && !s->except_selected)
goto out;
@@ -438,16 +438,18 @@ peek_pipe (select_record *s, int ignra)
select_printf ("%s, PeekNamedPipe failed, %E", fh->get_name ());
n = -1;
}
- else if (n && guard_mutex)
+ else if (!n || !guard_mutex)
+ /* nothing */;
+ else if (WaitForSingleObject (guard_mutex, 0) != WAIT_OBJECT_0)
+ {
+ select_printf ("%s, couldn't get mutex %p, %E", fh->get_name (),
+ guard_mutex);
+ n = 0;
+ }
+ else
{
- if (WaitForSingleObject (guard_mutex, 0) != WAIT_OBJECT_0)
- {
- select_printf ("%s, couldn't get mutex %p, %E", fh->get_name (),
- guard_mutex);
- n = 0;
- }
/* Now that we have the mutex, make sure that no one else has snuck
- in and grabbed the data that we originally saw. */
+ in and grabbed the data that we originally saw. */
if (!PeekNamedPipe (h, NULL, 0, NULL, (DWORD *) &n, NULL))
{
select_printf ("%s, PeekNamedPipe failed, %E", fh->get_name ());
@@ -459,6 +461,7 @@ peek_pipe (select_record *s, int ignra)
if (n < 0)
{
+ fh->set_eof ();
select_printf ("%s, n %d", fh->get_name (), n);
if (s->except_selected)
gotone += s->except_ready = TRUE;