Commit in reactos on MAIN
include/csrss/csrss.h+121.47 -> 1.48
lib/kernel32/misc/console.c+15-51.82 -> 1.83
lib/kernel32/synch/wait.c+47-831.30 -> 1.31
subsys/csrss/api/process.c+20-11.35 -> 1.36
subsys/csrss/include/api.h+2-11.6 -> 1.7
subsys/csrss/win32csr/conio.c+38-151.16 -> 1.17
subsys/csrss/init.c+2-11.29 -> 1.30
+136-106
7 modified files
- Implemented waitable console handles.  
- Removed a fake event after a input event to empty the queue in CsrReadInputEvent.

reactos/include/csrss
csrss.h 1.47 -> 1.48
diff -u -r1.47 -r1.48
--- csrss.h	2 Nov 2004 20:42:04 -0000	1.47
+++ csrss.h	14 Nov 2004 18:47:09 -0000	1.48
@@ -606,6 +606,15 @@
 {
 } CSRSS_SET_CONSOLE_OUTPUT_CP_REPLY, *PCSRSS_SET_CONSOLE_OUTPUT_CP_REPLY;
 
+typedef struct
+{
+} CSRSS_GET_INPUT_WAIT_HANDLE_REQUEST, *PCSRSS_GET_INPUT_WAIT_HANDLE_REQUEST;
+
+typedef struct
+{
+  HANDLE InputWaitHandle;
+} CSRSS_GET_INPUT_WAIT_HANDLE_REPLY, *PCSRSS_GET_INPUT_WAIT_HANDLE_REPLY;
+
 #define CSRSS_MAX_WRITE_CONSOLE_REQUEST       \
       (MAX_MESSAGE_DATA - sizeof(ULONG) - sizeof(CSRSS_WRITE_CONSOLE_REQUEST))
 
@@ -677,6 +686,7 @@
 #define CSRSS_SET_CONSOLE_CP                (0x32)
 #define CSRSS_GET_CONSOLE_OUTPUT_CP         (0x33)
 #define CSRSS_SET_CONSOLE_OUTPUT_CP         (0x34)
+#define CSRSS_GET_INPUT_WAIT_HANDLE	    (0x35)
 
 /* Keep in sync with definition below. */
 #define CSRSS_REQUEST_HEADER_SIZE (LPC_MESSAGE_BASE_SIZE + sizeof(ULONG))
@@ -741,6 +751,7 @@
         CSRSS_SET_CONSOLE_CP_REQUEST SetConsoleCodePage;
         CSRSS_GET_CONSOLE_OUTPUT_CP_REQUEST GetConsoleOutputCodePage;
         CSRSS_SET_CONSOLE_OUTPUT_CP_REQUEST SetConsoleOutputCodePage;
+	CSRSS_GET_INPUT_WAIT_HANDLE_REQUEST GetConsoleInputWaitHandle;
       } Data;
     };
   };
@@ -795,6 +806,7 @@
         CSRSS_SET_CONSOLE_CP_REPLY SetConsoleCodePage;
         CSRSS_GET_CONSOLE_OUTPUT_CP_REPLY GetConsoleOutputCodePage;
         CSRSS_SET_CONSOLE_OUTPUT_CP_REPLY SetConsoleOutputCodePage;
+	CSRSS_GET_INPUT_WAIT_HANDLE_REPLY GetConsoleInputWaitHandle;
       } Data;
     };
   };

reactos/lib/kernel32/misc
console.c 1.82 -> 1.83
diff -u -r1.82 -r1.83
--- console.c	2 Nov 2004 20:42:05 -0000	1.82
+++ console.c	14 Nov 2004 18:47:09 -0000	1.83
@@ -1,4 +1,4 @@
-/* $Id: console.c,v 1.82 2004/11/02 20:42:05 weiden Exp $
+/* $Id: console.c,v 1.83 2004/11/14 18:47:09 hbirr Exp $
  *
  * COPYRIGHT:       See COPYING in the top level directory
  * PROJECT:         ReactOS system libraries
@@ -559,7 +559,7 @@
 
 
 /*
- * @unimplemented
+ * @implemented
  */
 DWORD STDCALL
 GetConsoleInputWaitHandle (VOID)
@@ -567,9 +567,19 @@
       * Undocumented
       */
 {
-  DPRINT1("GetConsoleInputWaitHandle() UNIMPLEMENTED!\n");
-  SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
-  return FALSE;
+  CSRSS_API_REQUEST Request;
+  CSRSS_API_REPLY Reply;
+  NTSTATUS Status;
+
+  Request.Type = CSRSS_GET_INPUT_WAIT_HANDLE;
+  Status = CsrClientCallServer(&Request, &Reply, sizeof(CSRSS_API_REQUEST),
+				sizeof(CSRSS_API_REPLY));
+  if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Reply.Status))
+    {
+      SetLastErrorByStatus(Status);
+      return 0;
+    }
+  return (DWORD) Reply.Data.GetConsoleInputWaitHandle.InputWaitHandle;
 }
 
 

reactos/lib/kernel32/synch
wait.c 1.30 -> 1.31
diff -u -r1.30 -r1.31
--- wait.c	2 Oct 2004 10:19:38 -0000	1.30
+++ wait.c	14 Nov 2004 18:47:10 -0000	1.31
@@ -1,4 +1,4 @@
-/* $Id: wait.c,v 1.30 2004/10/02 10:19:38 hbirr Exp $
+/* $Id: wait.c,v 1.31 2004/11/14 18:47:10 hbirr Exp $
  *
  * COPYRIGHT:       See COPYING in the top level directory
  * PROJECT:         ReactOS system libraries
@@ -19,38 +19,8 @@
 
 /* FUNCTIONS ****************************************************************/
 
-/*
- * Thread that waits for a console handle.  Console handles only fire when
- * they're readable.
- */
-
-DWORD STDCALL WaitForConsoleHandleThread( PVOID ConHandle ) {
-    DWORD AmtRead = 0;
-    INPUT_RECORD Buffer[1];
-    do {
-	PeekConsoleInputA( ConHandle, Buffer, 1, &AmtRead );
-	if( !AmtRead ) Sleep( 100 );
-    } while( AmtRead == 0 );
-
-    return 0;
-}
-
-/*
- * Return a waitable object given a console handle
- */
-DWORD GetWaiterForConsoleHandle( HANDLE ConHandle, PHANDLE Waitable ) {
-    DWORD ThreadId;
-    HANDLE WaitableHandle = CreateThread( 0, 
-					  0, 
-					  WaitForConsoleHandleThread,
-					  ConHandle,
-					  0,
-					  &ThreadId );
-
-    *Waitable = WaitableHandle;
-
-    return WaitableHandle ? STATUS_SUCCESS : STATUS_UNSUCCESSFUL;
-}
+DWORD STDCALL
+GetConsoleInputWaitHandle (VOID);
 
 /*
  * @implemented
@@ -76,7 +46,6 @@
   PLARGE_INTEGER TimePtr;
   LARGE_INTEGER Time;
   NTSTATUS Status;
-  BOOL CloseWaitHandle = FALSE;
 
   /* Get real handle */
   switch ((ULONG)hHandle)
@@ -97,15 +66,18 @@
   /* Check for console handle */
   if (IsConsoleHandle(hHandle))
     {
-      if (VerifyConsoleIoHandle(hHandle))
+      if (!VerifyConsoleIoHandle(hHandle))
 	{
-	  Status = GetWaiterForConsoleHandle( hHandle, &hHandle );
-	  if (!NT_SUCCESS(Status))
-	    {
-	      SetLastErrorByStatus (Status);
-	      return FALSE;
-	    }
-	  CloseWaitHandle = TRUE;
+	  SetLastError (ERROR_INVALID_HANDLE);
+	  return WAIT_FAILED;
+        }
+	  
+      hHandle = (HANDLE)GetConsoleInputWaitHandle();
+      if (hHandle == NULL || hHandle == INVALID_HANDLE_VALUE)
+        {
+	  SetLastError (ERROR_INVALID_HANDLE);
+	  return WAIT_FAILED;
+
 	}
     }
 
@@ -123,12 +95,6 @@
 				 (BOOLEAN) bAlertable,
 				 TimePtr);
 
-  if (CloseWaitHandle)
-  {
-    TerminateThread(hHandle, 0);
-    NtClose(hHandle);
-  }
-
   if (HIWORD(Status))
     {
       SetLastErrorByStatus (Status);
@@ -169,24 +135,27 @@
   PLARGE_INTEGER TimePtr;
   LARGE_INTEGER Time;
   PHANDLE HandleBuffer;
-  DWORD i,j;
+  HANDLE Handle[3];
+  DWORD i;
   NTSTATUS Status;
-  PBOOL FreeThisHandle;
 
   DPRINT("nCount %lu\n", nCount);
 
-  HandleBuffer = RtlAllocateHeap(RtlGetProcessHeap(), 0, nCount * (sizeof(HANDLE) + sizeof(BOOL)) );
-  FreeThisHandle = (PBOOL)(&HandleBuffer[nCount]);
-
-  if (HandleBuffer == NULL)
+  if (nCount > 3)
     {
-      SetLastError(ERROR_NOT_ENOUGH_MEMORY);
-      return WAIT_FAILED;
+      HandleBuffer = RtlAllocateHeap(RtlGetProcessHeap(), 0, nCount * sizeof(HANDLE));
+      if (HandleBuffer == NULL)
+        {
+          SetLastError(ERROR_NOT_ENOUGH_MEMORY);
+          return WAIT_FAILED;
+        }
+    }
+  else
+    {
+      HandleBuffer = Handle;
     }
-
   for (i = 0; i < nCount; i++)
     {
-      FreeThisHandle[i] = FALSE;
       switch ((DWORD)lpHandles[i])
 	{
 	  case STD_INPUT_HANDLE:
@@ -209,24 +178,24 @@
       /* Check for console handle */
       if (IsConsoleHandle(HandleBuffer[i]))
 	{
-	  if (VerifyConsoleIoHandle(HandleBuffer[i]))
-	    { 
-	      Status = GetWaiterForConsoleHandle( HandleBuffer[i], 
-						  &HandleBuffer[i] );
-	      if (!NT_SUCCESS(Status))
-		{
-		  /* We'll leak some handles unless we close the already
-		     created handles */
-		  for (j = 0; j < i; j++)
-		    if (FreeThisHandle[j])
-		      NtClose(HandleBuffer[j]);
-
-		  SetLastErrorByStatus (Status);
-		  RtlFreeHeap(GetProcessHeap(),0,HandleBuffer);
-		  return FALSE;
-		}
-	      
-	      FreeThisHandle[i] = TRUE;
+	  if (!VerifyConsoleIoHandle(HandleBuffer[i]))
+	    {
+	      if (HandleBuffer != Handle)
+	        {
+	          RtlFreeHeap(GetProcessHeap(),0,HandleBuffer);
+	        }
+	      SetLastError (ERROR_INVALID_HANDLE);
+	      return WAIT_FAILED;
+	    }
+	  HandleBuffer[i] = (HANDLE)GetConsoleInputWaitHandle();
+	  if (HandleBuffer[i] == NULL || HandleBuffer[i] == INVALID_HANDLE_VALUE)
+	    {
+	      if (HandleBuffer != Handle)
+	        {
+	          RtlFreeHeap(GetProcessHeap(),0,HandleBuffer);
+	        }
+	      SetLastError (ERROR_INVALID_HANDLE);
+	      return WAIT_FAILED;
 	    }
 	}
     }
@@ -246,16 +215,11 @@
 				     bWaitAll  ? WaitAll : WaitAny,
 				     (BOOLEAN)bAlertable,
 				     TimePtr);
-
-  for (i = 0; i < nCount; i++)
-    if (FreeThisHandle[i])
+  if (HandleBuffer != Handle)
     {
-      TerminateThread(HandleBuffer[i], 0);
-      NtClose(HandleBuffer[i]);
+      RtlFreeHeap(RtlGetProcessHeap(), 0, HandleBuffer);
     }
 
-  RtlFreeHeap(RtlGetProcessHeap(), 0, HandleBuffer);
-
   if (Status == STATUS_TIMEOUT)
     {
       return WAIT_TIMEOUT;

reactos/subsys/csrss/api
process.c 1.35 -> 1.36
diff -u -r1.35 -r1.36
--- process.c	27 Jun 2004 12:21:31 -0000	1.35
+++ process.c	14 Nov 2004 18:47:10 -0000	1.36
@@ -1,4 +1,4 @@
-/* $Id: process.c,v 1.35 2004/06/27 12:21:31 weiden Exp $
+/* $Id: process.c,v 1.36 2004/11/14 18:47:10 hbirr Exp $
  *
  * reactos/subsys/csrss/api/process.c
  *
@@ -425,4 +425,23 @@
   return Reply->Status;
 }
 
+CSR_API(CsrGetInputWaitHandle)
+{
+  Reply->Header.MessageSize = sizeof(CSRSS_API_REPLY);
+  Reply->Header.DataSize = sizeof(CSRSS_API_REPLY) - LPC_MESSAGE_BASE_SIZE;
+
+  if (ProcessData == NULL)
+  {
+
+     Reply->Data.GetConsoleInputWaitHandle.InputWaitHandle = INVALID_HANDLE_VALUE;
+     Reply->Status = STATUS_INVALID_PARAMETER;
+  }
+  else
+  {
+     Reply->Data.GetConsoleInputWaitHandle.InputWaitHandle = ProcessData->ConsoleEvent;
+     Reply->Status = STATUS_SUCCESS;
+  }
+  return Reply->Status;
+}
+
 /* EOF */

reactos/subsys/csrss/include
api.h 1.6 -> 1.7
diff -u -r1.6 -r1.7
--- api.h	12 Jul 2004 20:09:34 -0000	1.6
+++ api.h	14 Nov 2004 18:47:10 -0000	1.7
@@ -1,4 +1,4 @@
-/* $Id: api.h,v 1.6 2004/07/12 20:09:34 gvg Exp $
+/* $Id: api.h,v 1.7 2004/11/14 18:47:10 hbirr Exp $
  *
  * COPYRIGHT:       See COPYING in the top level directory
  * PROJECT:         ReactOS system libraries
@@ -124,6 +124,7 @@
 CSR_API(CsrCloseHandle);
 CSR_API(CsrVerifyHandle);
 CSR_API(CsrDuplicateHandle);
+CSR_API(CsrGetInputWaitHandle);
 
 /* api/user.c */
 CSR_API(CsrRegisterServicesProcess);

reactos/subsys/csrss/win32csr
conio.c 1.16 -> 1.17
diff -u -r1.16 -r1.17
--- conio.c	2 Nov 2004 20:42:06 -0000	1.16
+++ conio.c	14 Nov 2004 18:47:10 -0000	1.17
@@ -1,4 +1,4 @@
-/* $Id: conio.c,v 1.16 2004/11/02 20:42:06 weiden Exp $
+/* $Id: conio.c,v 1.17 2004/11/14 18:47:10 hbirr Exp $
  *
  * reactos/subsys/csrss/win32csr/conio.c
  *
@@ -186,7 +186,7 @@
   SecurityAttributes.lpSecurityDescriptor = NULL;
   SecurityAttributes.bInheritHandle = TRUE;
 
-  Console->ActiveEvent = CreateEventW(&SecurityAttributes, FALSE, FALSE, NULL);
+  Console->ActiveEvent = CreateEventW(&SecurityAttributes, TRUE, FALSE, NULL);
   if (NULL == Console->ActiveEvent)
     {
       RtlFreeUnicodeString(&Console->Title);
@@ -559,6 +559,11 @@
     {
       /* remove input event from queue */
       CurrentEntry = RemoveHeadList(&Console->InputEvents);
+      if (IsListEmpty(&Console->InputEvents))
+      {
+         CHECKPOINT;
+         ResetEvent(Console->ActiveEvent);
+      }
       Input = CONTAINING_RECORD(CurrentEntry, ConsoleInput, ListEntry);
 
       /* only pay attention to valid ascii chars, on key down */
@@ -1650,7 +1655,6 @@
       ConioUnlockConsole(Console);
     }
 
-  Reply->Data.FillOutputReply.NrCharactersWritten = Written;
   return Reply->Status;
 }
 
@@ -1675,17 +1679,29 @@
     }
 
   /* only get input if there is any */
-  while (Console->InputEvents.Flink != &Console->InputEvents && ! Done)
+  CurrentEntry = Console->InputEvents.Flink;
+  while (CurrentEntry != &Console->InputEvents)
     {
-      CurrentEntry = RemoveHeadList(&Console->InputEvents);
       Input = CONTAINING_RECORD(CurrentEntry, ConsoleInput, ListEntry);
-      Done = !Input->Fake;
-      Reply->Data.ReadInputReply.Input = Input->InputEvent;
+      CurrentEntry = CurrentEntry->Flink;
 
-      if (Request->Data.ReadInputRequest.Unicode == FALSE)
+      if (Done && !Input->Fake)
         {
-          ConioInputEventToAnsi(Console, &Reply->Data.ReadInputReply.Input); /* FIXME */
-        }
+	  Reply->Data.ReadInputReply.MoreEvents = TRUE;
+	  break;
+	}
+      
+      RemoveEntryList(&Input->ListEntry);
+
+      if (!Done && !Input->Fake)
+        {
+          Reply->Data.ReadInputReply.Input = Input->InputEvent;
+          if (Request->Data.ReadInputRequest.Unicode == FALSE)
+            {
+              ConioInputEventToAnsi(Console, &Reply->Data.ReadInputReply.Input);
+            }
+	  Done = TRUE;
+	}
 
       if (Input->InputEvent.EventType == KEY_EVENT)
         {
@@ -1698,18 +1714,24 @@
           Console->WaitingChars--;
         }
       HeapFree(Win32CsrApiHeap, 0, Input);
-
-      Reply->Data.ReadInputReply.MoreEvents = (Console->InputEvents.Flink != &Console->InputEvents);
-      Status = STATUS_SUCCESS;
-      Console->EarlyReturn = FALSE; /* clear early return */
     }
    
-  if (Done)
+  if (Done)
+    {
+      Status = STATUS_SUCCESS;
+      Console->EarlyReturn = FALSE;
+    }
+  else
     {
       Status = STATUS_PENDING;
       Console->EarlyReturn = TRUE;  /* mark for early return */
     }
 
+  if (IsListEmpty(&Console->InputEvents))
+    {
+      ResetEvent(Console->ActiveEvent);
+    }
+
   ConioUnlockConsole(Console);
 
   return Reply->Status = Status;
@@ -2373,6 +2395,7 @@
       /* Destroy the event */
       HeapFree(Win32CsrApiHeap, 0, Input);
     }
+  ResetEvent(Console->ActiveEvent);
   Console->WaitingChars=0;
 
   ConioUnlockConsole(Console);

reactos/subsys/csrss
init.c 1.29 -> 1.30
diff -u -r1.29 -r1.30
--- init.c	12 Jul 2004 20:09:34 -0000	1.29
+++ init.c	14 Nov 2004 18:47:10 -0000	1.30
@@ -1,4 +1,4 @@
-/* $Id: init.c,v 1.29 2004/07/12 20:09:34 gvg Exp $
+/* $Id: init.c,v 1.30 2004/11/14 18:47:10 hbirr Exp $
  * 
  * reactos/subsys/csrss/init.c
  *
@@ -214,6 +214,7 @@
     CSRSS_DEFINE_API(CSRSS_CLOSE_HANDLE,                 CsrCloseHandle),
     CSRSS_DEFINE_API(CSRSS_VERIFY_HANDLE,                CsrVerifyHandle),
     CSRSS_DEFINE_API(CSRSS_DUPLICATE_HANDLE,             CsrDuplicateHandle),
+    CSRSS_DEFINE_API(CSRSS_GET_INPUT_WAIT_HANDLE,        CsrGetInputWaitHandle),
     { 0, 0, 0, NULL }
   };
 
CVSspam 0.2.8