- The slowing down issue of X11 forwarding using ssh -Y, reported
in https://www.cygwin.com/ml/cygwin/2019-12/msg00295.html,
is due to the change of select() code for pty in the commit
915fcd0ae8. cygthread::detach()
takes at most about 10msec because Sleep() is used in the thread.
For this issue, this patch uses cygwait() instead of Sleep() and
introduces an event to abort the wait. For not only pty, but pipe
and fifo also have the same problem potentially, so this patch
applies same strategy to them as well.
- Previously, input and output pipes were switched together between
the traditional pty and the pseudo console. However, for example,
if stdin is redirected to another device, it is better to leave
input pipe traditional pty side even for non-cygwin program. This
patch realizes such behaviour.
- When the I/O pipe is switched to the pseudo console side, the
behaviour of Ctrl-C was unstable. This rarely happens, however,
for example, shell sometimes crashes by Ctrl-C in that situation.
Furthermore, Ctrl-C was ignored if output of non-cygwin program
is redirected to pipe. This patch fixes these issues.
- select() did not work correctly when both read and except are
polled simultaneously for the same fd and the r/w pipe is switched
to pseudo console side. This patch fixes this isseu.
- Support pseudo console in PTY. Pseudo console is a new feature
in Windows 10 1809, which provides console APIs on virtual
terminal. With this patch, native console applications can work
in PTYs such as mintty, ssh, gnu screen or tmux.
Rather than waiting for signalfd_select_wait in a thread, which is racy,
create a global event "my_pendingsigs_evt" which is set and reset by
wait_sig depending only on the fact if blocked signals are pending or not.
This in turn allows to WFMO on this event in select as soon as signalfds
are present in the read descriptor set. Select's peek and verify
will then check if one of the present signalfds is affected.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
The word "client" suggests something that holds a handle to the client
side of the pipe (in Windows terminology). But our
fifo_client_handlers hold a handle the server side of the pipe, and
they *connect* to clients.
- Add 24 bit color support using xterm compatibility mode in
Windows 10 1703 or later.
- Add fake 24 bit color support for legacy console, which uses
the nearest color from 16 system colors.
Add static functions peek_fifo, thread_fifo, start_thread_fifo, and
fifo_cleanup to select.cc. These are based on the corresponding pipe
functions, the main difference being that peek_fifo loops through the
connected clients to see if any of them have data available for
reading.
Add the fhandler_fifo methods select_read, select_write, and
select_except.
Add accessor methods get_nclients, get_handle, and is_connected that
are needed by peek_fifo.
First cut of a timerfd implementation.
Still TODO:
- fork/exec semantics
- timerfd_settime TFD_TIMER_CANCEL_ON_SET flag
- ioctl(TFD_IOC_SET_TICKS)
- bug fixes
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Allow the signal thread to recognize we're called in consequence of
select on a signalfd. If the signal is part of the wait mask, don't
call any signal handler and don't remove the signal from the queue,
so a subsequent read (or sigwaitinfo/sigtimedwait) still gets the
signal. Instead, just signal the event object at
_cygtls::signalfd_select_wait for the thread running select.
The addition of signalfd_select_wait to _cygtls unearthed the alignment
problem of the context member again. To make sure this doesn't get lost,
improve the related comment in the header file so that this (hopefully)
doesn't get lost (again).
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
First cut of a signalfd implementation.
Still TODO: Non-polling select.
This should mostly work as on Linux except for missing support
for some members of struct signalfd_siginfo, namely ssi_fd,
ssi_band (both SIGIO/SIGPOLL, not fully implemented) and ssi_trapno
(HW exception, required HW support).
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
There's a long-standing bug in select. If we have poll-only
descriptors in the fd set, select overwrites the incoming
fd sets with the polling result. If none of the fds is ready,
select has to loop again. But now the fd sets are set to all
zero and select hangs.
Fix this by utilizing the local fd sets r, w, e as storage for
the incoming fd sets and use them to initialize select_stuff.
If we have to loop, overwritung the incoming fd sets doesn't matter.
While at it, rename r, w, e to readfds_in, writefds_in, exceptfds_in.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
- Drop hires_[nm]s clocks, rename hires.h to clock.h.
- Implement clk_t class as an extensible clock class in new file clock.cc.
- Introduce get_clock(clock_id) returning a pointer to the clk_t instance
for clock_id. Provide the following methods along the lines of the former
hires classes:
void clk_t::nsecs (struct timespec *);
ULONGLONG clk_t::nsecs ();
LONGLONG clk_t::usecs ();
LONGLONG clk_t::msecs ();
void clk_t::resolution (struct timespec *);
- Add CLOCK_REALTIME_COARSE, CLOCK_MONOTONIC_RAW, CLOCK_MONOTONIC_COARSE
and CLOCK_BOOTTIME clocks.
- Allow clock_nanosleep, pthread_condattr_setclock and timer_create to use
all new clocks (both clocks should be usable with a small tweak, though).
- Bump DLL major version to 2.12.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
* Make distinct from AF_LOCAL for testing purposes. This will have
to be reverted as soon as fhandler_socket_unix goes life.
* Move saw_reuseaddr flag back to fhandler_socket status
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Insert another class fhandler_socket_wsock between fhandler_socket
and fhandler_socket_inet/fhandler_socket_local.
Also, add a new method fhandler::is_wsock_socket to allow asking
for sockets in general (is_socket) vs. Winsock-based sockets
(is_wsock_socket).
This allows to develop a new handler_socket_unix class as derived
class from fhandler_socket without any trace of wsock code left
in fhandler_socket.
While this is basically a temporary measure at this time, it may
prove useful for later interoperability with the upcoming Windows 10
AF_UNIX implementation at one point.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
* Redefine NSPERSEC to NS100PERSEC
* Define NSPERSEC as nanosecs per second
* Define USPERSEC as microsecs per second
* Use above constants throughout where appropriate
* Rename to_us to timespec_to_us and inline
* Rename it_bad to timespec_bad and inline
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
* Don't use a bool var to store three states (-1, 0, 1).
* Correctly check for NT_SUCCESS of a function returning NTSTATUS.
* Straighten out code for better readability.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
For historical reasons peek_console was calling the functions
PeekConsoleInputA and ReadConsoleInputA. However, these functions are
not working correctly under at least codepage 65001 (UTF-8) on systems
prior to Windows 10.
Use PeekConsoleInputW and ReadConsoleInputW instead, which work
correctly under all systems and all codepages.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Create two new inline functions is_alt_numpad_key(PINPUT_RECORD) and
is_alt_numpad_event(PINPUT_RECORD) which contain the actual checks.
Call these functions from fhandler_console::read and peek_console for
better readability.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
{p}select/{p}poll completely ignored Alt+Numpad key sequences in console
input which results in newer readline using pselect to fail handling such
sequences correctly. See https://cygwin.com/ml/cygwin/2017-01/msg00135.html
During debugging and testing it turned out that while reading console
input, single key presses during an Alt+Numpad sequences where not
ignored, so ultimately a sequence like
Alt-down Numpad-1 Numpad-2 Numpad-3
whihc is supposed to result in a single character in the input stream
will actually result in 4 chars in the input stream, three control
sequences and the actual character.
Both problems should be fixed by this patch.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
SIGTTIN should be raised when read() is made on a tty in a backgrounded
process, but not when it's tested with poll()/select().
I guess poll()/select() does need to call bg_check(), in order to detect the
error conditions that notices (that is, if bg_check() returns bg_eof or
bg_error, then fd is ready as an error condition exists) so add an optional
parameter to fhandler_base::bg_select() to indicate that signals aren't
desired.
See https://cygwin.com/ml/cygwin-developers/2016-07/msg00004.html
Bump GPLv2+ to GPLv3+ for some files, clarify BSD 2-clause.
Everything else stays under GPLv3+.
New Linking Exception exempts resulting executables from LGPLv3 section 4.
Add CONTRIBUTORS file to keep track of licensing.
Remove 'Copyright Red Hat Inc' comments.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Commit a23e6a35d8 introduced a timer
object to the WFMO handling in select_stuff::wait to allow sub-tickcount
timeout values in select.
Problems with this patch: The timer was created and destroyed on every
invocation of select_stuff::wait, thus potentially multiple times per
select. Also, since the timer was prepended to the WFMO hande list,
the timer handle could shadow actual events on other objects, given that
WFMO checks the objects in the order they have been specified in the
HANDLE array. The timer was also created/destroyed and added to the
HANDLE array even if it was not required.
This patch drops the local timer HANDLE and recycles the cw_timer HANDLE
in the cygtls area instead. Thus we typically don't need to create the
timer in select at all, and we never have to destroy it.
The timer HANDLE is now also appended as last object to the HANDLE array,
and it's only added if actually needed.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
The check for current timestamp > start timestamp has an unwelcome
side effect: The loop is not left as long as the current timestamp
hasn't been incremented. This leads to busy loops of about one tick
(10 to 16 ms per MSDN).
This fixes https://cygwin.com/ml/cygwin/2016-05/msg00327.html
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
* select.h: Eliminate redundant select_stuff::select_loop state.
* select.cc (select): Eliminate redundant
select_stuff::select_loop state. Eliminate redundant code for
zero timeout. Do not return early on early timer return.
(select_stuff::wait): Eliminate redundant
select_stuff::select_loop state.
* select.h: Change prototype for select_stuff::wait() for larger
microsecond timeouts.
* select.cc (pselect): Convert from old cygwin_select().
Implement microsecond timeouts.
(cygwin_select): Rewrite as a wrapper on pselect().
(select): Implement microsecond timeouts.
(select_stuff::wait): Implement microsecond timeouts with a timer
object.
* cygwait.h (cygwait_us) Remove; this reverts previous changes.
* select.h: Eliminate redundant select_stuff::select_loop state.
* select.cc (select): Eliminate redundant
select_stuff::select_loop state. Eliminate redundant code for
zero timeout. Do not return early on early timer return.
(select_stuff::wait): Eliminate redundant
select_stuff::select_loop state.
* cygwait.h: Add cygwait_us() methods.
* select.h: Change prototype for select_stuff::wait() for larger
microsecond timeouts.
* select.cc (pselect): Convert from old cygwin_select().
Implement microsecond timeouts.
(cygwin_select): Rewrite as a wrapper on pselect().
(select): Implement microsecond timeouts.
(select_stuff::wait): Implement microsecond timeouts with a timer
object.
* fhandler.h (fhandler_console): Move get_nonascii_key() from
select.c into this class.
* select.cc (peek_console): Move get_nonascii_key() into
fhandler_console class.
Rename "res" to "wait_state" and change its type to
select_stuff::wait_states. Use select_stuff::wait_states
values instead of ints throughout. Rearrange a few comments.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>