-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathexample.cpp
54 lines (39 loc) · 1.51 KB
/
example.cpp
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
// This autogenerated skeleton file illustrates how to build a server.
// You should copy it to another filename to avoid overwriting it.
#include <thrift/transport/TServerSocket.h>
#include <thrift/transport/TServerEpollSocket.h>
#include <thrift/server/TEpollServer.h>
#include <thrift/transport/TBufferTransports.h>
#include <thrift/protocol/TBinaryProtocol.h>
using namespace ::apache::thrift;
using namespace ::apache::thrift::protocol;
using namespace ::apache::thrift::transport;
using namespace ::apache::thrift::server;
using boost::shared_ptr;
class exampleHandler: virtual public exampleIf {
public
int32_t ex_fun(const int32_t area){
return ret;
}
};
int main(int argc, char **argv) {
int port = 9090;
int processnum = 5; //process num
shared_ptr<exampleHandler> handler(new exampleHandler());
shared_ptr<TProcessor> processor(new exampleProcessor(handler));
shared_ptr<TServerTransport> serverTransport(new TServerEpollSocket(port, 1000, 1000));
shared_ptr<TTransportFactory> transportFactory(new TBufferedTransportFactory());
shared_ptr<TProtocolFactory> protocolFactory(new TBinaryProtocolFactory());
TEpollServer server(processor, serverTransport, transportFactory, protocolFactory);
server.listen();
for(int i = 1; i <= processnum; ++i){
if(fork() == 0){
fprintf(stderr, "Process %d start serve()\n", getpid());
server.epoll();
server.serve();
break;
}
}
exit(0);
return 0;
}