* fhandler.cc (fhandler_base::dup): Call setup_overlapped unconditionally.
(fhandler_base::fork_fixup): Ditto. (fhandler_base::fixup_after_fork): Ditto. (fhandler_base::fixup_after_exec): Ditto. (fhandler_base_overlapped::setup_overlapped): Move to this class from fhandler_base. (handler_base_overlapped::destroy_overlapped): Ditto. (fhandler_base_overlapped::wait_overlapped): Ditto. Track when we expect pending I/O. (fhandler_base_overlapped::read_overlapped): Move to this class from fhandler_base. Return error if ongoing I/O. (fhandler_base_overlapped::write_overlapped): Ditto. (fhandler_base_overlapped::has_ongoing_io): Semi-reinstate previous function. * fhandler.h (fhandler_base::wait_overlapped): Move to fhandler_base_overlapped class. (fhandler_base::write_overlapped): Ditto. (fhandler_base::get_overlapped): Ditto. (fhandler_base::get_overlapped_buffer): Ditto. (fhandler_base_overlapped): New class. (fhandler_pipe): Inherit from fhandler_base_overlapped. Remove overlapped stuff as a result. (fhandler_fifo): Ditto. * pipe.cc (fhandler_pipe::fhandler_pipe): Initialize fhandler_base_overlapped. (pipe): Put a descriptive name in the fhandler.
This commit is contained in:
parent
d8b4cbe896
commit
2aeef06579
|
@ -1,3 +1,32 @@
|
||||||
|
2010-03-31 Christopher Faylor <me+cygwin@cgf.cx>
|
||||||
|
|
||||||
|
* fhandler.cc (fhandler_base::dup): Call setup_overlapped
|
||||||
|
unconditionally.
|
||||||
|
(fhandler_base::fork_fixup): Ditto.
|
||||||
|
(fhandler_base::fixup_after_fork): Ditto.
|
||||||
|
(fhandler_base::fixup_after_exec): Ditto.
|
||||||
|
(fhandler_base_overlapped::setup_overlapped): Move to this class from
|
||||||
|
fhandler_base.
|
||||||
|
(handler_base_overlapped::destroy_overlapped): Ditto.
|
||||||
|
(fhandler_base_overlapped::wait_overlapped): Ditto. Track when we
|
||||||
|
expect pending I/O.
|
||||||
|
(fhandler_base_overlapped::read_overlapped): Move to this class from
|
||||||
|
fhandler_base. Return error if ongoing I/O.
|
||||||
|
(fhandler_base_overlapped::write_overlapped): Ditto.
|
||||||
|
(fhandler_base_overlapped::has_ongoing_io): Semi-reinstate previous
|
||||||
|
function.
|
||||||
|
* fhandler.h (fhandler_base::wait_overlapped): Move to
|
||||||
|
fhandler_base_overlapped class.
|
||||||
|
(fhandler_base::write_overlapped): Ditto.
|
||||||
|
(fhandler_base::get_overlapped): Ditto.
|
||||||
|
(fhandler_base::get_overlapped_buffer): Ditto.
|
||||||
|
(fhandler_base_overlapped): New class.
|
||||||
|
(fhandler_pipe): Inherit from fhandler_base_overlapped. Remove
|
||||||
|
overlapped stuff as a result.
|
||||||
|
(fhandler_fifo): Ditto.
|
||||||
|
* pipe.cc (fhandler_pipe::fhandler_pipe): Initialize fhandler_base_overlapped.
|
||||||
|
(pipe): Put a descriptive name in the fhandler.
|
||||||
|
|
||||||
2010-03-30 Corinna Vinschen <corinna@vinschen.de>
|
2010-03-30 Corinna Vinschen <corinna@vinschen.de>
|
||||||
|
|
||||||
* fhandler_socket.cc (fhandler_socket::wait_for_events): Remove call to
|
* fhandler_socket.cc (fhandler_socket::wait_for_events): Remove call to
|
||||||
|
|
|
@ -1162,8 +1162,7 @@ fhandler_base::dup (fhandler_base *child)
|
||||||
VerifyHandle (nh);
|
VerifyHandle (nh);
|
||||||
child->set_io_handle (nh);
|
child->set_io_handle (nh);
|
||||||
}
|
}
|
||||||
if (get_overlapped ())
|
child->setup_overlapped ();
|
||||||
child->setup_overlapped ();
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1335,8 +1334,7 @@ fhandler_base::fork_fixup (HANDLE parent, HANDLE &h, const char *name)
|
||||||
VerifyHandle (h);
|
VerifyHandle (h);
|
||||||
res = true;
|
res = true;
|
||||||
}
|
}
|
||||||
if (get_overlapped ())
|
setup_overlapped ();
|
||||||
setup_overlapped ();
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1355,8 +1353,7 @@ fhandler_base::fixup_after_fork (HANDLE parent)
|
||||||
debug_printf ("inheriting '%s' from parent", get_name ());
|
debug_printf ("inheriting '%s' from parent", get_name ());
|
||||||
if (!nohandle ())
|
if (!nohandle ())
|
||||||
fork_fixup (parent, io_handle, "io_handle");
|
fork_fixup (parent, io_handle, "io_handle");
|
||||||
if (get_overlapped ())
|
setup_overlapped ();
|
||||||
setup_overlapped ();
|
|
||||||
/* POSIX locks are not inherited across fork. */
|
/* POSIX locks are not inherited across fork. */
|
||||||
if (unique_id)
|
if (unique_id)
|
||||||
del_my_locks (after_fork);
|
del_my_locks (after_fork);
|
||||||
|
@ -1366,8 +1363,7 @@ void
|
||||||
fhandler_base::fixup_after_exec ()
|
fhandler_base::fixup_after_exec ()
|
||||||
{
|
{
|
||||||
debug_printf ("here for '%s'", get_name ());
|
debug_printf ("here for '%s'", get_name ());
|
||||||
if (get_overlapped ())
|
setup_overlapped ();
|
||||||
setup_overlapped ();
|
|
||||||
if (unique_id && close_on_exec ())
|
if (unique_id && close_on_exec ())
|
||||||
del_my_locks (after_exec);
|
del_my_locks (after_exec);
|
||||||
}
|
}
|
||||||
|
@ -1645,7 +1641,7 @@ fhandler_base::fpathconf (int v)
|
||||||
/* Overlapped I/O */
|
/* Overlapped I/O */
|
||||||
|
|
||||||
bool
|
bool
|
||||||
fhandler_base::setup_overlapped (bool doit)
|
fhandler_base_overlapped::setup_overlapped (bool doit)
|
||||||
{
|
{
|
||||||
OVERLAPPED *ov = get_overlapped_buffer ();
|
OVERLAPPED *ov = get_overlapped_buffer ();
|
||||||
memset (ov, 0, sizeof (*ov));
|
memset (ov, 0, sizeof (*ov));
|
||||||
|
@ -1664,7 +1660,7 @@ fhandler_base::setup_overlapped (bool doit)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
fhandler_base::destroy_overlapped ()
|
fhandler_base_overlapped::destroy_overlapped ()
|
||||||
{
|
{
|
||||||
OVERLAPPED *ov = get_overlapped ();
|
OVERLAPPED *ov = get_overlapped ();
|
||||||
if (ov && ov->hEvent)
|
if (ov && ov->hEvent)
|
||||||
|
@ -1674,8 +1670,22 @@ fhandler_base::destroy_overlapped ()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
fhandler_base_overlapped::has_ongoing_io ()
|
||||||
|
{
|
||||||
|
if (!io_pending)
|
||||||
|
return false;
|
||||||
|
if (WaitForSingleObject (get_overlapped ()->hEvent, 0) != WAIT_OBJECT_0)
|
||||||
|
{
|
||||||
|
set_errno (EAGAIN);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
io_pending = false;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
fhandler_base::wait_overlapped (bool inres, bool writing, DWORD *bytes, DWORD len)
|
fhandler_base_overlapped::wait_overlapped (bool inres, bool writing, DWORD *bytes, DWORD len)
|
||||||
{
|
{
|
||||||
if (!get_overlapped ())
|
if (!get_overlapped ())
|
||||||
return inres;
|
return inres;
|
||||||
|
@ -1687,6 +1697,7 @@ fhandler_base::wait_overlapped (bool inres, bool writing, DWORD *bytes, DWORD le
|
||||||
{
|
{
|
||||||
if (inres || err == ERROR_IO_PENDING)
|
if (inres || err == ERROR_IO_PENDING)
|
||||||
{
|
{
|
||||||
|
io_pending = err == ERROR_IO_PENDING;
|
||||||
if (writing && !inres)
|
if (writing && !inres)
|
||||||
*bytes = len; /* This really isn't true but it seems like
|
*bytes = len; /* This really isn't true but it seems like
|
||||||
this is a corner-case for linux's
|
this is a corner-case for linux's
|
||||||
|
@ -1758,32 +1769,38 @@ fhandler_base::wait_overlapped (bool inres, bool writing, DWORD *bytes, DWORD le
|
||||||
}
|
}
|
||||||
|
|
||||||
void __stdcall
|
void __stdcall
|
||||||
fhandler_base::read_overlapped (void *ptr, size_t& len)
|
fhandler_base_overlapped::read_overlapped (void *ptr, size_t& len)
|
||||||
{
|
{
|
||||||
DWORD nbytes;
|
DWORD nbytes;
|
||||||
while (1)
|
if (has_ongoing_io ())
|
||||||
{
|
nbytes = (DWORD) -1;
|
||||||
bool res = ReadFile (get_handle (), ptr, len, &nbytes,
|
else
|
||||||
get_overlapped ());
|
while (1)
|
||||||
int wres = wait_overlapped (res, false, &nbytes);
|
{
|
||||||
if (wres || !_my_tls.call_signal_handler ())
|
bool res = ReadFile (get_handle (), ptr, len, &nbytes,
|
||||||
break;
|
get_overlapped ());
|
||||||
}
|
int wres = wait_overlapped (res, false, &nbytes);
|
||||||
|
if (wres || !_my_tls.call_signal_handler ())
|
||||||
|
break;
|
||||||
|
}
|
||||||
len = (size_t) nbytes;
|
len = (size_t) nbytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t __stdcall
|
ssize_t __stdcall
|
||||||
fhandler_base::write_overlapped (const void *ptr, size_t len)
|
fhandler_base_overlapped::write_overlapped (const void *ptr, size_t len)
|
||||||
{
|
{
|
||||||
DWORD nbytes;
|
DWORD nbytes;
|
||||||
while (1)
|
if (has_ongoing_io ())
|
||||||
{
|
nbytes = (DWORD) -1;
|
||||||
bool res = WriteFile (get_output_handle (), ptr, len, &nbytes,
|
else
|
||||||
get_overlapped ());
|
while (1)
|
||||||
int wres = wait_overlapped (res, true, &nbytes, (size_t) len);
|
{
|
||||||
if (wres || !_my_tls.call_signal_handler ())
|
bool res = WriteFile (get_output_handle (), ptr, len, &nbytes,
|
||||||
break;
|
get_overlapped ());
|
||||||
}
|
int wres = wait_overlapped (res, true, &nbytes, (size_t) len);
|
||||||
|
if (wres || !_my_tls.call_signal_handler ())
|
||||||
|
break;
|
||||||
|
}
|
||||||
debug_printf ("returning %u", nbytes);
|
debug_printf ("returning %u", nbytes);
|
||||||
return nbytes;
|
return nbytes;
|
||||||
}
|
}
|
||||||
|
|
|
@ -150,9 +150,6 @@ class fhandler_base
|
||||||
void del_my_locks (del_lock_called_from);
|
void del_my_locks (del_lock_called_from);
|
||||||
|
|
||||||
HANDLE read_state;
|
HANDLE read_state;
|
||||||
int wait_overlapped (bool, bool, DWORD *, DWORD = 0) __attribute__ ((regparm (3)));
|
|
||||||
bool setup_overlapped (bool doit = true) __attribute__ ((regparm (2)));
|
|
||||||
void destroy_overlapped () __attribute__ ((regparm (1)));
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
class fhandler_base *archetype;
|
class fhandler_base *archetype;
|
||||||
|
@ -310,9 +307,7 @@ class fhandler_base
|
||||||
virtual int fcntl (int cmd, void *);
|
virtual int fcntl (int cmd, void *);
|
||||||
virtual char const *ttyname () { return get_name (); }
|
virtual char const *ttyname () { return get_name (); }
|
||||||
virtual void __stdcall read (void *ptr, size_t& len) __attribute__ ((regparm (3)));
|
virtual void __stdcall read (void *ptr, size_t& len) __attribute__ ((regparm (3)));
|
||||||
virtual void __stdcall read_overlapped (void *ptr, size_t& len) __attribute__ ((regparm (3)));
|
|
||||||
virtual ssize_t __stdcall write (const void *ptr, size_t len);
|
virtual ssize_t __stdcall write (const void *ptr, size_t len);
|
||||||
virtual ssize_t __stdcall write_overlapped (const void *ptr, size_t len);
|
|
||||||
virtual ssize_t __stdcall readv (const struct iovec *, int iovcnt, ssize_t tot = -1);
|
virtual ssize_t __stdcall readv (const struct iovec *, int iovcnt, ssize_t tot = -1);
|
||||||
virtual ssize_t __stdcall writev (const struct iovec *, int iovcnt, ssize_t tot = -1);
|
virtual ssize_t __stdcall writev (const struct iovec *, int iovcnt, ssize_t tot = -1);
|
||||||
virtual ssize_t __stdcall pread (void *, size_t, _off64_t) __attribute__ ((regparm (3)));
|
virtual ssize_t __stdcall pread (void *, size_t, _off64_t) __attribute__ ((regparm (3)));
|
||||||
|
@ -354,9 +349,6 @@ class fhandler_base
|
||||||
|
|
||||||
virtual void __stdcall raw_read (void *ptr, size_t& ulen);
|
virtual void __stdcall raw_read (void *ptr, size_t& ulen);
|
||||||
virtual ssize_t __stdcall raw_write (const void *ptr, size_t ulen);
|
virtual ssize_t __stdcall raw_write (const void *ptr, size_t ulen);
|
||||||
virtual OVERLAPPED *get_overlapped () {return NULL;}
|
|
||||||
virtual OVERLAPPED *get_overlapped_buffer () {return NULL;}
|
|
||||||
virtual void set_overlapped (OVERLAPPED *) {}
|
|
||||||
|
|
||||||
/* Virtual accessor functions to hide the fact
|
/* Virtual accessor functions to hide the fact
|
||||||
that some fd's have two handles. */
|
that some fd's have two handles. */
|
||||||
|
@ -394,6 +386,8 @@ class fhandler_base
|
||||||
bool issymlink () {return pc.issymlink ();}
|
bool issymlink () {return pc.issymlink ();}
|
||||||
bool device_access_denied (int) __attribute__ ((regparm (2)));
|
bool device_access_denied (int) __attribute__ ((regparm (2)));
|
||||||
int fhaccess (int flags, bool) __attribute__ ((regparm (3)));
|
int fhaccess (int flags, bool) __attribute__ ((regparm (3)));
|
||||||
|
virtual void destroy_overlapped () __attribute__ ((regparm (1))) {}
|
||||||
|
virtual bool setup_overlapped () {return false;}
|
||||||
};
|
};
|
||||||
|
|
||||||
class fhandler_mailslot : public fhandler_base
|
class fhandler_mailslot : public fhandler_base
|
||||||
|
@ -558,18 +552,32 @@ class fhandler_socket: public fhandler_base
|
||||||
bool is_slow () {return true;}
|
bool is_slow () {return true;}
|
||||||
};
|
};
|
||||||
|
|
||||||
class fhandler_pipe: public fhandler_base
|
class fhandler_base_overlapped: public fhandler_base
|
||||||
{
|
{
|
||||||
private:
|
protected:
|
||||||
pid_t popen_pid;
|
bool io_pending;
|
||||||
OVERLAPPED io_status;
|
OVERLAPPED io_status;
|
||||||
OVERLAPPED *overlapped;
|
OVERLAPPED *overlapped;
|
||||||
public:
|
public:
|
||||||
fhandler_pipe ();
|
int wait_overlapped (bool, bool, DWORD *, DWORD = 0) __attribute__ ((regparm (3)));
|
||||||
|
bool setup_overlapped (bool doit = true) __attribute__ ((regparm (2)));
|
||||||
|
void destroy_overlapped () __attribute__ ((regparm (1)));
|
||||||
|
void __stdcall read_overlapped (void *ptr, size_t& len) __attribute__ ((regparm (3)));
|
||||||
|
ssize_t __stdcall write_overlapped (const void *ptr, size_t len);
|
||||||
OVERLAPPED *get_overlapped () {return overlapped;}
|
OVERLAPPED *get_overlapped () {return overlapped;}
|
||||||
OVERLAPPED *get_overlapped_buffer () {return &io_status;}
|
OVERLAPPED *get_overlapped_buffer () {return &io_status;}
|
||||||
void set_overlapped (OVERLAPPED *ov) {overlapped = ov;}
|
void set_overlapped (OVERLAPPED *ov) {overlapped = ov;}
|
||||||
|
fhandler_base_overlapped (): io_pending (false), overlapped (NULL) {}
|
||||||
|
bool has_ongoing_io ();
|
||||||
|
};
|
||||||
|
|
||||||
|
class fhandler_pipe: public fhandler_base_overlapped
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
pid_t popen_pid;
|
||||||
|
public:
|
||||||
|
fhandler_pipe ();
|
||||||
|
|
||||||
|
|
||||||
bool ispipe() const { return true; }
|
bool ispipe() const { return true; }
|
||||||
|
|
||||||
|
@ -595,7 +603,7 @@ public:
|
||||||
friend class fhandler_fifo;
|
friend class fhandler_fifo;
|
||||||
};
|
};
|
||||||
|
|
||||||
class fhandler_fifo: public fhandler_base
|
class fhandler_fifo: public fhandler_base_overlapped
|
||||||
{
|
{
|
||||||
enum fifo_state
|
enum fifo_state
|
||||||
{
|
{
|
||||||
|
@ -611,7 +619,6 @@ class fhandler_fifo: public fhandler_base
|
||||||
fifo_state wait_state;
|
fifo_state wait_state;
|
||||||
HANDLE dummy_client;
|
HANDLE dummy_client;
|
||||||
HANDLE open_nonserver (const char *, unsigned, LPSECURITY_ATTRIBUTES);
|
HANDLE open_nonserver (const char *, unsigned, LPSECURITY_ATTRIBUTES);
|
||||||
OVERLAPPED io_status;
|
|
||||||
bool wait (bool) __attribute__ ((regparm (1)));
|
bool wait (bool) __attribute__ ((regparm (1)));
|
||||||
char *fifo_name (char *) __attribute__ ((regparm (2)));
|
char *fifo_name (char *) __attribute__ ((regparm (2)));
|
||||||
public:
|
public:
|
||||||
|
@ -624,8 +631,6 @@ public:
|
||||||
bool isfifo () const { return true; }
|
bool isfifo () const { return true; }
|
||||||
void set_close_on_exec (bool val);
|
void set_close_on_exec (bool val);
|
||||||
int __stdcall fstatvfs (struct statvfs *buf) __attribute__ ((regparm (2)));
|
int __stdcall fstatvfs (struct statvfs *buf) __attribute__ ((regparm (2)));
|
||||||
OVERLAPPED *get_overlapped () {return &io_status;}
|
|
||||||
OVERLAPPED *get_overlapped_buffer () {return &io_status;}
|
|
||||||
select_record *select_read (select_stuff *);
|
select_record *select_read (select_stuff *);
|
||||||
select_record *select_write (select_stuff *);
|
select_record *select_write (select_stuff *);
|
||||||
select_record *select_except (select_stuff *);
|
select_record *select_except (select_stuff *);
|
||||||
|
|
|
@ -24,7 +24,7 @@ details. */
|
||||||
#include "shared_info.h"
|
#include "shared_info.h"
|
||||||
|
|
||||||
fhandler_pipe::fhandler_pipe ()
|
fhandler_pipe::fhandler_pipe ()
|
||||||
: fhandler_base (), popen_pid (0), overlapped (NULL)
|
: fhandler_base_overlapped (), popen_pid (0)
|
||||||
{
|
{
|
||||||
need_fork_fixup (true);
|
need_fork_fixup (true);
|
||||||
uninterruptible_io (true);
|
uninterruptible_io (true);
|
||||||
|
@ -378,6 +378,11 @@ pipe (int filedes[2])
|
||||||
{
|
{
|
||||||
cygheap_fdnew fdin;
|
cygheap_fdnew fdin;
|
||||||
cygheap_fdnew fdout (fdin, false);
|
cygheap_fdnew fdout (fdin, false);
|
||||||
|
char buf[sizeof ("/dev/fd/pipe:[2147483647]")];
|
||||||
|
__small_sprintf (buf, "/dev/fd/pipe:[%d]", (int) fdin);
|
||||||
|
fhs[0]->pc.set_normalized_path (buf);
|
||||||
|
__small_sprintf (buf, "pipe:[%d]", (int) fdout);
|
||||||
|
fhs[1]->pc.set_normalized_path (buf);
|
||||||
fdin = fhs[0];
|
fdin = fhs[0];
|
||||||
fdout = fhs[1];
|
fdout = fhs[1];
|
||||||
filedes[0] = fdin;
|
filedes[0] = fdin;
|
||||||
|
|
Loading…
Reference in New Issue