2 * Server-side request handling
4 * Copyright (C) 1998 Alexandre Julliard
13 #include <sys/types.h>
21 #define WANT_REQUEST_HANDLERS
25 struct thread
*current
= NULL
; /* thread handling the current request */
27 /* complain about a protocol error and terminate the client connection */
28 void fatal_protocol_error( const char *err
, ... )
32 va_start( args
, err
);
33 fprintf( stderr
, "Protocol error:%p: ", current
);
34 vfprintf( stderr
, err
, args
);
36 remove_client( current
->client
, -2 );
39 /* call a request handler */
40 void call_req_handler( struct thread
*thread
, enum request req
,
41 void *data
, int len
, int fd
)
43 const struct handler
*handler
= &req_handlers
[req
];
47 if ((req
< 0) || (req
>= REQ_NB_REQUESTS
))
49 fatal_protocol_error( "unknown request %d\n", req
);
53 if (len
< handler
->min_size
)
55 fatal_protocol_error( "req %d bad length %d < %d\n", req
, len
, handler
->min_size
);
59 /* now call the handler */
63 if (debug_level
) trace_request( req
, data
, len
, fd
);
65 len
-= handler
->min_size
;
66 ptr
= (char *)data
+ handler
->min_size
;
67 handler
->handler( data
, ptr
, len
, fd
);
71 /* handle a client timeout */
72 void call_timeout_handler( void *thread
)
74 current
= (struct thread
*)thread
;
75 if (debug_level
) trace_timeout();
81 /* a thread has been killed */
82 void call_kill_handler( struct thread
*thread
, int exit_code
)
84 /* must be reentrant WRT call_req_handler */
85 struct thread
*old_current
= current
;
89 if (debug_level
) trace_kill( exit_code
);
90 thread_killed( current
, exit_code
);
92 current
= (old_current
!= thread
) ? old_current
: NULL
;
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
;
102 send_reply( current
, -1, 0 );
105 /* debugger support operations */
106 DECL_HANDLER(debugger
)
110 case DEBUGGER_FREEZE_ALL
:
111 suspend_all_threads();
114 case DEBUGGER_UNFREEZE_ALL
:
115 resume_all_threads();
119 send_reply( current
, -1, 0 );