Made server communication faster by using a shared memory block.
A few other optimizations in request processing in the server.
Moved automatically generated request definitions to server.h and
removed include/server/request.h.

diff --git a/server/request.c b/server/request.c
index d8b6eab..a8cab9c 100644
--- a/server/request.c
+++ b/server/request.c
@@ -18,54 +18,63 @@
 #include "winnt.h"
 #include "winbase.h"
 #include "wincon.h"
-#define WANT_REQUEST_HANDLERS
-#include "server.h"
 #include "thread.h"
+#include "server.h"
+#define WANT_REQUEST_HANDLERS
+#include "request.h"
  
 struct thread *current = NULL;  /* thread handling the current request */
 
 /* complain about a protocol error and terminate the client connection */
-void fatal_protocol_error( const char *err, ... )
+void fatal_protocol_error( const char *err )
 {
-    va_list args;
+    unsigned char *p;
 
-    va_start( args, err );
-    fprintf( stderr, "Protocol error:%p: ", current );
-    vfprintf( stderr, err, args );
-    va_end( args );
+    fprintf( stderr, "Protocol error:%p: %s\n    request:", current, err );
+    for (p = (unsigned char *)current->buffer; p < (unsigned char *)current->req_end; p++)
+        fprintf( stderr, " %02x", *p );
+    fprintf( stderr, "\n" );
     remove_client( current->client, -2 );
 }
 
 /* call a request handler */
-void call_req_handler( struct thread *thread, enum request req,
-                       void *data, int len, int fd )
+void call_req_handler( struct thread *thread, int fd )
 {
-    const struct handler *handler = &req_handlers[req];
-    char *ptr;
+    const struct handler *handler;
+    struct header *head;
+    unsigned int req, len;
 
     current = thread;
-    if ((req < 0) || (req >= REQ_NB_REQUESTS))
-    {
-        fatal_protocol_error( "unknown request %d\n", req );
-        return;
-    }
+    assert (current);
 
-    if (len < handler->min_size)
-    {
-        fatal_protocol_error( "req %d bad length %d < %d\n", req, len, handler->min_size );
-        return;
-    }
+    head = (struct header *)current->buffer;
+
+    req = head->type;
+    len = head->len;
+
+    /* set the buffer pointers */
+    current->req_pos = current->reply_pos = (char *)current->buffer + sizeof(struct header);
+    current->req_end = (char *)current->buffer + len;
+    clear_error();
+
+    if ((len < sizeof(struct header)) || (len > MAX_MSG_LENGTH)) goto bad_header;
+    if (req >= REQ_NB_REQUESTS) goto bad_header;
+
+    if (debug_level) trace_request( req, fd );
 
     /* now call the handler */
-    if (current)
-    {
-        CLEAR_ERROR();
-        if (debug_level) trace_request( req, data, len, fd );
-    }
-    len -= handler->min_size;
-    ptr = (char *)data + handler->min_size;
-    handler->handler( data, ptr, len, fd );
+    handler = &req_handlers[req];
+    if (!check_req_data( handler->min_size )) goto bad_request;
+    handler->handler( get_req_data( handler->min_size ), fd );
+    if (current && current->state != SLEEPING) send_reply( current );
     current = NULL;
+    return;
+
+ bad_header:
+    /* dump only the header */
+    current->req_end = (char *)current->buffer + sizeof(struct header);
+ bad_request:
+    fatal_protocol_error( "bad request" );
 }
 
 /* handle a client timeout */
@@ -73,7 +82,7 @@
 {
     current = (struct thread *)thread;
     if (debug_level) trace_timeout();
-    CLEAR_ERROR();
+    clear_error();
     thread_timeout();
     current = NULL;
 }
@@ -92,14 +101,32 @@
     current = (old_current != thread) ? old_current : NULL;
 }
 
+/* set the fd to pass to the thread */
+void set_reply_fd( struct thread *thread, int pass_fd )
+{
+    client_pass_fd( thread->client, pass_fd );
+}
+
+/* send a reply to a thread */
+void send_reply( struct thread *thread )
+{
+    struct header *head = thread->buffer;
+    int len = (char *)thread->reply_pos - (char *)thread->buffer;
+
+    assert( len < MAX_MSG_LENGTH );
+
+    head->len  = len;
+    head->type = thread->error;
+    if (thread->state == SLEEPING) thread->state = RUNNING;
+    client_reply( thread->client );
+}
+
 /* set the debug level */
 DECL_HANDLER(set_debug)
 {
     debug_level = req->level;
     /* Make sure last_req is initialized */
     current->last_req = REQ_SET_DEBUG;
-    CLEAR_ERROR();
-    send_reply( current, -1, 0 );
 }
 
 /* debugger support operations */
@@ -115,6 +142,4 @@
         resume_all_threads();
         break;
     }
-
-    send_reply( current, -1, 0 );
 }