2 * Server-side request handling
4 * Copyright (C) 1998 Alexandre Julliard
13 #include <sys/types.h>
23 #define WANT_REQUEST_HANDLERS
26 struct thread
*current
= NULL
; /* thread handling the current request */
28 /* complain about a protocol error and terminate the client connection */
29 void fatal_protocol_error( struct thread
*thread
, const char *err
, ... )
33 va_start( args
, err
);
34 fprintf( stderr
, "Protocol error:%p: ", thread
);
35 vfprintf( stderr
, err
, args
);
37 remove_client( thread
->client
, PROTOCOL_ERROR
);
40 /* call a request handler */
41 void call_req_handler( struct thread
*thread
, enum request req
, int fd
)
46 if (debug_level
) trace_request( req
, fd
);
48 if (req
< REQ_NB_REQUESTS
)
50 req_handlers
[req
].handler( current
->buffer
, fd
);
51 if (current
&& current
->state
!= SLEEPING
) send_reply( current
);
55 fatal_protocol_error( current
, "bad request %d\n", req
);
58 /* handle a client timeout */
59 void call_timeout_handler( void *thread
)
61 current
= (struct thread
*)thread
;
62 if (debug_level
) trace_timeout();
68 /* a thread has been killed */
69 void call_kill_handler( struct thread
*thread
, int exit_code
)
71 /* must be reentrant WRT call_req_handler */
72 struct thread
*old_current
= current
;
76 if (debug_level
) trace_kill( exit_code
);
77 thread_killed( current
, exit_code
);
79 current
= (old_current
!= thread
) ? old_current
: NULL
;
82 /* set the fd to pass to the thread */
83 void set_reply_fd( struct thread
*thread
, int pass_fd
)
85 client_pass_fd( thread
->client
, pass_fd
);
88 /* send a reply to a thread */
89 void send_reply( struct thread
*thread
)
91 if (thread
->state
== SLEEPING
) thread
->state
= RUNNING
;
92 client_reply( thread
->client
, thread
->error
);
95 /* set the debug level */
96 DECL_HANDLER(set_debug
)
98 debug_level
= req
->level
;
99 /* Make sure last_req is initialized */
100 current
->last_req
= REQ_SET_DEBUG
;
103 /* debugger support operations */
104 DECL_HANDLER(debugger
)
108 case DEBUGGER_FREEZE_ALL
:
109 suspend_all_threads();
112 case DEBUGGER_UNFREEZE_ALL
:
113 resume_all_threads();