Back to home page

EIC code displayed by LXR

 
 

    


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_TSERVERWINPIPES_H_
0021 #define _THRIFT_TRANSPORT_TSERVERWINPIPES_H_ 1
0022 
0023 #include <memory>
0024 #include <thrift/transport/TServerTransport.h>
0025 #ifndef _WIN32
0026 #include <thrift/transport/TServerSocket.h>
0027 #endif
0028 
0029 #define TPIPE_SERVER_MAX_CONNS_DEFAULT PIPE_UNLIMITED_INSTANCES
0030 
0031 // Windows - set security to allow non-elevated apps
0032 // to access pipes created by elevated apps.
0033 // Full access to everyone
0034 const std::string DEFAULT_PIPE_SECURITY{"D:(A;;FA;;;WD)"};
0035 
0036 namespace apache {
0037 namespace thrift {
0038 namespace transport {
0039 
0040 /**
0041  * Windows Pipes implementation of TServerTransport.
0042  * Don't destroy a TPipeServer at global scope, as that will cause a thread join
0043  * during DLLMain.  That also means that TServer's using TPipeServer shouldn't be at global
0044  * scope.
0045  */
0046 #ifdef _WIN32
0047 class TPipeServerImpl;
0048 class TPipe;
0049 
0050 class TPipeServer : public TServerTransport {
0051 public:
0052   // Constructors
0053   // Named Pipe -
0054   TPipeServer(const std::string& pipename, uint32_t bufsize);
0055   TPipeServer(const std::string& pipename, uint32_t bufsize, uint32_t maxconnections);
0056   TPipeServer(const std::string& pipename,
0057               uint32_t bufsize,
0058               uint32_t maxconnections,
0059               const std::string& securityDescriptor);
0060   TPipeServer(const std::string& pipename);
0061   // Anonymous pipe -
0062   TPipeServer(int bufsize);
0063   TPipeServer();
0064 
0065   // Destructor
0066   virtual ~TPipeServer();
0067 
0068   bool isOpen() const override;
0069 
0070   // Standard transport callbacks
0071   void interrupt() override;
0072   void close() override;
0073   void listen() override;
0074 
0075   // Accessors
0076   std::string getPipename();
0077   void setPipename(const std::string& pipename);
0078   int getBufferSize();
0079   void setBufferSize(int bufsize);
0080   HANDLE getPipeHandle(); // Named Pipe R/W -or- Anonymous pipe Read handle
0081   HANDLE getWrtPipeHandle();
0082   HANDLE getClientRdPipeHandle();
0083   HANDLE getClientWrtPipeHandle();
0084   bool getAnonymous();
0085   void setAnonymous(bool anon);
0086   void setMaxConnections(uint32_t maxconnections);
0087   void setSecurityDescriptor(const std::string& securityDescriptor);
0088 
0089   // this function is intended to be used in generic / template situations,
0090   // so its name needs to be the same as TPipe's
0091   HANDLE getNativeWaitHandle();
0092 
0093 protected:
0094   virtual std::shared_ptr<TTransport> acceptImpl();
0095 
0096 private:
0097   std::shared_ptr<TPipeServerImpl> impl_;
0098 
0099   std::string pipename_;
0100   std::string securityDescriptor_;
0101   uint32_t bufsize_;
0102   uint32_t maxconns_;
0103   bool isAnonymous_;
0104 };
0105 #else //_WIN32
0106 //*NIX named pipe implementation uses domain socket
0107 typedef TServerSocket TPipeServer;
0108 #endif
0109 }
0110 }
0111 } // apache::thrift::transport
0112 
0113 #endif // #ifndef _THRIFT_TRANSPORT_TSERVERWINPIPES_H_