splfserver.hpp
1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
* Copyright 2007 Stephen Liu
* For license terms, see the file COPYING along with this library.
*/
#ifndef __splfserver_hpp__
#define __splfserver_hpp__
#include "spthread.hpp"
class SP_EventArg;
class SP_ThreadPool;
class SP_HandlerFactory;
class SP_CompletionHandler;
class SP_IOChannelFactory;
typedef struct tagSP_AcceptArg SP_AcceptArg_t;
struct event;
// leader/follower thread pool server
class SP_LFServer {
public:
SP_LFServer( const char * bindIP, int port, SP_HandlerFactory * handlerFactory );
~SP_LFServer();
void setTimeout( int timeout );
void setMaxConnections( int maxConnections );
void setMaxThreads( int maxThreads );
void setReqQueueSize( int reqQueueSize, const char * refusedMsg );
void setIOChannelFactory( SP_IOChannelFactory * ioChannelFactory );
void shutdown();
int isRunning();
// return -1 : cannot listen on ip:port, 0 : ok
int run();
void runForever();
private:
char mBindIP[ 64 ];
int mPort;
int mIsShutdown;
int mIsRunning;
SP_AcceptArg_t * mAcceptArg;
SP_EventArg * mEventArg;
int mMaxThreads;
SP_ThreadPool * mThreadPool;
SP_CompletionHandler * mCompletionHandler;
struct event * mEvAccept;
struct event * mEvSigInt, * mEvSigTerm;
sp_thread_mutex_t mMutex;
void handleOneEvent();
static void lfHandler( void * arg );
static void sigHandler( int, short, void * arg );
};
#endif