Roger Meier | d1bf5d0 | 2012-04-11 21:38:56 +0000 | [diff] [blame] | 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_TPIPE_H_ |
| 21 | #define _THRIFT_TRANSPORT_TPIPE_H_ 1 |
| 22 | #ifdef _WIN32 |
| 23 | |
| 24 | #include "TTransport.h" |
| 25 | #include "TVirtualTransport.h" |
| 26 | |
| 27 | namespace apache { namespace thrift { namespace transport { |
| 28 | |
| 29 | /** |
| 30 | * Windows Pipes implementation of the TTransport interface. |
| 31 | * |
| 32 | */ |
| 33 | class TPipe : public TVirtualTransport<TPipe> { |
| 34 | public: |
| 35 | |
| 36 | // Constructs a new pipe object. |
| 37 | TPipe(); |
| 38 | // Named pipe constructors - |
| 39 | TPipe(HANDLE hPipe); |
| 40 | TPipe(std::string path); |
| 41 | // Anonymous pipe - |
| 42 | TPipe(HANDLE hPipeRd, HANDLE hPipeWrt); |
| 43 | |
| 44 | // Destroys the pipe object, closing it if necessary. |
| 45 | virtual ~TPipe(); |
| 46 | |
| 47 | // Returns whether the pipe is open & valid. |
| 48 | virtual bool isOpen(); |
| 49 | |
| 50 | // Checks whether more data is available in the pipe. |
| 51 | virtual bool peek(); |
| 52 | |
| 53 | // Creates and opens the named/anonymous pipe. |
| 54 | virtual void open(); |
| 55 | |
| 56 | // Shuts down communications on the pipe. |
| 57 | virtual void close(); |
| 58 | |
| 59 | // Reads from the pipe. |
| 60 | virtual uint32_t read(uint8_t* buf, uint32_t len); |
| 61 | |
| 62 | // Writes to the pipe. |
| 63 | virtual void write(const uint8_t* buf, uint32_t len); |
| 64 | |
| 65 | |
| 66 | //Accessors |
| 67 | std::string getPipename(); |
| 68 | void setPipename(std::string pipename); |
| 69 | HANDLE getPipeHandle(); //doubles as the read handle for anon pipe |
| 70 | void setPipeHandle(HANDLE pipehandle); |
| 71 | HANDLE getWrtPipeHandle(); |
| 72 | void setWrtPipeHandle(HANDLE pipehandle); |
| 73 | long getConnectTimeout(); |
| 74 | void setConnectTimeout(long seconds); |
| 75 | |
| 76 | private: |
| 77 | std::string pipename_; |
| 78 | //Named pipe handles are R/W, while anonymous pipes are one or the other (half duplex). |
| 79 | HANDLE hPipe_, hPipeWrt_; |
| 80 | long TimeoutSeconds_; |
| 81 | bool isAnonymous; |
| 82 | |
| 83 | }; |
| 84 | |
| 85 | }}} // apache::thrift::transport |
| 86 | |
| 87 | #endif //_WIN32 |
| 88 | #endif // #ifndef _THRIFT_TRANSPORT_TPIPE_H_ |
| 89 | |