]>
git.proxmox.com Git - ceph.git/blob - ceph/src/jaegertracing/thrift/lib/cpp/src/thrift/server/TConnectedClient.cpp
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
10 * http://www.apache.org/licenses/LICENSE-2.0
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
20 #include <thrift/server/TConnectedClient.h>
26 using apache::thrift::TProcessor
;
27 using apache::thrift::protocol::TProtocol
;
28 using apache::thrift::server::TServerEventHandler
;
29 using apache::thrift::transport::TTransport
;
30 using apache::thrift::transport::TTransportException
;
31 using std::shared_ptr
;
34 TConnectedClient::TConnectedClient(const shared_ptr
<TProcessor
>& processor
,
35 const shared_ptr
<TProtocol
>& inputProtocol
,
36 const shared_ptr
<TProtocol
>& outputProtocol
,
37 const shared_ptr
<TServerEventHandler
>& eventHandler
,
38 const shared_ptr
<TTransport
>& client
)
40 : processor_(processor
),
41 inputProtocol_(inputProtocol
),
42 outputProtocol_(outputProtocol
),
43 eventHandler_(eventHandler
),
45 opaqueContext_(nullptr) {
48 TConnectedClient::~TConnectedClient() = default;
50 void TConnectedClient::run() {
52 opaqueContext_
= eventHandler_
->createContext(inputProtocol_
, outputProtocol_
);
55 for (bool done
= false; !done
;) {
57 eventHandler_
->processContext(opaqueContext_
, client_
);
61 if (!processor_
->process(inputProtocol_
, outputProtocol_
, opaqueContext_
)) {
64 } catch (const TTransportException
& ttx
) {
65 switch (ttx
.getType()) {
66 case TTransportException::END_OF_FILE
:
67 case TTransportException::INTERRUPTED
:
68 case TTransportException::TIMED_OUT
:
69 // Client disconnected or was interrupted or did not respond within the receive timeout.
70 // No logging needed. Done.
75 // All other transport exceptions are logged.
76 // State of connection is unknown. Done.
77 string errStr
= string("TConnectedClient died: ") + ttx
.what();
78 GlobalOutput(errStr
.c_str());
83 } catch (const TException
& tex
) {
84 string errStr
= string("TConnectedClient processing exception: ") + tex
.what();
85 GlobalOutput(errStr
.c_str());
86 // Disconnect from client, because we could not process the message.
94 void TConnectedClient::cleanup() {
96 eventHandler_
->deleteContext(opaqueContext_
, inputProtocol_
, outputProtocol_
);
100 inputProtocol_
->getTransport()->close();
101 } catch (const TTransportException
& ttx
) {
102 string errStr
= string("TConnectedClient input close failed: ") + ttx
.what();
103 GlobalOutput(errStr
.c_str());
107 outputProtocol_
->getTransport()->close();
108 } catch (const TTransportException
& ttx
) {
109 string errStr
= string("TConnectedClient output close failed: ") + ttx
.what();
110 GlobalOutput(errStr
.c_str());
115 } catch (const TTransportException
& ttx
) {
116 string errStr
= string("TConnectedClient client close failed: ") + ttx
.what();
117 GlobalOutput(errStr
.c_str());
122 } // apache::thrift::server