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_TPIPE_H_
0021 #define _THRIFT_TRANSPORT_TPIPE_H_ 1
0022 
0023 #include <thrift/transport/TTransport.h>
0024 #include <thrift/transport/TVirtualTransport.h>
0025 #ifndef _WIN32
0026 #include <thrift/transport/TSocket.h>
0027 #endif
0028 #ifdef _WIN32
0029 #include <thrift/windows/Sync.h>
0030 #endif
0031 #include <thrift/TNonCopyable.h>
0032 #ifdef _WIN32
0033 #include <thrift/windows/Sync.h>
0034 #endif
0035 
0036 namespace apache {
0037 namespace thrift {
0038 namespace transport {
0039 
0040 /**
0041  * Windows Pipes implementation of the TTransport interface.
0042  * Don't destroy a TPipe at global scope, as that will cause a thread join
0043  * during DLLMain.  That also means that client objects using TPipe shouldn't be at global
0044  * scope.
0045  */
0046 #ifdef _WIN32
0047 class TPipeImpl;
0048 
0049 class TPipe : public TVirtualTransport<TPipe> {
0050 public:
0051   // Constructs a new pipe object.
0052   TPipe(std::shared_ptr<TConfiguration> config = nullptr);
0053   // Named pipe constructors -
0054   explicit TPipe(HANDLE Pipe, std::shared_ptr<TConfiguration> config = nullptr);       // HANDLE is a void*
0055   explicit TPipe(TAutoHandle& Pipe, std::shared_ptr<TConfiguration> config = nullptr); // this ctor will clear out / move from Pipe
0056   // need a const char * overload so string literals don't go to the HANDLE overload
0057   explicit TPipe(const char* pipename, std::shared_ptr<TConfiguration> config = nullptr);
0058   explicit TPipe(const std::string& pipename, std::shared_ptr<TConfiguration> config = nullptr);
0059   // Anonymous pipe -
0060   TPipe(HANDLE PipeRd, HANDLE PipeWrt, std::shared_ptr<TConfiguration> config = nullptr);
0061 
0062   // Destroys the pipe object, closing it if necessary.
0063   virtual ~TPipe();
0064 
0065   // Returns whether the pipe is open & valid.
0066   bool isOpen() const override;
0067 
0068   // Checks whether more data is available in the pipe.
0069   bool peek() override;
0070 
0071   // Creates and opens the named/anonymous pipe.
0072   void open() override;
0073 
0074   // Shuts down communications on the pipe.
0075   void close() override;
0076 
0077   // Reads from the pipe.
0078   virtual uint32_t read(uint8_t* buf, uint32_t len);
0079 
0080   // Writes to the pipe.
0081   virtual void write(const uint8_t* buf, uint32_t len);
0082 
0083   // Accessors
0084   std::string getPipename();
0085   void setPipename(const std::string& pipename);
0086   HANDLE getPipeHandle(); // doubles as the read handle for anon pipe
0087   void setPipeHandle(HANDLE pipehandle);
0088   HANDLE getWrtPipeHandle();
0089   void setWrtPipeHandle(HANDLE pipehandle);
0090   long getConnTimeout();
0091   void setConnTimeout(long seconds);
0092 
0093   // this function is intended to be used in generic / template situations,
0094   // so its name needs to be the same as TPipeServer's
0095   HANDLE getNativeWaitHandle();
0096 
0097 private:
0098   std::shared_ptr<TPipeImpl> impl_;
0099 
0100   std::string pipename_;
0101 
0102   long TimeoutSeconds_;
0103   bool isAnonymous_;
0104 };
0105 
0106 #else
0107 typedef TSocket TPipe;
0108 #endif
0109 }
0110 }
0111 } // apache::thrift::transport
0112 
0113 #endif // #ifndef _THRIFT_TRANSPORT_TPIPE_H_