r1355@opsdev009 (orig r71477): mcslee | 2007-11-27 00:42:19 -0800
[amiethrift.git] / lib / cpp / src / transport / TServerTransport.h
blob9512372e900902ed21b2f4339bafef3ad5f09c0d
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/
7 #ifndef _THRIFT_TRANSPORT_TSERVERTRANSPORT_H_
8 #define _THRIFT_TRANSPORT_TSERVERTRANSPORT_H_ 1
10 #include "TTransport.h"
11 #include "TTransportException.h"
12 #include <boost/shared_ptr.hpp>
14 namespace facebook { namespace thrift { namespace transport {
16 /**
17 * Server transport framework. A server needs to have some facility for
18 * creating base transports to read/write from.
20 * @author Mark Slee <mcslee@facebook.com>
22 class TServerTransport {
23 public:
24 virtual ~TServerTransport() {}
26 /**
27 * Starts the server transport listening for new connections. Prior to this
28 * call most transports will not return anything when accept is called.
30 * @throws TTransportException if we were unable to listen
32 virtual void listen() {}
34 /**
35 * Gets a new dynamically allocated transport object and passes it to the
36 * caller. Note that it is the explicit duty of the caller to free the
37 * allocated object. The returned TTransport object must always be in the
38 * opened state. NULL should never be returned, instead an Exception should
39 * always be thrown.
41 * @return A new TTransport object
42 * @throws TTransportException if there is an error
44 boost::shared_ptr<TTransport> accept() {
45 boost::shared_ptr<TTransport> result = acceptImpl();
46 if (result == NULL) {
47 throw TTransportException("accept() may not return NULL");
49 return result;
52 /**
53 * For "smart" TServerTransport implementations that work in a multi
54 * threaded context this can be used to break out of an accept() call.
55 * It is expected that the transport will throw a TTransportException
56 * with the interrupted error code.
58 virtual void interrupt() {}
60 /**
61 * Closes this transport such that future calls to accept will do nothing.
63 virtual void close() = 0;
65 protected:
66 TServerTransport() {}
68 /**
69 * Subclasses should implement this function for accept.
71 * @return A newly allocated TTransport object
72 * @throw TTransportException If an error occurs
74 virtual boost::shared_ptr<TTransport> acceptImpl() = 0;
78 }}} // facebook::thrift::transport
80 #endif // #ifndef _THRIFT_TRANSPORT_TSERVERTRANSPORT_H_