Mark Slee | 9f0c651 | 2007-02-28 23:58:26 +0000 | [diff] [blame] | 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/ |
| 6 | |
Mark Slee | 2f6404d | 2006-10-10 01:37:40 +0000 | [diff] [blame] | 7 | #ifndef _THRIFT_SERVER_TNONBLOCKINGSERVER_H_ |
| 8 | #define _THRIFT_SERVER_TNONBLOCKINGSERVER_H_ 1 |
| 9 | |
Mark Slee | 4af6ed7 | 2006-10-25 19:02:49 +0000 | [diff] [blame] | 10 | #include <Thrift.h> |
| 11 | #include <server/TServer.h> |
| 12 | #include <transport/TTransportUtils.h> |
Mark Slee | e02385b | 2007-06-09 01:21:16 +0000 | [diff] [blame] | 13 | #include <concurrency/ThreadManager.h> |
Mark Slee | 2f6404d | 2006-10-10 01:37:40 +0000 | [diff] [blame] | 14 | #include <stack> |
David Reiss | 9b20955 | 2008-04-08 06:26:05 +0000 | [diff] [blame] | 15 | #include <string> |
| 16 | #include <errno.h> |
David Reiss | d7a16f4 | 2008-02-19 22:47:29 +0000 | [diff] [blame] | 17 | #include <cstdlib> |
Mark Slee | 2f6404d | 2006-10-10 01:37:40 +0000 | [diff] [blame] | 18 | #include <event.h> |
| 19 | |
Mark Slee | 79b1694 | 2007-11-26 19:05:29 +0000 | [diff] [blame] | 20 | namespace facebook { namespace thrift { namespace server { |
Mark Slee | 2f6404d | 2006-10-10 01:37:40 +0000 | [diff] [blame] | 21 | |
Mark Slee | 5ea15f9 | 2007-03-05 22:55:59 +0000 | [diff] [blame] | 22 | using facebook::thrift::transport::TMemoryBuffer; |
| 23 | using facebook::thrift::protocol::TProtocol; |
Mark Slee | e02385b | 2007-06-09 01:21:16 +0000 | [diff] [blame] | 24 | using facebook::thrift::concurrency::Runnable; |
| 25 | using facebook::thrift::concurrency::ThreadManager; |
Mark Slee | 2f6404d | 2006-10-10 01:37:40 +0000 | [diff] [blame] | 26 | |
| 27 | // Forward declaration of class |
| 28 | class TConnection; |
| 29 | |
| 30 | /** |
| 31 | * This is a non-blocking server in C++ for high performance that operates a |
| 32 | * single IO thread. It assumes that all incoming requests are framed with a |
| 33 | * 4 byte length indicator and writes out responses using the same framing. |
| 34 | * |
| 35 | * It does not use the TServerTransport framework, but rather has socket |
| 36 | * operations hardcoded for use with select. |
| 37 | * |
| 38 | * @author Mark Slee <mcslee@facebook.com> |
| 39 | */ |
| 40 | class TNonblockingServer : public TServer { |
| 41 | private: |
| 42 | |
| 43 | // Listen backlog |
| 44 | static const int LISTEN_BACKLOG = 1024; |
| 45 | |
| 46 | // Server socket file descriptor |
| 47 | int serverSocket_; |
| 48 | |
| 49 | // Port server runs on |
| 50 | int port_; |
| 51 | |
Mark Slee | 92f00fb | 2006-10-25 01:28:17 +0000 | [diff] [blame] | 52 | // Whether to frame responses |
| 53 | bool frameResponses_; |
| 54 | |
Mark Slee | e02385b | 2007-06-09 01:21:16 +0000 | [diff] [blame] | 55 | // For processing via thread pool, may be NULL |
| 56 | boost::shared_ptr<ThreadManager> threadManager_; |
| 57 | |
| 58 | // Is thread pool processing? |
| 59 | bool threadPoolProcessing_; |
| 60 | |
Mark Slee | 79b1694 | 2007-11-26 19:05:29 +0000 | [diff] [blame] | 61 | // The event base for libevent |
| 62 | event_base* eventBase_; |
| 63 | |
| 64 | // Event struct, for use with eventBase_ |
| 65 | struct event serverEvent_; |
| 66 | |
David Reiss | 1997f10 | 2008-04-29 00:29:41 +0000 | [diff] [blame^] | 67 | // Number of TConnection object we've created |
| 68 | size_t numTConnections_; |
| 69 | |
Mark Slee | 2f6404d | 2006-10-10 01:37:40 +0000 | [diff] [blame] | 70 | /** |
| 71 | * This is a stack of all the objects that have been created but that |
| 72 | * are NOT currently in use. When we close a connection, we place it on this |
| 73 | * stack so that the object can be reused later, rather than freeing the |
| 74 | * memory and reallocating a new object later. |
| 75 | */ |
| 76 | std::stack<TConnection*> connectionStack_; |
| 77 | |
| 78 | void handleEvent(int fd, short which); |
| 79 | |
| 80 | public: |
Mark Slee | 5ea15f9 | 2007-03-05 22:55:59 +0000 | [diff] [blame] | 81 | TNonblockingServer(boost::shared_ptr<TProcessor> processor, |
Mark Slee | f937339 | 2007-01-24 19:41:57 +0000 | [diff] [blame] | 82 | int port) : |
| 83 | TServer(processor), |
Mark Slee | 79b1694 | 2007-11-26 19:05:29 +0000 | [diff] [blame] | 84 | serverSocket_(-1), |
Mark Slee | f937339 | 2007-01-24 19:41:57 +0000 | [diff] [blame] | 85 | port_(port), |
Mark Slee | 8eceaea | 2007-06-15 01:43:21 +0000 | [diff] [blame] | 86 | frameResponses_(true), |
dweatherford | 5898599 | 2007-06-19 23:10:19 +0000 | [diff] [blame] | 87 | threadPoolProcessing_(false), |
David Reiss | 1997f10 | 2008-04-29 00:29:41 +0000 | [diff] [blame^] | 88 | eventBase_(NULL), |
| 89 | numTConnections_(0) {} |
Mark Slee | f937339 | 2007-01-24 19:41:57 +0000 | [diff] [blame] | 90 | |
Mark Slee | 79b1694 | 2007-11-26 19:05:29 +0000 | [diff] [blame] | 91 | TNonblockingServer(boost::shared_ptr<TProcessor> processor, |
Mark Slee | 5ea15f9 | 2007-03-05 22:55:59 +0000 | [diff] [blame] | 92 | boost::shared_ptr<TProtocolFactory> protocolFactory, |
Mark Slee | e02385b | 2007-06-09 01:21:16 +0000 | [diff] [blame] | 93 | int port, |
| 94 | boost::shared_ptr<ThreadManager> threadManager = boost::shared_ptr<ThreadManager>()) : |
Aditya Agarwal | 9abb0d6 | 2007-01-24 22:53:54 +0000 | [diff] [blame] | 95 | TServer(processor), |
Mark Slee | 79b1694 | 2007-11-26 19:05:29 +0000 | [diff] [blame] | 96 | serverSocket_(-1), |
Mark Slee | 92f00fb | 2006-10-25 01:28:17 +0000 | [diff] [blame] | 97 | port_(port), |
Mark Slee | e02385b | 2007-06-09 01:21:16 +0000 | [diff] [blame] | 98 | frameResponses_(true), |
Mark Slee | 79b1694 | 2007-11-26 19:05:29 +0000 | [diff] [blame] | 99 | threadManager_(threadManager), |
David Reiss | 1997f10 | 2008-04-29 00:29:41 +0000 | [diff] [blame^] | 100 | eventBase_(NULL), |
| 101 | numTConnections_(0) { |
Mark Slee | 5ea15f9 | 2007-03-05 22:55:59 +0000 | [diff] [blame] | 102 | setInputTransportFactory(boost::shared_ptr<TTransportFactory>(new TTransportFactory())); |
| 103 | setOutputTransportFactory(boost::shared_ptr<TTransportFactory>(new TTransportFactory())); |
Aditya Agarwal | 9abb0d6 | 2007-01-24 22:53:54 +0000 | [diff] [blame] | 104 | setInputProtocolFactory(protocolFactory); |
| 105 | setOutputProtocolFactory(protocolFactory); |
Mark Slee | e02385b | 2007-06-09 01:21:16 +0000 | [diff] [blame] | 106 | setThreadManager(threadManager); |
Aditya Agarwal | 9abb0d6 | 2007-01-24 22:53:54 +0000 | [diff] [blame] | 107 | } |
Aditya Agarwal | 1ea9052 | 2007-01-19 02:02:12 +0000 | [diff] [blame] | 108 | |
Mark Slee | 5ea15f9 | 2007-03-05 22:55:59 +0000 | [diff] [blame] | 109 | TNonblockingServer(boost::shared_ptr<TProcessor> processor, |
| 110 | boost::shared_ptr<TTransportFactory> inputTransportFactory, |
| 111 | boost::shared_ptr<TTransportFactory> outputTransportFactory, |
| 112 | boost::shared_ptr<TProtocolFactory> inputProtocolFactory, |
| 113 | boost::shared_ptr<TProtocolFactory> outputProtocolFactory, |
Mark Slee | e02385b | 2007-06-09 01:21:16 +0000 | [diff] [blame] | 114 | int port, |
| 115 | boost::shared_ptr<ThreadManager> threadManager = boost::shared_ptr<ThreadManager>()) : |
Aditya Agarwal | 9abb0d6 | 2007-01-24 22:53:54 +0000 | [diff] [blame] | 116 | TServer(processor), |
Aditya Agarwal | 1ea9052 | 2007-01-19 02:02:12 +0000 | [diff] [blame] | 117 | serverSocket_(0), |
| 118 | port_(port), |
Mark Slee | e02385b | 2007-06-09 01:21:16 +0000 | [diff] [blame] | 119 | frameResponses_(true), |
Mark Slee | 5d1784a | 2007-12-05 23:20:54 +0000 | [diff] [blame] | 120 | threadManager_(threadManager), |
David Reiss | 1997f10 | 2008-04-29 00:29:41 +0000 | [diff] [blame^] | 121 | eventBase_(NULL), |
| 122 | numTConnections_(0) { |
Aditya Agarwal | 9abb0d6 | 2007-01-24 22:53:54 +0000 | [diff] [blame] | 123 | setInputTransportFactory(inputTransportFactory); |
| 124 | setOutputTransportFactory(outputTransportFactory); |
| 125 | setInputProtocolFactory(inputProtocolFactory); |
| 126 | setOutputProtocolFactory(outputProtocolFactory); |
Mark Slee | e02385b | 2007-06-09 01:21:16 +0000 | [diff] [blame] | 127 | setThreadManager(threadManager); |
Aditya Agarwal | 9abb0d6 | 2007-01-24 22:53:54 +0000 | [diff] [blame] | 128 | } |
Mark Slee | 79b1694 | 2007-11-26 19:05:29 +0000 | [diff] [blame] | 129 | |
Mark Slee | 2f6404d | 2006-10-10 01:37:40 +0000 | [diff] [blame] | 130 | ~TNonblockingServer() {} |
| 131 | |
Mark Slee | e02385b | 2007-06-09 01:21:16 +0000 | [diff] [blame] | 132 | void setThreadManager(boost::shared_ptr<ThreadManager> threadManager) { |
| 133 | threadManager_ = threadManager; |
| 134 | threadPoolProcessing_ = (threadManager != NULL); |
| 135 | } |
| 136 | |
David Reiss | 1997f10 | 2008-04-29 00:29:41 +0000 | [diff] [blame^] | 137 | boost::shared_ptr<ThreadManager> getThreadManager() { |
| 138 | return threadManager_; |
| 139 | } |
| 140 | |
Mark Slee | 79b1694 | 2007-11-26 19:05:29 +0000 | [diff] [blame] | 141 | bool isThreadPoolProcessing() const { |
Mark Slee | e02385b | 2007-06-09 01:21:16 +0000 | [diff] [blame] | 142 | return threadPoolProcessing_; |
| 143 | } |
| 144 | |
| 145 | void addTask(boost::shared_ptr<Runnable> task) { |
| 146 | threadManager_->add(task); |
| 147 | } |
| 148 | |
Mark Slee | 92f00fb | 2006-10-25 01:28:17 +0000 | [diff] [blame] | 149 | void setFrameResponses(bool frameResponses) { |
| 150 | frameResponses_ = frameResponses; |
| 151 | } |
| 152 | |
Mark Slee | 79b1694 | 2007-11-26 19:05:29 +0000 | [diff] [blame] | 153 | bool getFrameResponses() const { |
Mark Slee | 92f00fb | 2006-10-25 01:28:17 +0000 | [diff] [blame] | 154 | return frameResponses_; |
| 155 | } |
| 156 | |
Mark Slee | 79b1694 | 2007-11-26 19:05:29 +0000 | [diff] [blame] | 157 | event_base* getEventBase() const { |
| 158 | return eventBase_; |
| 159 | } |
| 160 | |
David Reiss | 1997f10 | 2008-04-29 00:29:41 +0000 | [diff] [blame^] | 161 | void incrementNumConnections(size_t incr=1) { |
| 162 | numTConnections_ += incr; |
| 163 | } |
| 164 | |
| 165 | size_t getNumConnections() { |
| 166 | return numTConnections_; |
| 167 | } |
| 168 | |
| 169 | size_t getNumIdleConnections() { |
| 170 | return connectionStack_.size(); |
| 171 | } |
| 172 | |
Mark Slee | 2f6404d | 2006-10-10 01:37:40 +0000 | [diff] [blame] | 173 | TConnection* createConnection(int socket, short flags); |
| 174 | |
| 175 | void returnConnection(TConnection* connection); |
| 176 | |
| 177 | static void eventHandler(int fd, short which, void* v) { |
| 178 | ((TNonblockingServer*)v)->handleEvent(fd, which); |
| 179 | } |
| 180 | |
Mark Slee | 79b1694 | 2007-11-26 19:05:29 +0000 | [diff] [blame] | 181 | void listenSocket(); |
| 182 | |
| 183 | void listenSocket(int fd); |
| 184 | |
| 185 | void registerEvents(event_base* base); |
| 186 | |
Mark Slee | 2f6404d | 2006-10-10 01:37:40 +0000 | [diff] [blame] | 187 | void serve(); |
| 188 | }; |
| 189 | |
| 190 | /** |
| 191 | * Two states for sockets, recv and send mode |
| 192 | */ |
| 193 | enum TSocketState { |
| 194 | SOCKET_RECV, |
| 195 | SOCKET_SEND |
| 196 | }; |
| 197 | |
| 198 | /** |
| 199 | * Four states for the nonblocking servr: |
| 200 | * 1) initialize |
| 201 | * 2) read 4 byte frame size |
| 202 | * 3) read frame of data |
| 203 | * 4) send back data (if any) |
| 204 | */ |
| 205 | enum TAppState { |
| 206 | APP_INIT, |
| 207 | APP_READ_FRAME_SIZE, |
| 208 | APP_READ_REQUEST, |
Mark Slee | e02385b | 2007-06-09 01:21:16 +0000 | [diff] [blame] | 209 | APP_WAIT_TASK, |
Mark Slee | 92f00fb | 2006-10-25 01:28:17 +0000 | [diff] [blame] | 210 | APP_SEND_FRAME_SIZE, |
Mark Slee | 2f6404d | 2006-10-10 01:37:40 +0000 | [diff] [blame] | 211 | APP_SEND_RESULT |
| 212 | }; |
| 213 | |
| 214 | /** |
| 215 | * Represents a connection that is handled via libevent. This connection |
| 216 | * essentially encapsulates a socket that has some associated libevent state. |
| 217 | */ |
| 218 | class TConnection { |
| 219 | private: |
| 220 | |
Mark Slee | e02385b | 2007-06-09 01:21:16 +0000 | [diff] [blame] | 221 | class Task; |
| 222 | |
Mark Slee | 2f6404d | 2006-10-10 01:37:40 +0000 | [diff] [blame] | 223 | // Server handle |
| 224 | TNonblockingServer* server_; |
| 225 | |
| 226 | // Socket handle |
| 227 | int socket_; |
| 228 | |
| 229 | // Libevent object |
| 230 | struct event event_; |
| 231 | |
| 232 | // Libevent flags |
| 233 | short eventFlags_; |
| 234 | |
| 235 | // Socket mode |
| 236 | TSocketState socketState_; |
| 237 | |
| 238 | // Application state |
| 239 | TAppState appState_; |
| 240 | |
| 241 | // How much data needed to read |
| 242 | uint32_t readWant_; |
| 243 | |
| 244 | // Where in the read buffer are we |
| 245 | uint32_t readBufferPos_; |
| 246 | |
| 247 | // Read buffer |
| 248 | uint8_t* readBuffer_; |
| 249 | |
| 250 | // Read buffer size |
| 251 | uint32_t readBufferSize_; |
| 252 | |
| 253 | // Write buffer |
| 254 | uint8_t* writeBuffer_; |
Mark Slee | 79b1694 | 2007-11-26 19:05:29 +0000 | [diff] [blame] | 255 | |
Mark Slee | 2f6404d | 2006-10-10 01:37:40 +0000 | [diff] [blame] | 256 | // Write buffer size |
| 257 | uint32_t writeBufferSize_; |
| 258 | |
| 259 | // How far through writing are we? |
| 260 | uint32_t writeBufferPos_; |
| 261 | |
Mark Slee | 92f00fb | 2006-10-25 01:28:17 +0000 | [diff] [blame] | 262 | // Frame size |
| 263 | int32_t frameSize_; |
| 264 | |
Mark Slee | e02385b | 2007-06-09 01:21:16 +0000 | [diff] [blame] | 265 | // Task handle |
| 266 | int taskHandle_; |
| 267 | |
| 268 | // Task event |
| 269 | struct event taskEvent_; |
| 270 | |
Mark Slee | 2f6404d | 2006-10-10 01:37:40 +0000 | [diff] [blame] | 271 | // Transport to read from |
Mark Slee | 5ea15f9 | 2007-03-05 22:55:59 +0000 | [diff] [blame] | 272 | boost::shared_ptr<TMemoryBuffer> inputTransport_; |
Mark Slee | 2f6404d | 2006-10-10 01:37:40 +0000 | [diff] [blame] | 273 | |
| 274 | // Transport that processor writes to |
Mark Slee | 5ea15f9 | 2007-03-05 22:55:59 +0000 | [diff] [blame] | 275 | boost::shared_ptr<TMemoryBuffer> outputTransport_; |
Mark Slee | 2f6404d | 2006-10-10 01:37:40 +0000 | [diff] [blame] | 276 | |
Aditya Agarwal | 1ea9052 | 2007-01-19 02:02:12 +0000 | [diff] [blame] | 277 | // extra transport generated by transport factory (e.g. BufferedRouterTransport) |
Mark Slee | 5ea15f9 | 2007-03-05 22:55:59 +0000 | [diff] [blame] | 278 | boost::shared_ptr<TTransport> factoryInputTransport_; |
| 279 | boost::shared_ptr<TTransport> factoryOutputTransport_; |
Mark Slee | 4af6ed7 | 2006-10-25 19:02:49 +0000 | [diff] [blame] | 280 | |
| 281 | // Protocol decoder |
Mark Slee | 5ea15f9 | 2007-03-05 22:55:59 +0000 | [diff] [blame] | 282 | boost::shared_ptr<TProtocol> inputProtocol_; |
Aditya Agarwal | 9abb0d6 | 2007-01-24 22:53:54 +0000 | [diff] [blame] | 283 | |
| 284 | // Protocol encoder |
Mark Slee | 5ea15f9 | 2007-03-05 22:55:59 +0000 | [diff] [blame] | 285 | boost::shared_ptr<TProtocol> outputProtocol_; |
Mark Slee | 79b1694 | 2007-11-26 19:05:29 +0000 | [diff] [blame] | 286 | |
Mark Slee | 2f6404d | 2006-10-10 01:37:40 +0000 | [diff] [blame] | 287 | // Go into read mode |
| 288 | void setRead() { |
| 289 | setFlags(EV_READ | EV_PERSIST); |
| 290 | } |
| 291 | |
| 292 | // Go into write mode |
| 293 | void setWrite() { |
| 294 | setFlags(EV_WRITE | EV_PERSIST); |
| 295 | } |
| 296 | |
Mark Slee | 402ee28 | 2007-08-23 01:43:20 +0000 | [diff] [blame] | 297 | // Set socket idle |
| 298 | void setIdle() { |
| 299 | setFlags(0); |
| 300 | } |
| 301 | |
Mark Slee | 2f6404d | 2006-10-10 01:37:40 +0000 | [diff] [blame] | 302 | // Set event flags |
| 303 | void setFlags(short eventFlags); |
| 304 | |
| 305 | // Libevent handlers |
| 306 | void workSocket(); |
| 307 | |
| 308 | // Close this client and reset |
| 309 | void close(); |
| 310 | |
| 311 | public: |
| 312 | |
| 313 | // Constructor |
Aditya Agarwal | 9abb0d6 | 2007-01-24 22:53:54 +0000 | [diff] [blame] | 314 | TConnection(int socket, short eventFlags, TNonblockingServer *s) { |
David Reiss | d7a16f4 | 2008-02-19 22:47:29 +0000 | [diff] [blame] | 315 | readBuffer_ = (uint8_t*)std::malloc(1024); |
Mark Slee | 2f6404d | 2006-10-10 01:37:40 +0000 | [diff] [blame] | 316 | if (readBuffer_ == NULL) { |
Mark Slee | b9ff32a | 2006-11-16 01:00:24 +0000 | [diff] [blame] | 317 | throw new facebook::thrift::TException("Out of memory."); |
Mark Slee | 2f6404d | 2006-10-10 01:37:40 +0000 | [diff] [blame] | 318 | } |
| 319 | readBufferSize_ = 1024; |
Mark Slee | 79b1694 | 2007-11-26 19:05:29 +0000 | [diff] [blame] | 320 | |
Mark Slee | 2f6404d | 2006-10-10 01:37:40 +0000 | [diff] [blame] | 321 | // Allocate input and output tranpsorts |
Mark Slee | 79b1694 | 2007-11-26 19:05:29 +0000 | [diff] [blame] | 322 | // these only need to be allocated once per TConnection (they don't need to be |
Aditya Agarwal | 1ea9052 | 2007-01-19 02:02:12 +0000 | [diff] [blame] | 323 | // reallocated on init() call) |
Mark Slee | 5ea15f9 | 2007-03-05 22:55:59 +0000 | [diff] [blame] | 324 | inputTransport_ = boost::shared_ptr<TMemoryBuffer>(new TMemoryBuffer(readBuffer_, readBufferSize_)); |
| 325 | outputTransport_ = boost::shared_ptr<TMemoryBuffer>(new TMemoryBuffer()); |
Mark Slee | 79b1694 | 2007-11-26 19:05:29 +0000 | [diff] [blame] | 326 | |
Mark Slee | 2f6404d | 2006-10-10 01:37:40 +0000 | [diff] [blame] | 327 | init(socket, eventFlags, s); |
David Reiss | 1997f10 | 2008-04-29 00:29:41 +0000 | [diff] [blame^] | 328 | server_->incrementNumConnections(); |
| 329 | } |
| 330 | |
| 331 | ~TConnection() { |
| 332 | server_->incrementNumConnections(-1); |
Mark Slee | 2f6404d | 2006-10-10 01:37:40 +0000 | [diff] [blame] | 333 | } |
| 334 | |
| 335 | // Initialize |
| 336 | void init(int socket, short eventFlags, TNonblockingServer *s); |
| 337 | |
| 338 | // Transition into a new state |
| 339 | void transition(); |
| 340 | |
| 341 | // Handler wrapper |
Mark Slee | a8de489 | 2008-02-09 00:02:26 +0000 | [diff] [blame] | 342 | static void eventHandler(int fd, short /* which */, void* v) { |
Mark Slee | e02385b | 2007-06-09 01:21:16 +0000 | [diff] [blame] | 343 | assert(fd == ((TConnection*)v)->socket_); |
Mark Slee | 2f6404d | 2006-10-10 01:37:40 +0000 | [diff] [blame] | 344 | ((TConnection*)v)->workSocket(); |
| 345 | } |
Mark Slee | 79b1694 | 2007-11-26 19:05:29 +0000 | [diff] [blame] | 346 | |
Mark Slee | e02385b | 2007-06-09 01:21:16 +0000 | [diff] [blame] | 347 | // Handler wrapper for task block |
Mark Slee | a8de489 | 2008-02-09 00:02:26 +0000 | [diff] [blame] | 348 | static void taskHandler(int fd, short /* which */, void* v) { |
Mark Slee | e02385b | 2007-06-09 01:21:16 +0000 | [diff] [blame] | 349 | assert(fd == ((TConnection*)v)->taskHandle_); |
| 350 | if (-1 == ::close(((TConnection*)v)->taskHandle_)) { |
David Reiss | 9b20955 | 2008-04-08 06:26:05 +0000 | [diff] [blame] | 351 | std::string errStr = "TConnection::taskHandler close handle failed, resource leak " + TOutput::strerror_s(errno); |
| 352 | GlobalOutput(errStr.c_str()); |
Mark Slee | e02385b | 2007-06-09 01:21:16 +0000 | [diff] [blame] | 353 | } |
| 354 | ((TConnection*)v)->transition(); |
| 355 | } |
| 356 | |
Mark Slee | 2f6404d | 2006-10-10 01:37:40 +0000 | [diff] [blame] | 357 | }; |
| 358 | |
| 359 | }}} // facebook::thrift::server |
| 360 | |
| 361 | #endif // #ifndef _THRIFT_SERVER_TSIMPLESERVER_H_ |