]>
Commit | Line | Data |
---|---|---|
f67539c2 TL |
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_TSERVERWINPIPES_H_ | |
21 | #define _THRIFT_TRANSPORT_TSERVERWINPIPES_H_ 1 | |
22 | ||
23 | #include <memory> | |
24 | #include <thrift/transport/TServerTransport.h> | |
25 | #ifndef _WIN32 | |
26 | #include <thrift/transport/TServerSocket.h> | |
27 | #endif | |
28 | #ifdef _WIN32 | |
29 | #include <thrift/windows/Sync.h> | |
30 | #endif | |
31 | ||
32 | #define TPIPE_SERVER_MAX_CONNS_DEFAULT PIPE_UNLIMITED_INSTANCES | |
33 | ||
34 | namespace apache { | |
35 | namespace thrift { | |
36 | namespace transport { | |
37 | ||
38 | /** | |
39 | * Windows Pipes implementation of TServerTransport. | |
40 | * Don't destroy a TPipeServer at global scope, as that will cause a thread join | |
41 | * during DLLMain. That also means that TServer's using TPipeServer shouldn't be at global | |
42 | * scope. | |
43 | */ | |
44 | #ifdef _WIN32 | |
45 | class TPipeServerImpl; | |
46 | class TPipe; | |
47 | ||
48 | class TPipeServer : public TServerTransport { | |
49 | public: | |
50 | // Constructors | |
51 | // Named Pipe - | |
52 | TPipeServer(const std::string& pipename, uint32_t bufsize); | |
53 | TPipeServer(const std::string& pipename, uint32_t bufsize, uint32_t maxconnections); | |
54 | TPipeServer(const std::string& pipename); | |
55 | // Anonymous pipe - | |
56 | TPipeServer(int bufsize); | |
57 | TPipeServer(); | |
58 | ||
59 | // Destructor | |
60 | virtual ~TPipeServer(); | |
61 | ||
62 | // Standard transport callbacks | |
63 | void interrupt() override; | |
64 | void close() override; | |
65 | void listen() override; | |
66 | ||
67 | // Accessors | |
68 | std::string getPipename(); | |
69 | void setPipename(const std::string& pipename); | |
70 | int getBufferSize(); | |
71 | void setBufferSize(int bufsize); | |
72 | HANDLE getPipeHandle(); // Named Pipe R/W -or- Anonymous pipe Read handle | |
73 | HANDLE getWrtPipeHandle(); | |
74 | HANDLE getClientRdPipeHandle(); | |
75 | HANDLE getClientWrtPipeHandle(); | |
76 | bool getAnonymous(); | |
77 | void setAnonymous(bool anon); | |
78 | void setMaxConnections(uint32_t maxconnections); | |
79 | ||
80 | // this function is intended to be used in generic / template situations, | |
81 | // so its name needs to be the same as TPipe's | |
82 | HANDLE getNativeWaitHandle(); | |
83 | ||
84 | protected: | |
85 | virtual std::shared_ptr<TTransport> acceptImpl(); | |
86 | ||
87 | private: | |
88 | std::shared_ptr<TPipeServerImpl> impl_; | |
89 | ||
90 | std::string pipename_; | |
91 | uint32_t bufsize_; | |
92 | uint32_t maxconns_; | |
93 | bool isAnonymous_; | |
94 | }; | |
95 | #else //_WIN32 | |
96 | //*NIX named pipe implementation uses domain socket | |
97 | typedef TServerSocket TPipeServer; | |
98 | #endif | |
99 | } | |
100 | } | |
101 | } // apache::thrift::transport | |
102 | ||
103 | #endif // #ifndef _THRIFT_TRANSPORT_TSERVERWINPIPES_H_ |