blob: b02f1060507392da4d22c98d313d52716add2b48 [file] [log] [blame]
Mark Slee9f0c6512007-02-28 23:58:26 +00001// Copyright (c) 2006- Facebook
2// Distributed under the Thrift Software License
3//
4// See accompanying file LICENSE or visit the Thrift site at:
5// http://developers.facebook.com/thrift/
6
Mark Sleed788b2e2006-09-07 01:26:35 +00007#ifndef _THRIFT_SERVER_TSIMPLESERVER_H_
8#define _THRIFT_SERVER_TSIMPLESERVER_H_ 1
Mark Sleee8540632006-05-30 09:24:40 +00009
10#include "server/TServer.h"
11#include "transport/TServerTransport.h"
12
Marc Slemko6f038a72006-08-03 18:58:09 +000013namespace facebook { namespace thrift { namespace server {
14
Mark Sleee8540632006-05-30 09:24:40 +000015/**
16 * This is the most basic simple server. It is single-threaded and runs a
17 * continuous loop of accepting a single connection, processing requests on
18 * that connection until it closes, and then repeating. It is a good example
19 * of how to extend the TServer interface.
20 *
21 * @author Mark Slee <mcslee@facebook.com>
22 */
23class TSimpleServer : public TServer {
24 public:
Mark Slee5ea15f92007-03-05 22:55:59 +000025 TSimpleServer(boost::shared_ptr<TProcessor> processor,
26 boost::shared_ptr<TServerTransport> serverTransport,
27 boost::shared_ptr<TTransportFactory> transportFactory,
28 boost::shared_ptr<TProtocolFactory> protocolFactory) :
Mark Slee6e3f6372007-03-01 22:05:46 +000029 TServer(processor, serverTransport, transportFactory, protocolFactory),
30 stop_(false) {}
Aditya Agarwal9abb0d62007-01-24 22:53:54 +000031
Mark Slee5ea15f92007-03-05 22:55:59 +000032 TSimpleServer(boost::shared_ptr<TProcessor> processor,
33 boost::shared_ptr<TServerTransport> serverTransport,
34 boost::shared_ptr<TTransportFactory> inputTransportFactory,
35 boost::shared_ptr<TTransportFactory> outputTransportFactory,
36 boost::shared_ptr<TProtocolFactory> inputProtocolFactory,
37 boost::shared_ptr<TProtocolFactory> outputProtocolFactory):
Aditya Agarwal9abb0d62007-01-24 22:53:54 +000038 TServer(processor, serverTransport,
39 inputTransportFactory, outputTransportFactory,
Mark Slee6e3f6372007-03-01 22:05:46 +000040 inputProtocolFactory, outputProtocolFactory),
41 stop_(false) {}
Mark Sleee8540632006-05-30 09:24:40 +000042
43 ~TSimpleServer() {}
44
Mark Slee794993d2006-09-20 01:56:10 +000045 void serve();
Mark Sleee8540632006-05-30 09:24:40 +000046
Mark Slee6e3f6372007-03-01 22:05:46 +000047 void stop() {
48 stop_ = true;
49 }
50
51 protected:
52 bool stop_;
53
Mark Sleee8540632006-05-30 09:24:40 +000054};
55
Marc Slemko6f038a72006-08-03 18:58:09 +000056}}} // facebook::thrift::server
57
Mark Sleed788b2e2006-09-07 01:26:35 +000058#endif // #ifndef _THRIFT_SERVER_TSIMPLESERVER_H_