spserver.hpp
1.3 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
/*
* Copyright 2007 Stephen Liu
* For license terms, see the file COPYING along with this library.
*/
#ifndef __spserver_hpp__
#define __spserver_hpp__
#include <sys/types.h>
#include "spthread.hpp"
class SP_HandlerFactory;
class SP_Session;
class SP_Executor;
class SP_IOChannelFactory;
struct event;
// half-sync/half-async thread pool server
class SP_Server {
public:
SP_Server( const char * bindIP, int port, SP_HandlerFactory * handlerFactory );
~SP_Server();
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();
int run();
void runForever();
private:
SP_HandlerFactory * mHandlerFactory;
SP_IOChannelFactory * mIOChannelFactory;
char mBindIP[ 64 ];
int mPort;
int mIsShutdown;
int mIsRunning;
int mTimeout;
int mMaxThreads;
int mMaxConnections;
int mReqQueueSize;
char * mRefusedMsg;
static sp_thread_result_t SP_THREAD_CALL eventLoop( void * arg );
int start();
static void sigHandler( int, short, void * arg );
static void outputCompleted( void * arg );
};
#endif