Subversion Repositories SmartDukaan

Rev

Rev 30 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
30 ashish 1
/*
2
 * Licensed to the Apache Software Foundation (ASF) under one
3
 * or more contributor license agreements. See the NOTICE file
4
 * distributed with this work for additional information
5
 * regarding copyright ownership. The ASF licenses this file
6
 * to you under the Apache License, Version 2.0 (the
7
 * "License"); you may not use this file except in compliance
8
 * with the License. You may obtain a copy of the License at
9
 *
10
 *   http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing,
13
 * software distributed under the License is distributed on an
14
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
 * KIND, either express or implied. See the License for the
16
 * specific language governing permissions and limitations
17
 * under the License.
18
 */
19
 
20
#ifndef _THRIFT_TRANSPORT_TSERVERTRANSPORT_H_
21
#define _THRIFT_TRANSPORT_TSERVERTRANSPORT_H_ 1
22
 
23
#include "TTransport.h"
24
#include "TTransportException.h"
25
#include <boost/shared_ptr.hpp>
26
 
27
namespace apache { namespace thrift { namespace transport {
28
 
29
/**
30
 * Server transport framework. A server needs to have some facility for
31
 * creating base transports to read/write from.
32
 *
33
 */
34
class TServerTransport {
35
 public:
36
  virtual ~TServerTransport() {}
37
 
38
  /**
39
   * Starts the server transport listening for new connections. Prior to this
40
   * call most transports will not return anything when accept is called.
41
   *
42
   * @throws TTransportException if we were unable to listen
43
   */
44
  virtual void listen() {}
45
 
46
  /**
47
   * Gets a new dynamically allocated transport object and passes it to the
48
   * caller. Note that it is the explicit duty of the caller to free the
49
   * allocated object. The returned TTransport object must always be in the
50
   * opened state. NULL should never be returned, instead an Exception should
51
   * always be thrown.
52
   *
53
   * @return A new TTransport object
54
   * @throws TTransportException if there is an error
55
   */
56
  boost::shared_ptr<TTransport> accept() {
57
    boost::shared_ptr<TTransport> result = acceptImpl();
58
    if (result == NULL) {
59
      throw TTransportException("accept() may not return NULL");
60
    }
61
    return result;
62
  }
63
 
64
  /**
65
   * For "smart" TServerTransport implementations that work in a multi
66
   * threaded context this can be used to break out of an accept() call.
67
   * It is expected that the transport will throw a TTransportException
68
   * with the interrupted error code.
69
   */
70
  virtual void interrupt() {}
71
 
72
  /**
73
   * Closes this transport such that future calls to accept will do nothing.
74
   */
75
  virtual void close() = 0;
76
 
77
 protected:
78
  TServerTransport() {}
79
 
80
  /**
81
   * Subclasses should implement this function for accept.
82
   *
83
   * @return A newly allocated TTransport object
84
   * @throw TTransportException If an error occurs
85
   */
86
  virtual boost::shared_ptr<TTransport> acceptImpl() = 0;
87
 
88
};
89
 
90
}}} // apache::thrift::transport
91
 
92
#endif // #ifndef _THRIFT_TRANSPORT_TSERVERTRANSPORT_H_