|
@@ -33,15 +33,42 @@ using System.Threading;
|
|
namespace Mono.Terminal {
|
|
namespace Mono.Terminal {
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
- /// Simple main loop implementation that can be used to monitor
|
|
|
|
- /// file descriptor, run timers and idle handlers.
|
|
|
|
|
|
+ /// Public interface to create your own platform specific main loop driver.
|
|
|
|
+ /// </summary>
|
|
|
|
+ public interface IMainLoopDriver {
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// Initializes the main loop driver, gets the calling main loop for the initialization.
|
|
|
|
+ /// </summary>
|
|
|
|
+ /// <param name="mainLoop">Main loop.</param>
|
|
|
|
+ void Setup (MainLoop mainLoop);
|
|
|
|
+
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// Wakes up the mainloop that might be waiting on input, must be thread safe.
|
|
|
|
+ /// </summary>
|
|
|
|
+ void Wakeup ();
|
|
|
|
+
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// Must report whether there are any events pending, or even block waiting for events.
|
|
|
|
+ /// </summary>
|
|
|
|
+ /// <returns><c>true</c>, if there were pending events, <c>false</c> otherwise.</returns>
|
|
|
|
+ /// <param name="wait">If set to <c>true</c> wait until an event is available, otherwise return immediately.</param>
|
|
|
|
+ bool EventsPending (bool wait);
|
|
|
|
+ void MainIteration ();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// Unix main loop, suitable for using on Posix systems
|
|
/// </summary>
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// <remarks>
|
|
- /// Monitoring of file descriptors is only available on Unix, there
|
|
|
|
- /// does not seem to be a way of supporting this on Windows.
|
|
|
|
|
|
+ /// In addition to the general functions of the mainloop, the Unix version
|
|
|
|
+ /// can watch file descriptors using the AddWatch methods.
|
|
/// </remarks>
|
|
/// </remarks>
|
|
- public class MainLoop {
|
|
|
|
- bool useUnix = true;
|
|
|
|
|
|
+ public class UnixMainLoop : IMainLoopDriver {
|
|
|
|
+ [StructLayout (LayoutKind.Sequential)]
|
|
|
|
+ struct Pollfd {
|
|
|
|
+ public int fd;
|
|
|
|
+ public short events, revents;
|
|
|
|
+ }
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
/// Condition on which to wake up from file descriptor activity. These match the Linux/BSD poll definitions.
|
|
/// Condition on which to wake up from file descriptor activity. These match the Linux/BSD poll definitions.
|
|
@@ -77,29 +104,16 @@ namespace Mono.Terminal {
|
|
class Watch {
|
|
class Watch {
|
|
public int File;
|
|
public int File;
|
|
public Condition Condition;
|
|
public Condition Condition;
|
|
- public Func<MainLoop,bool> Callback;
|
|
|
|
|
|
+ public Func<MainLoop, bool> Callback;
|
|
}
|
|
}
|
|
|
|
|
|
- class Timeout {
|
|
|
|
- public TimeSpan Span;
|
|
|
|
- public Func<MainLoop,bool> Callback;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- Dictionary <int, Watch> descriptorWatchers = new Dictionary<int,Watch>();
|
|
|
|
- SortedList <long, Timeout> timeouts = new SortedList<long,Timeout> ();
|
|
|
|
- List<Func<bool>> idleHandlers = new List<Func<bool>> ();
|
|
|
|
-
|
|
|
|
- [StructLayout(LayoutKind.Sequential)]
|
|
|
|
- struct Pollfd {
|
|
|
|
- public int fd;
|
|
|
|
- public short events, revents;
|
|
|
|
- }
|
|
|
|
|
|
+ Dictionary<int, Watch> descriptorWatchers = new Dictionary<int, Watch> ();
|
|
|
|
|
|
[DllImport ("libc")]
|
|
[DllImport ("libc")]
|
|
- extern static int poll ([In,Out]Pollfd[] ufds, uint nfds, int timeout);
|
|
|
|
|
|
+ extern static int poll ([In, Out]Pollfd [] ufds, uint nfds, int timeout);
|
|
|
|
|
|
[DllImport ("libc")]
|
|
[DllImport ("libc")]
|
|
- extern static int pipe ([In,Out]int [] pipes);
|
|
|
|
|
|
+ extern static int pipe ([In, Out]int [] pipes);
|
|
|
|
|
|
[DllImport ("libc")]
|
|
[DllImport ("libc")]
|
|
extern static int read (int fd, IntPtr buf, IntPtr n);
|
|
extern static int read (int fd, IntPtr buf, IntPtr n);
|
|
@@ -111,34 +125,213 @@ namespace Mono.Terminal {
|
|
bool poll_dirty = true;
|
|
bool poll_dirty = true;
|
|
int [] wakeupPipes = new int [2];
|
|
int [] wakeupPipes = new int [2];
|
|
static IntPtr ignore = Marshal.AllocHGlobal (1);
|
|
static IntPtr ignore = Marshal.AllocHGlobal (1);
|
|
|
|
+ MainLoop mainLoop;
|
|
|
|
+
|
|
|
|
+ void IMainLoopDriver.Wakeup ()
|
|
|
|
+ {
|
|
|
|
+ write (wakeupPipes [1], ignore, (IntPtr) 1);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ void IMainLoopDriver.Setup (MainLoop mainLoop) {
|
|
|
|
+ this.mainLoop = mainLoop;
|
|
|
|
+ pipe (wakeupPipes);
|
|
|
|
+ AddWatch (wakeupPipes [0], Condition.PollIn, ml => {
|
|
|
|
+ read (wakeupPipes [0], ignore, (IntPtr)1);
|
|
|
|
+ return true;
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
- /// Default constructor
|
|
|
|
|
|
+ /// Removes an active watch from the mainloop.
|
|
/// </summary>
|
|
/// </summary>
|
|
- public MainLoop () : this (useUnix: true)
|
|
|
|
|
|
+ /// <remarks>
|
|
|
|
+ /// The token parameter is the value returned from AddWatch
|
|
|
|
+ /// </remarks>
|
|
|
|
+ public void RemoveWatch (object token)
|
|
|
|
+ {
|
|
|
|
+ var watch = token as Watch;
|
|
|
|
+ if (watch == null)
|
|
|
|
+ return;
|
|
|
|
+ descriptorWatchers.Remove (watch.File);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// Watches a file descriptor for activity.
|
|
|
|
+ /// </summary>
|
|
|
|
+ /// <remarks>
|
|
|
|
+ /// When the condition is met, the provided callback
|
|
|
|
+ /// is invoked. If the callback returns false, the
|
|
|
|
+ /// watch is automatically removed.
|
|
|
|
+ ///
|
|
|
|
+ /// The return value is a token that represents this watch, you can
|
|
|
|
+ /// use this token to remove the watch by calling RemoveWatch.
|
|
|
|
+ /// </remarks>
|
|
|
|
+ public object AddWatch (int fileDescriptor, Condition condition, Func<MainLoop, bool> callback)
|
|
|
|
+ {
|
|
|
|
+ if (callback == null)
|
|
|
|
+ throw new ArgumentNullException (nameof(callback));
|
|
|
|
+
|
|
|
|
+ var watch = new Watch () { Condition = condition, Callback = callback, File = fileDescriptor };
|
|
|
|
+ descriptorWatchers [fileDescriptor] = watch;
|
|
|
|
+ poll_dirty = true;
|
|
|
|
+ return watch;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ void UpdatePollMap ()
|
|
{
|
|
{
|
|
|
|
+ if (!poll_dirty)
|
|
|
|
+ return;
|
|
|
|
+ poll_dirty = false;
|
|
|
|
+
|
|
|
|
+ pollmap = new Pollfd [descriptorWatchers.Count];
|
|
|
|
+ int i = 0;
|
|
|
|
+ foreach (var fd in descriptorWatchers.Keys) {
|
|
|
|
+ pollmap [i].fd = fd;
|
|
|
|
+ pollmap [i].events = (short)descriptorWatchers [fd].Condition;
|
|
|
|
+ i++;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
- public MainLoop (bool useUnix, bool useNet=false)
|
|
|
|
|
|
+ bool IMainLoopDriver.EventsPending (bool wait)
|
|
{
|
|
{
|
|
- this.useUnix = useUnix;
|
|
|
|
- if (useUnix) {
|
|
|
|
- pipe (wakeupPipes);
|
|
|
|
- AddWatch (wakeupPipes [0], Condition.PollIn, ml => {
|
|
|
|
- read (wakeupPipes [0], ignore, (IntPtr)1);
|
|
|
|
|
|
+ long now = DateTime.UtcNow.Ticks;
|
|
|
|
+
|
|
|
|
+ int pollTimeout, n;
|
|
|
|
+ if (mainLoop.timeouts.Count > 0) {
|
|
|
|
+ pollTimeout = (int)((mainLoop.timeouts.Keys [0] - now) / TimeSpan.TicksPerMillisecond);
|
|
|
|
+ if (pollTimeout < 0)
|
|
return true;
|
|
return true;
|
|
- });
|
|
|
|
- } else if (useNet) {
|
|
|
|
- Thread readThread = new Thread (WindowsKeyReader);
|
|
|
|
- readThread.Start ();
|
|
|
|
|
|
+
|
|
|
|
+ } else
|
|
|
|
+ pollTimeout = -1;
|
|
|
|
+
|
|
|
|
+ if (!wait)
|
|
|
|
+ pollTimeout = 0;
|
|
|
|
+
|
|
|
|
+ UpdatePollMap ();
|
|
|
|
+
|
|
|
|
+ n = poll (pollmap, (uint)pollmap.Length, pollTimeout);
|
|
|
|
+ int ic;
|
|
|
|
+ lock (mainLoop.idleHandlers)
|
|
|
|
+ ic = mainLoop.idleHandlers.Count;
|
|
|
|
+ return n > 0 || mainLoop.timeouts.Count > 0 && ((mainLoop.timeouts.Keys [0] - DateTime.UtcNow.Ticks) < 0) || ic > 0;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ void IMainLoopDriver.MainIteration ()
|
|
|
|
+ {
|
|
|
|
+ if (pollmap != null) {
|
|
|
|
+ foreach (var p in pollmap) {
|
|
|
|
+ Watch watch;
|
|
|
|
+
|
|
|
|
+ if (p.revents == 0)
|
|
|
|
+ continue;
|
|
|
|
+
|
|
|
|
+ if (!descriptorWatchers.TryGetValue (p.fd, out watch))
|
|
|
|
+ continue;
|
|
|
|
+ if (!watch.Callback (this.mainLoop))
|
|
|
|
+ descriptorWatchers.Remove (p.fd);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// Mainloop intended to be used with the .NET System.Console API, and can
|
|
|
|
+ /// be used on Windows and Unix, it is cross platform but lacks things like
|
|
|
|
+ /// file descriptor monitoring.
|
|
|
|
+ /// </summary>
|
|
|
|
+ class NetMainLoop : IMainLoopDriver {
|
|
|
|
+ AutoResetEvent keyReady = new AutoResetEvent (false);
|
|
|
|
+ AutoResetEvent waitForProbe = new AutoResetEvent (false);
|
|
|
|
+ ConsoleKeyInfo? windowsKeyResult = null;
|
|
|
|
+ public Action<ConsoleKeyInfo> WindowsKeyPressed;
|
|
|
|
+ MainLoop mainLoop;
|
|
|
|
+
|
|
|
|
+ public NetMainLoop ()
|
|
|
|
+ {
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ void WindowsKeyReader ()
|
|
|
|
+ {
|
|
|
|
+ while (true) {
|
|
|
|
+ waitForProbe.WaitOne ();
|
|
|
|
+ windowsKeyResult = Console.ReadKey (true);
|
|
|
|
+ keyReady.Set ();
|
|
}
|
|
}
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ void IMainLoopDriver.Setup (MainLoop mainLoop)
|
|
|
|
+ {
|
|
|
|
+ this.mainLoop = mainLoop;
|
|
|
|
+ Thread readThread = new Thread (WindowsKeyReader);
|
|
|
|
+ readThread.Start ();
|
|
}
|
|
}
|
|
|
|
|
|
- void Wakeup ()
|
|
|
|
|
|
+ void IMainLoopDriver.Wakeup ()
|
|
{
|
|
{
|
|
- write (wakeupPipes [1], ignore, (IntPtr) 1);
|
|
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+ bool IMainLoopDriver.EventsPending (bool wait)
|
|
|
|
+ {
|
|
|
|
+ long now = DateTime.UtcNow.Ticks;
|
|
|
|
+
|
|
|
|
+ int waitTimeout;
|
|
|
|
+ if (mainLoop.timeouts.Count > 0) {
|
|
|
|
+ waitTimeout = (int)((mainLoop.timeouts.Keys [0] - now) / TimeSpan.TicksPerMillisecond);
|
|
|
|
+ if (waitTimeout < 0)
|
|
|
|
+ return true;
|
|
|
|
+ } else
|
|
|
|
+ waitTimeout = -1;
|
|
|
|
+
|
|
|
|
+ if (!wait)
|
|
|
|
+ waitTimeout = 0;
|
|
|
|
+
|
|
|
|
+ windowsKeyResult = null;
|
|
|
|
+ waitForProbe.Set ();
|
|
|
|
+ keyReady.WaitOne (waitTimeout);
|
|
|
|
+ return windowsKeyResult.HasValue;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ void IMainLoopDriver.MainIteration ()
|
|
|
|
+ {
|
|
|
|
+ if (windowsKeyResult.HasValue) {
|
|
|
|
+ if (WindowsKeyPressed!= null)
|
|
|
|
+ WindowsKeyPressed (windowsKeyResult.Value);
|
|
|
|
+ windowsKeyResult = null;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// Simple main loop implementation that can be used to monitor
|
|
|
|
+ /// file descriptor, run timers and idle handlers.
|
|
|
|
+ /// </summary>
|
|
|
|
+ /// <remarks>
|
|
|
|
+ /// Monitoring of file descriptors is only available on Unix, there
|
|
|
|
+ /// does not seem to be a way of supporting this on Windows.
|
|
|
|
+ /// </remarks>
|
|
|
|
+ public class MainLoop {
|
|
|
|
+ internal class Timeout {
|
|
|
|
+ public TimeSpan Span;
|
|
|
|
+ public Func<MainLoop,bool> Callback;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ internal SortedList <long, Timeout> timeouts = new SortedList<long,Timeout> ();
|
|
|
|
+ internal List<Func<bool>> idleHandlers = new List<Func<bool>> ();
|
|
|
|
+
|
|
|
|
+ IMainLoopDriver driver;
|
|
|
|
+ public IMainLoopDriver Driver => driver;
|
|
|
|
+
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// Creates a new Mainloop, to run it you must provide a driver, and choose
|
|
|
|
+ /// one of the implementations UnixMainLoop, NetMainLoop or WindowsMainLoop.
|
|
|
|
+ /// </summary>
|
|
|
|
+ public MainLoop (IMainLoopDriver driver)
|
|
|
|
+ {
|
|
|
|
+ this.driver = driver;
|
|
|
|
+ driver.Setup (this);
|
|
|
|
+ }
|
|
|
|
+
|
|
/// <summary>
|
|
/// <summary>
|
|
/// Runs @action on the thread that is processing events
|
|
/// Runs @action on the thread that is processing events
|
|
/// </summary>
|
|
/// </summary>
|
|
@@ -148,7 +341,7 @@ namespace Mono.Terminal {
|
|
action ();
|
|
action ();
|
|
return false;
|
|
return false;
|
|
});
|
|
});
|
|
- Wakeup ();
|
|
|
|
|
|
+ driver.Wakeup ();
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
@@ -169,50 +362,7 @@ namespace Mono.Terminal {
|
|
lock (idleHandler)
|
|
lock (idleHandler)
|
|
idleHandlers.Remove (idleHandler);
|
|
idleHandlers.Remove (idleHandler);
|
|
}
|
|
}
|
|
-
|
|
|
|
- /// <summary>
|
|
|
|
- /// Watches a file descriptor for activity.
|
|
|
|
- /// </summary>
|
|
|
|
- /// <remarks>
|
|
|
|
- /// When the condition is met, the provided callback
|
|
|
|
- /// is invoked. If the callback returns false, the
|
|
|
|
- /// watch is automatically removed.
|
|
|
|
- ///
|
|
|
|
- /// The return value is a token that represents this watch, you can
|
|
|
|
- /// use this token to remove the watch by calling RemoveWatch.
|
|
|
|
- /// </remarks>
|
|
|
|
- public object AddWatch (int fileDescriptor, Condition condition, Func<MainLoop,bool> callback)
|
|
|
|
- {
|
|
|
|
- if (callback == null)
|
|
|
|
- throw new ArgumentNullException ("callback");
|
|
|
|
- if (!useUnix)
|
|
|
|
- throw new Exception ("AddWatch is only supported for Unix");
|
|
|
|
-
|
|
|
|
- var watch = new Watch () { Condition = condition, Callback = callback, File = fileDescriptor };
|
|
|
|
- descriptorWatchers [fileDescriptor] = watch;
|
|
|
|
- poll_dirty = true;
|
|
|
|
- return watch;
|
|
|
|
- }
|
|
|
|
|
|
|
|
- /// <summary>
|
|
|
|
- /// This event is raised when a key is pressed when using the Windows driver.
|
|
|
|
- /// </summary>
|
|
|
|
- public Action<ConsoleKeyInfo> WindowsKeyPressed;
|
|
|
|
-
|
|
|
|
- /// <summary>
|
|
|
|
- /// Removes an active watch from the mainloop.
|
|
|
|
- /// </summary>
|
|
|
|
- /// <remarks>
|
|
|
|
- /// The token parameter is the value returned from AddWatch
|
|
|
|
- /// </remarks>
|
|
|
|
- public void RemoveWatch (object token)
|
|
|
|
- {
|
|
|
|
- var watch = token as Watch;
|
|
|
|
- if (watch == null)
|
|
|
|
- return;
|
|
|
|
- descriptorWatchers.Remove (watch.File);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
void AddTimeout (TimeSpan time, Timeout timeout)
|
|
void AddTimeout (TimeSpan time, Timeout timeout)
|
|
{
|
|
{
|
|
timeouts.Add ((DateTime.UtcNow + time).Ticks, timeout);
|
|
timeouts.Add ((DateTime.UtcNow + time).Ticks, timeout);
|
|
@@ -232,7 +382,7 @@ namespace Mono.Terminal {
|
|
public object AddTimeout (TimeSpan time, Func<MainLoop,bool> callback)
|
|
public object AddTimeout (TimeSpan time, Func<MainLoop,bool> callback)
|
|
{
|
|
{
|
|
if (callback == null)
|
|
if (callback == null)
|
|
- throw new ArgumentNullException ("callback");
|
|
|
|
|
|
+ throw new ArgumentNullException (nameof (callback));
|
|
var timeout = new Timeout () {
|
|
var timeout = new Timeout () {
|
|
Span = time,
|
|
Span = time,
|
|
Callback = callback
|
|
Callback = callback
|
|
@@ -255,21 +405,6 @@ namespace Mono.Terminal {
|
|
timeouts.RemoveAt (idx);
|
|
timeouts.RemoveAt (idx);
|
|
}
|
|
}
|
|
|
|
|
|
- void UpdatePollMap ()
|
|
|
|
- {
|
|
|
|
- if (!poll_dirty)
|
|
|
|
- return;
|
|
|
|
- poll_dirty = false;
|
|
|
|
-
|
|
|
|
- pollmap = new Pollfd [descriptorWatchers.Count];
|
|
|
|
- int i = 0;
|
|
|
|
- foreach (var fd in descriptorWatchers.Keys){
|
|
|
|
- pollmap [i].fd = fd;
|
|
|
|
- pollmap [i].events = (short) descriptorWatchers [fd].Condition;
|
|
|
|
- i++;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
void RunTimers ()
|
|
void RunTimers ()
|
|
{
|
|
{
|
|
long now = DateTime.UtcNow.Ticks;
|
|
long now = DateTime.UtcNow.Ticks;
|
|
@@ -308,19 +443,7 @@ namespace Mono.Terminal {
|
|
public void Stop ()
|
|
public void Stop ()
|
|
{
|
|
{
|
|
running = false;
|
|
running = false;
|
|
- Wakeup ();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- AutoResetEvent keyReady = new AutoResetEvent (false);
|
|
|
|
- AutoResetEvent waitForProbe = new AutoResetEvent (false);
|
|
|
|
- ConsoleKeyInfo? windowsKeyResult = null;
|
|
|
|
- void WindowsKeyReader ()
|
|
|
|
- {
|
|
|
|
- while (true) {
|
|
|
|
- waitForProbe.WaitOne ();
|
|
|
|
- windowsKeyResult = Console.ReadKey (true);
|
|
|
|
- keyReady.Set ();
|
|
|
|
- }
|
|
|
|
|
|
+ driver.Wakeup ();
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
@@ -333,44 +456,7 @@ namespace Mono.Terminal {
|
|
/// </remarks>
|
|
/// </remarks>
|
|
public bool EventsPending (bool wait = false)
|
|
public bool EventsPending (bool wait = false)
|
|
{
|
|
{
|
|
- long now = DateTime.UtcNow.Ticks;
|
|
|
|
- if (useUnix) {
|
|
|
|
- int pollTimeout, n;
|
|
|
|
- if (timeouts.Count > 0){
|
|
|
|
- pollTimeout = (int)((timeouts.Keys [0] - now) / TimeSpan.TicksPerMillisecond);
|
|
|
|
- if (pollTimeout < 0)
|
|
|
|
- return true;
|
|
|
|
-
|
|
|
|
- } else
|
|
|
|
- pollTimeout = -1;
|
|
|
|
-
|
|
|
|
- if (!wait)
|
|
|
|
- pollTimeout = 0;
|
|
|
|
-
|
|
|
|
- UpdatePollMap ();
|
|
|
|
-
|
|
|
|
- n = poll (pollmap, (uint)pollmap.Length, pollTimeout);
|
|
|
|
- int ic;
|
|
|
|
- lock (idleHandlers)
|
|
|
|
- ic = idleHandlers.Count;
|
|
|
|
- return n > 0 || timeouts.Count > 0 && ((timeouts.Keys [0] - DateTime.UtcNow.Ticks) < 0) || ic > 0;
|
|
|
|
- } else {
|
|
|
|
- int waitTimeout;
|
|
|
|
- if (timeouts.Count > 0){
|
|
|
|
- waitTimeout = (int)((timeouts.Keys [0] - now) / TimeSpan.TicksPerMillisecond);
|
|
|
|
- if (waitTimeout < 0)
|
|
|
|
- return true;
|
|
|
|
- } else
|
|
|
|
- waitTimeout = -1;
|
|
|
|
-
|
|
|
|
- if (!wait)
|
|
|
|
- waitTimeout = 0;
|
|
|
|
-
|
|
|
|
- windowsKeyResult = null;
|
|
|
|
- waitForProbe.Set ();
|
|
|
|
- keyReady.WaitOne (waitTimeout);
|
|
|
|
- return windowsKeyResult.HasValue;
|
|
|
|
- }
|
|
|
|
|
|
+ return driver.EventsPending (wait);
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
@@ -387,27 +473,7 @@ namespace Mono.Terminal {
|
|
if (timeouts.Count > 0)
|
|
if (timeouts.Count > 0)
|
|
RunTimers ();
|
|
RunTimers ();
|
|
|
|
|
|
- if (useUnix) {
|
|
|
|
- if (pollmap != null) {
|
|
|
|
- foreach (var p in pollmap) {
|
|
|
|
- Watch watch;
|
|
|
|
-
|
|
|
|
- if (p.revents == 0)
|
|
|
|
- continue;
|
|
|
|
-
|
|
|
|
- if (!descriptorWatchers.TryGetValue (p.fd, out watch))
|
|
|
|
- continue;
|
|
|
|
- if (!watch.Callback (this))
|
|
|
|
- descriptorWatchers.Remove (p.fd);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- } else {
|
|
|
|
- if (windowsKeyResult.HasValue) {
|
|
|
|
- if (WindowsKeyPressed != null)
|
|
|
|
- WindowsKeyPressed (windowsKeyResult.Value);
|
|
|
|
- windowsKeyResult = null;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ driver.MainIteration ();
|
|
|
|
|
|
lock (idleHandlers){
|
|
lock (idleHandlers){
|
|
if (idleHandlers.Count > 0)
|
|
if (idleHandlers.Count > 0)
|