Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 1 | #ifndef T_SERVER_TRANSPORT_H |
| 2 | #define T_SERVER_TRANSPORT_H |
| 3 | |
Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame^] | 4 | #include "transport/TTransport.h" |
| 5 | #include "transport/TTransportException.h" |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 6 | |
| 7 | /** |
| 8 | * Server transport framework. A server needs to have some facility for |
| 9 | * creating base transports to read/write from. |
| 10 | * |
| 11 | * @author Mark Slee <mcslee@facebook.com> |
| 12 | */ |
| 13 | class TServerTransport { |
| 14 | public: |
| 15 | virtual ~TServerTransport() {} |
| 16 | |
Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame^] | 17 | /** |
| 18 | * Starts the server transport listening for new connections. Prior to this |
| 19 | * call most transports will not return anything when accept is called. |
| 20 | * |
| 21 | * @throws TTransportException if we were unable to listen |
| 22 | */ |
| 23 | virtual void listen() {} |
| 24 | |
| 25 | /** |
| 26 | * Gets a new dynamically allocated transport object and passes it to the |
| 27 | * caller. Note that it is the explicit duty of the caller to free the |
| 28 | * allocated object. The returned TTransport object must always be in the |
| 29 | * opened state. NULL should never be returned, instead an Exception should |
| 30 | * always be thrown. |
| 31 | * |
| 32 | * @return A new TTransport object |
| 33 | * @throws TTransportException if there is an error |
| 34 | */ |
| 35 | TTransport* accept() { |
| 36 | TTransport* result = acceptImpl(); |
| 37 | if (result == NULL) { |
| 38 | throw TTransportException("accept() may not return NULL"); |
| 39 | } |
| 40 | return result; |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * Closes this transport such that future calls to accept will do nothing. |
| 45 | */ |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 46 | virtual void close() = 0; |
| 47 | |
| 48 | protected: |
| 49 | TServerTransport() {} |
Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame^] | 50 | |
| 51 | /** |
| 52 | * Subclasses should implement this function for accept. |
| 53 | * |
| 54 | * @return A newly allocated TTransport object |
| 55 | * @throw TTransportException If an error occurs |
| 56 | */ |
| 57 | virtual TTransport* acceptImpl() = 0; |
| 58 | |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 59 | }; |
| 60 | |
| 61 | #endif |