blob: 9d71539d332576c88eea45486880b56afff02fe2 [file] [log] [blame]
Mark Sleee8540632006-05-30 09:24:40 +00001#ifndef T_SERVER_TRANSPORT_H
2#define T_SERVER_TRANSPORT_H
3
Mark Slee8d7e1f62006-06-07 06:48:56 +00004#include "transport/TTransport.h"
5#include "transport/TTransportException.h"
Mark Sleee8540632006-05-30 09:24:40 +00006
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 */
13class TServerTransport {
14 public:
15 virtual ~TServerTransport() {}
16
Mark Slee8d7e1f62006-06-07 06:48:56 +000017 /**
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 Sleee8540632006-05-30 09:24:40 +000046 virtual void close() = 0;
47
48 protected:
49 TServerTransport() {}
Mark Slee8d7e1f62006-06-07 06:48:56 +000050
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 Sleee8540632006-05-30 09:24:40 +000059};
60
61#endif