Removed client-side wait functions; all waiting is now done through
the server.

diff --git a/files/change.c b/files/change.c
index 5b99ca5..331700c 100644
--- a/files/change.c
+++ b/files/change.c
@@ -15,22 +15,13 @@
 #include "process.h"
 #include "thread.h"
 #include "heap.h"
+#include "server.h"
 #include "debug.h"
 
-static BOOL32 CHANGE_Signaled( K32OBJ *obj, DWORD thread_id );
-static BOOL32 CHANGE_Satisfied( K32OBJ *obj, DWORD thread_id );
-static void CHANGE_AddWait( K32OBJ *obj, DWORD thread_id );
-static void CHANGE_RemoveWait( K32OBJ *obj, DWORD thread_id );
 static void CHANGE_Destroy( K32OBJ *obj );
 
 const K32OBJ_OPS CHANGE_Ops =
 {
-    CHANGE_Signaled,    /* signaled */
-    CHANGE_Satisfied,   /* satisfied */
-    CHANGE_AddWait,     /* add_wait */
-    CHANGE_RemoveWait,  /* remove_wait */
-    NULL,               /* read */
-    NULL,               /* write */
     CHANGE_Destroy      /* destroy */
 };
 
@@ -48,51 +39,6 @@
 
 } CHANGE_OBJECT;
 
-/***********************************************************************
- *           CHANGE_Signaled
- */
-static BOOL32 CHANGE_Signaled( K32OBJ *obj, DWORD thread_id )
-{
-    CHANGE_OBJECT *change = (CHANGE_OBJECT *)obj;
-    assert( obj->type == K32OBJ_CHANGE );
-    return change->notify;
-}
-
-/***********************************************************************
- *           CHANGE_Satisfied
- *
- * Wait on this object has been satisfied.
- */
-static BOOL32 CHANGE_Satisfied( K32OBJ *obj, DWORD thread_id )
-{
-    assert( obj->type == K32OBJ_CHANGE );
-    return FALSE;  /* Not abandoned */
-}
-
-/***********************************************************************
- *           CHANGE_AddWait
- *
- * Add thread to object wait queue.
- */
-static void CHANGE_AddWait( K32OBJ *obj, DWORD thread_id )
-{
-    CHANGE_OBJECT *change = (CHANGE_OBJECT *)obj;
-    assert( obj->type == K32OBJ_CHANGE );
-    THREAD_AddQueue( &change->wait_queue, THREAD_ID_TO_THDB(thread_id) );
-}
-
-/***********************************************************************
- *           CHANGE_RemoveWait
- *
- * Remove thread from object wait queue.
- */
-static void CHANGE_RemoveWait( K32OBJ *obj, DWORD thread_id )
-{
-    CHANGE_OBJECT *change = (CHANGE_OBJECT *)obj;
-    assert( obj->type == K32OBJ_CHANGE );
-    THREAD_RemoveQueue( &change->wait_queue, THREAD_ID_TO_THDB(thread_id) );
-}
-
 /****************************************************************************
  *		CHANGE_Destroy
  */
@@ -118,11 +64,24 @@
                                                 BOOL32 bWatchSubtree,
                                                 DWORD dwNotifyFilter ) 
 {
-    HANDLE32 handle;
     CHANGE_OBJECT *change;
+    struct create_change_notification_request req;
+    struct create_change_notification_reply reply;
+    int len;
+
+    req.subtree = bWatchSubtree;
+    req.filter  = dwNotifyFilter;
+    CLIENT_SendRequest( REQ_CREATE_CHANGE_NOTIFICATION, -1, 1, &req, sizeof(req) );
+    CLIENT_WaitReply( &len, NULL, 1, &reply, sizeof(reply) );
+    CHECK_LEN( len, sizeof(reply) );
+    if (reply.handle == -1) return INVALID_HANDLE_VALUE32;
 
     change = HeapAlloc( SystemHeap, 0, sizeof(CHANGE_OBJECT) );
-    if (!change) return INVALID_HANDLE_VALUE32;
+    if (!change)
+    {
+        CLIENT_CloseHandle( reply.handle );
+        return INVALID_HANDLE_VALUE32;
+    }
 
     change->header.type = K32OBJ_CHANGE;
     change->header.refcount = 1;
@@ -134,11 +93,9 @@
     change->wait_queue = NULL;
     change->notify = FALSE;
 
-    handle = HANDLE_Alloc( PROCESS_Current(), &change->header, 
-                           FILE_ALL_ACCESS /*FIXME*/, TRUE, -1 );
-    /* If the allocation failed, the object is already destroyed */
-    if (handle == INVALID_HANDLE_VALUE32) change = NULL;
-    return handle;
+    return HANDLE_Alloc( PROCESS_Current(), &change->header, 
+                         STANDARD_RIGHTS_REQUIRED|SYNCHRONIZE /*FIXME*/,
+                         FALSE, reply.handle );
 }
 
 /****************************************************************************
diff --git a/files/file.c b/files/file.c
index 585b461..5b000cf 100644
--- a/files/file.c
+++ b/files/file.c
@@ -45,29 +45,10 @@
 #define MAP_ANON MAP_ANONYMOUS
 #endif
 
-#if 0
-static BOOL32 FILE_Signaled(K32OBJ *ptr, DWORD tid);
-static BOOL32 FILE_Satisfied(K32OBJ *ptr, DWORD thread_id);
-static void FILE_AddWait(K32OBJ *ptr, DWORD tid);
-static void FILE_RemoveWait(K32OBJ *ptr, DWORD thread_id);
-#endif
 static void FILE_Destroy( K32OBJ *obj );
 
 const K32OBJ_OPS FILE_Ops =
 {
-#if 0
-    FILE_Signaled,     /* signaled */
-    FILE_Satisfied,    /* satisfied */
-    FILE_AddWait,      /* add_wait */
-    FILE_RemoveWait,   /* remove_wait */
-#else
-    NULL,              /* signaled */
-    NULL,              /* satisfied */
-    NULL,              /* add_wait */
-    NULL,              /* remove_wait */
-#endif
-    NULL,              /* read */
-    NULL,              /* write */
     FILE_Destroy       /* destroy */
 };
 
@@ -126,58 +107,6 @@
     return handle;
 }
 
-/***********************************************************************
- *		FILE_async_handler			[internal]
- */
-#if 0
-static void
-FILE_async_handler(int unixfd,void *private) {
-	FILE_OBJECT *file = (FILE_OBJECT*)private;
-
-	SYNC_WakeUp(&file->wait_queue,INFINITE32);
-}
-
-static BOOL32 FILE_Signaled(K32OBJ *ptr, DWORD thread_id)
-{
-	fd_set	fds,*readfds = NULL,*writefds = NULL;
-	struct timeval tv;
-	FILE_OBJECT *file = (FILE_OBJECT *)ptr;
-
-	FD_ZERO(&fds);
-	FD_SET(file->unix_handle,&fds);
-	if (file->mode == OF_READ) readfds = &fds;
-	if (file->mode == OF_WRITE) writefds = &fds;
-	if (file->mode == OF_READWRITE) {writefds = &fds; readfds = &fds;}
-	tv.tv_sec = 0;
-	tv.tv_usec = 0;
-	assert(readfds || writefds);
-	if (select(file->unix_handle+1,readfds,writefds,NULL,&tv)>0)
-		return TRUE; /* we triggered one fd. Whereever. */
-	return FALSE;
-}
-
-static void FILE_AddWait(K32OBJ *ptr, DWORD thread_id)
-{
-	FILE_OBJECT *file = (FILE_OBJECT*)ptr;
-	if (!file->wait_queue)
-		ASYNC_RegisterFD(file->unix_handle,FILE_async_handler,file);
-	THREAD_AddQueue(&file->wait_queue,thread_id);
-}
-
-static void FILE_RemoveWait(K32OBJ *ptr, DWORD thread_id)
-{
-	FILE_OBJECT *file = (FILE_OBJECT*)ptr;
-	THREAD_RemoveQueue(&file->wait_queue,thread_id);
-	if (!file->wait_queue)
-		ASYNC_UnregisterFD(file->unix_handle,FILE_async_handler);
-}
-
-static BOOL32 FILE_Satisfied(K32OBJ *ptr, DWORD thread_id)
-{
-	return FALSE; /* not abandoned. Hmm? */
-}
-#endif
-
 
 /***********************************************************************
  *           FILE_Destroy
@@ -1248,6 +1177,7 @@
 {
     K32OBJ *ptr;
     struct get_read_fd_request req;
+    int unix_handle, result;
 
     TRACE(file, "%d %p %ld\n", hFile, buffer, bytesToRead );
 
@@ -1258,29 +1188,25 @@
                                   K32OBJ_UNKNOWN, GENERIC_READ, &req.handle )))
         return FALSE;
 
-    if (req.handle != -1)  /* We have a server handle */
+    if (req.handle == -1)  /* We need a server handle */
     {
-        int unix_handle, result;
-
-        CLIENT_SendRequest( REQ_GET_READ_FD, -1, 1, &req, sizeof(req) );
-        CLIENT_WaitReply( NULL, &unix_handle, 0 );
-        if (unix_handle == -1) return FALSE;
-        if ((result = read( unix_handle, buffer, bytesToRead )) == -1)
-            FILE_SetDosError();
-        close( unix_handle );
         K32OBJ_DecCount( ptr );
-        if (result == -1) return FALSE;
-        if (bytesRead) *bytesRead = result;
-        return TRUE;
+        return FALSE;
     }
-    else
+    CLIENT_SendRequest( REQ_GET_READ_FD, -1, 1, &req, sizeof(req) );
+    CLIENT_WaitReply( NULL, &unix_handle, 0 );
+    K32OBJ_DecCount( ptr );
+    if (unix_handle == -1) return FALSE;
+    while ((result = read( unix_handle, buffer, bytesToRead )) == -1)
     {
-        BOOL32 status = FALSE;
-        if (K32OBJ_OPS(ptr)->read)
-            status = K32OBJ_OPS(ptr)->read(ptr, buffer, bytesToRead, bytesRead, overlapped );
-        K32OBJ_DecCount( ptr );
-        return status;
+        if ((errno == EAGAIN) || (errno == EINTR)) continue;
+        FILE_SetDosError();
+        break;
     }
+    close( unix_handle );
+    if (result == -1) return FALSE;
+    if (bytesRead) *bytesRead = result;
+    return TRUE;
 }
 
 
@@ -1292,6 +1218,7 @@
 {
     K32OBJ *ptr;
     struct get_write_fd_request req;
+    int unix_handle, result;
 
     TRACE(file, "%d %p %ld\n", hFile, buffer, bytesToWrite );
 
@@ -1302,31 +1229,25 @@
                                   K32OBJ_UNKNOWN, GENERIC_WRITE, &req.handle )))
         return FALSE;
 
-    if (req.handle != -1)  /* We have a server handle */
+    if (req.handle == -1)  /* We need a server handle */
     {
-        int unix_handle, result;
-
-        CLIENT_SendRequest( REQ_GET_WRITE_FD, -1, 1, &req, sizeof(req) );
-        CLIENT_WaitReply( NULL, &unix_handle, 0 );
-        if (unix_handle == -1) return FALSE;
-
-        if ((result = write( unix_handle, buffer, bytesToWrite )) == -1)
-            FILE_SetDosError();
-        close( unix_handle );
         K32OBJ_DecCount( ptr );
-        if (result == -1) return FALSE;
-        if (bytesWritten) *bytesWritten = result;
-        return TRUE;
+        return FALSE;
     }
-    else
+    CLIENT_SendRequest( REQ_GET_WRITE_FD, -1, 1, &req, sizeof(req) );
+    CLIENT_WaitReply( NULL, &unix_handle, 0 );
+    K32OBJ_DecCount( ptr );
+    if (unix_handle == -1) return FALSE;
+    while ((result = write( unix_handle, buffer, bytesToWrite )) == -1)
     {
-        BOOL32 status = FALSE;
-        if (K32OBJ_OPS(ptr)->write)
-            status = K32OBJ_OPS(ptr)->write( ptr, buffer, bytesToWrite,
-                                             bytesWritten, overlapped );
-        K32OBJ_DecCount( ptr );
-        return status;
+        if ((errno == EAGAIN) || (errno == EINTR)) continue;
+        FILE_SetDosError();
+        break;
     }
+    close( unix_handle );
+    if (result == -1) return FALSE;
+    if (bytesWritten) *bytesWritten = result;
+    return TRUE;
 }