help-smalltalk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Help-smalltalk] [PATCH] Wild guess on windows console problems


From: Paolo Bonzini
Subject: [Help-smalltalk] [PATCH] Wild guess on windows console problems
Date: Tue, 02 Oct 2007 10:25:17 +0200
User-agent: Thunderbird 2.0.0.6 (Macintosh/20070728)

Here is what I meant in my last message. Not even compiled, obviously, but the idea should be clear.

Can anybody test it?

Paolo
--- orig/lib-src/socketx.c
+++ mod/lib-src/socketx.c
@@ -24,6 +24,9 @@
 #include <conio.h>
 
 #define MAX_WIN_HANDLES        300     /* max number of fd we can handle */
+#define CONSOLE_HUP -1
+
+static int get_number_of_console_key_events (HANDLE h);
 
 /* n = maxfd + 1 */
 int
@@ -90,56 +93,41 @@ win_select (int n, fd_set * rfds, fd_set
   nset = 0;
   for (i = 0; i < nhandles; i++)
     {
-      ret = WaitForSingleObject (handle_array[i], 0);
-      if (ret == WAIT_OBJECT_0)
-       {
-         FD_SET (handle_fd[i], handle_set[i]);
-         nset++;
-       }
+      HANDLE h = handle_array[i];
+      ret = WaitForSingleObject (h, 0);
+      if (ret != WAIT_OBJECT_0)
+       continue;
+
+      /* Discard non-key events.  */
+      if (GetFileType (h) == FILE_TYPE_CHAR
+         && get_number_of_console_key_events (h) == 0)
+        continue;
+
+      FD_SET (handle_fd[i], handle_set[i]);
+      nset++;
     }
 
   return nset;
 }
 
-/*
- * This only gets called with the MSG_PEEK flag by poll.c when a read is ready
- * It does not need to indicate the real
- * number of characters available ... only return values of 1 and 0
- * are currently tested for by poll.c
- * TODO: return real number of characters available
- */
 int
-win_recv (int fd, void *buffer, int n, int flags)
+get_number_of_console_key_events (HANDLE h)
 {
   BOOL bRet;
   int i, ret, data_available;
   size_t nread;
   INPUT_RECORD *irbuffer;
   DWORD nevents, nbuffer;
-  HANDLE h = (HANDLE) _get_osfhandle (fd);
-  ret = WaitForSingleObject (h, 0);
-  if (ret == WAIT_OBJECT_0)
-    data_available = 1;
-  else
-    data_available = 0;
-
-  if (flags != MSG_PEEK)
-    return 0;
-
-  /* MSG_PEEK */
-  if (GetFileType (h) != FILE_TYPE_CHAR)
-    return (data_available ? 1 : 0);
 
-  /* console (FILE_TYPE_CHAR) */
   nbuffer = nevents = 0;
   bRet = GetNumberOfConsoleInputEvents (h, &nbuffer);
   if (!bRet || nbuffer == 0)
-    return 0;
+    return CONSOLE_HUP;
 
   irbuffer = (INPUT_RECORD *) alloca (nbuffer * sizeof (INPUT_RECORD));
   bRet = PeekConsoleInput (h, irbuffer, nbuffer, &nevents);
   if (!bRet || nevents == 0)
-    return 0;
+    return CONSOLE_HUP;
 
   nread = 0;
   for (i = 0; i < nevents; i++)
@@ -148,4 +136,36 @@ win_recv (int fd, void *buffer, int n, i
 
   return nread;
 }
+
+/*
+ * This only gets called with the MSG_PEEK flag by poll.c when a read is ready
+ * It does not need to indicate the real
+ * number of characters available ... only return values of 1 and 0
+ * are currently tested for by poll.c
+ * TODO: return real number of characters available
+ */
+int
+win_recv (int fd, void *buffer, int n, int flags)
+{
+  HANDLE h;
+
+  if (flags != MSG_PEEK)
+    return 0;
+
+  h = (HANDLE) _get_osfhandle (fd);
+  ret = WaitForSingleObject (h, 0);
+  if (ret != WAIT_OBJECT_0)
+    return 0;
+
+  if (GetFileType (h) != FILE_TYPE_CHAR)
+    return 1;
+
+  else
+    {
+      int keys = get_number_of_console_key_events (h);
+      return (keys == CONSOLE_HANGUP ? 0 : keys);
+    }
+}
+
+
 #endif

reply via email to

[Prev in Thread] Current Thread [Next in Thread]