1 // Copyright (c) 2006- Facebook
2 // Distributed under the Thrift Software License
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
{
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
{
24 virtual ~TServerTransport() {}
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() {}
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
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();
47 throw TTransportException("accept() may not return NULL");
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() {}
61 * Closes this transport such that future calls to accept will do nothing.
63 virtual void close() = 0;
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_