Mark Slee | 9f0c651 | 2007-02-28 23:58:26 +0000 | [diff] [blame] | 1 | // 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 Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 7 | #ifndef _THRIFT_SERVER_TSIMPLESERVER_H_ |
| 8 | #define _THRIFT_SERVER_TSIMPLESERVER_H_ 1 |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 9 | |
| 10 | #include "server/TServer.h" |
| 11 | #include "transport/TServerTransport.h" |
| 12 | |
Marc Slemko | 6f038a7 | 2006-08-03 18:58:09 +0000 | [diff] [blame] | 13 | namespace facebook { namespace thrift { namespace server { |
| 14 | |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 15 | /** |
| 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 | */ |
| 23 | class TSimpleServer : public TServer { |
| 24 | public: |
Mark Slee | 5ea15f9 | 2007-03-05 22:55:59 +0000 | [diff] [blame^] | 25 | 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 Slee | 6e3f637 | 2007-03-01 22:05:46 +0000 | [diff] [blame] | 29 | TServer(processor, serverTransport, transportFactory, protocolFactory), |
| 30 | stop_(false) {} |
Aditya Agarwal | 9abb0d6 | 2007-01-24 22:53:54 +0000 | [diff] [blame] | 31 | |
Mark Slee | 5ea15f9 | 2007-03-05 22:55:59 +0000 | [diff] [blame^] | 32 | 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 Agarwal | 9abb0d6 | 2007-01-24 22:53:54 +0000 | [diff] [blame] | 38 | TServer(processor, serverTransport, |
| 39 | inputTransportFactory, outputTransportFactory, |
Mark Slee | 6e3f637 | 2007-03-01 22:05:46 +0000 | [diff] [blame] | 40 | inputProtocolFactory, outputProtocolFactory), |
| 41 | stop_(false) {} |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 42 | |
| 43 | ~TSimpleServer() {} |
| 44 | |
Mark Slee | 794993d | 2006-09-20 01:56:10 +0000 | [diff] [blame] | 45 | void serve(); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 46 | |
Mark Slee | 6e3f637 | 2007-03-01 22:05:46 +0000 | [diff] [blame] | 47 | void stop() { |
| 48 | stop_ = true; |
| 49 | } |
| 50 | |
| 51 | protected: |
| 52 | bool stop_; |
| 53 | |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 54 | }; |
| 55 | |
Marc Slemko | 6f038a7 | 2006-08-03 18:58:09 +0000 | [diff] [blame] | 56 | }}} // facebook::thrift::server |
| 57 | |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 58 | #endif // #ifndef _THRIFT_SERVER_TSIMPLESERVER_H_ |