2012-06-06 11:27:52 +01:00
|
|
|
#ifndef CLIENT_H
|
|
|
|
#define CLIENT_H
|
|
|
|
|
2013-06-06 14:16:20 +01:00
|
|
|
#include <signal.h>
|
|
|
|
#include <time.h>
|
|
|
|
|
2012-06-22 10:05:41 +01:00
|
|
|
/** CLIENT_MAX_WAIT_SECS
|
|
|
|
* This is the length of time an inbound migration will wait for a fresh
|
|
|
|
* write before assuming the source has Gone Away. Note: it is *not*
|
|
|
|
* the time from one write to the next, it is the gap between the end of
|
|
|
|
* one write and the start of the next.
|
|
|
|
*/
|
|
|
|
#define CLIENT_MAX_WAIT_SECS 5
|
|
|
|
|
2013-06-06 14:16:20 +01:00
|
|
|
/** CLIENT_HANDLER_TIMEOUT
|
|
|
|
* This is the length of time (in seconds) any request can be outstanding for.
|
|
|
|
* If we spend longer than this in a request, the whole server is killed.
|
|
|
|
*/
|
|
|
|
#define CLIENT_HANDLER_TIMEOUT 120
|
|
|
|
|
|
|
|
/** CLIENT_KILLSWITCH_SIGNAL
|
|
|
|
* The signal number we use to kill the server when *any* killswitch timer
|
|
|
|
* fires. We don't actually need to install a signal handler for it, the default
|
|
|
|
* behaviour is perfectly fine.
|
|
|
|
*/
|
|
|
|
#define CLIENT_KILLSWITCH_SIGNAL ( SIGRTMIN + 1 )
|
|
|
|
|
2012-06-08 18:03:41 +01:00
|
|
|
|
2012-06-06 11:33:17 +01:00
|
|
|
struct client {
|
2012-06-12 15:08:07 +01:00
|
|
|
/* When we call pthread_join, if the thread is already dead
|
|
|
|
* we can get an ESRCH. Since we have no other way to tell
|
|
|
|
* if that ESRCH is from a dead thread or a thread that never
|
|
|
|
* existed, we use a `stopped` flag to indicate a thread which
|
|
|
|
* did exist, but went away. Only check this after a
|
|
|
|
* pthread_join call.
|
|
|
|
*/
|
|
|
|
int stopped;
|
2012-06-06 11:27:52 +01:00
|
|
|
int socket;
|
2013-06-06 14:16:20 +01:00
|
|
|
|
2012-06-06 11:27:52 +01:00
|
|
|
int fileno;
|
|
|
|
char* mapped;
|
2012-06-07 11:44:19 +01:00
|
|
|
|
|
|
|
struct self_pipe * stop_signal;
|
2013-06-06 14:16:20 +01:00
|
|
|
|
2012-06-06 11:27:52 +01:00
|
|
|
struct server* serve; /* FIXME: remove above duplication */
|
2012-06-21 18:01:50 +01:00
|
|
|
|
2012-07-12 09:39:39 +01:00
|
|
|
/* Have we seen a REQUEST_DISCONNECT message? */
|
|
|
|
int disconnect;
|
2013-06-06 14:16:20 +01:00
|
|
|
|
|
|
|
/* kill the whole server if a request has been outstanding too long */
|
|
|
|
timer_t killswitch;
|
|
|
|
|
2012-06-06 11:27:52 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
void* client_serve(void* client_uncast);
|
2012-06-07 11:44:19 +01:00
|
|
|
struct client * client_create( struct server * serve, int socket );
|
|
|
|
void client_destroy( struct client * client );
|
|
|
|
void client_signal_stop( struct client * client );
|
2012-06-06 11:27:52 +01:00
|
|
|
|
|
|
|
#endif
|
2013-06-06 14:16:20 +01:00
|
|
|
|