|
|
|||
File indexing completed on 2026-04-17 08:35:03
0001 /* 0002 * Licensed to the Apache Software Foundation (ASF) under one 0003 * or more contributor license agreements. See the NOTICE file 0004 * distributed with this work for additional information 0005 * regarding copyright ownership. The ASF licenses this file 0006 * to you under the Apache License, Version 2.0 (the 0007 * "License"); you may not use this file except in compliance 0008 * with the License. You may obtain a copy of the License at 0009 * 0010 * http://www.apache.org/licenses/LICENSE-2.0 0011 * 0012 * Unless required by applicable law or agreed to in writing, 0013 * software distributed under the License is distributed on an 0014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 0015 * KIND, either express or implied. See the License for the 0016 * specific language governing permissions and limitations 0017 * under the License. 0018 */ 0019 0020 #ifndef _THRIFT_TRANSPORT_TNONBLOCKINGSERVERTRANSPORT_H_ 0021 #define _THRIFT_TRANSPORT_TNONBLOCKINGSERVERTRANSPORT_H_ 1 0022 0023 #include <thrift/transport/TSocket.h> 0024 #include <thrift/transport/TTransportException.h> 0025 0026 namespace apache { 0027 namespace thrift { 0028 namespace transport { 0029 0030 /** 0031 * Server transport framework. A server needs to have some facility for 0032 * creating base transports to read/write from. The server is expected 0033 * to keep track of TTransport children that it creates for purposes of 0034 * controlling their lifetime. 0035 */ 0036 class TNonblockingServerTransport { 0037 public: 0038 virtual ~TNonblockingServerTransport() = default; 0039 0040 /** 0041 * Starts the server transport listening for new connections. Prior to this 0042 * call most transports will not return anything when accept is called. 0043 * 0044 * @throws TTransportException if we were unable to listen 0045 */ 0046 virtual void listen() {} 0047 0048 /** 0049 * Gets a new dynamically allocated transport object and passes it to the 0050 * caller. Note that it is the explicit duty of the caller to free the 0051 * allocated object. The returned TTransport object must always be in the 0052 * opened state. nullptr should never be returned, instead an Exception should 0053 * always be thrown. 0054 * 0055 * @return A new TTransport object 0056 * @throws TTransportException if there is an error 0057 */ 0058 std::shared_ptr<TSocket> accept() { 0059 std::shared_ptr<TSocket> result = acceptImpl(); 0060 if (!result) { 0061 throw TTransportException("accept() may not return nullptr"); 0062 } 0063 return result; 0064 } 0065 0066 /** 0067 * Utility method 0068 * 0069 * @return server socket file descriptor 0070 * @throw TTransportException If an error occurs 0071 */ 0072 0073 virtual THRIFT_SOCKET getSocketFD() = 0; 0074 0075 virtual int getPort() = 0; 0076 0077 virtual int getListenPort() = 0; 0078 0079 /** 0080 * Closes this transport such that future calls to accept will do nothing. 0081 */ 0082 virtual void close() = 0; 0083 0084 protected: 0085 TNonblockingServerTransport() = default; 0086 0087 /** 0088 * Subclasses should implement this function for accept. 0089 * 0090 * @return A newly allocated TTransport object 0091 * @throw TTransportException If an error occurs 0092 */ 0093 virtual std::shared_ptr<TSocket> acceptImpl() = 0; 0094 0095 }; 0096 } 0097 } 0098 } // apache::thrift::transport 0099 0100 #endif // #ifndef _THRIFT_TRANSPORT_TNONBLOCKINGSERVERTRANSPORT_H_
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|