Skip to content

Commit e5563ba

Browse files
Handles: [THRIFT-5830: Using THttpTransport using interleaved asynchronous calls may throw exception](https://issues.apache.org/jira/browse/THRIFT-5830)
feat: Implement per-call transport support in THttpTransport - Added ITPerCallTransportProvider interface to define per-call transport creation. - Enhanced TBaseClient to support per-call transport with separate protocols. - Introduced THttpPerCallTransport for handling HTTP requests on a per-call basis. - Updated THttpTransport to manage lifecycle and creation of per-call transports. - Improved error handling and resource management in transport classes. Co-authored-by: Claude Sonnet 5 Co-authored-by: GPT 5.6 Luna Co-authored-by: GitHub Copilot
1 parent 1ae43c8 commit e5563ba

6 files changed

Lines changed: 2036 additions & 39 deletions

File tree

‎compiler/cpp/src/thrift/generate/t_netstd_generator.cc‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2439,6 +2439,40 @@ void t_netstd_generator::generate_service_client(ostream& out, t_service* tservi
24392439
<< indent() << "public Client(TProtocol inputProtocol, TProtocol outputProtocol) : base(inputProtocol, outputProtocol)" << '\n'
24402440
<< indent() << "{" << '\n'
24412441
<< indent() << "}" << '\n'
2442+
<< '\n'
2443+
<< indent() << "/// <summary>" << '\n'
2444+
<< indent() << "/// Initializes a client that uses the protocol factory to create shared protocols and, when supported, per-call protocols." << '\n'
2445+
<< indent() << "/// </summary>" << '\n'
2446+
<< indent() << "/// <param name=\"transport\">The shared transport. The client owns protocols created for this transport.</param>" << '\n'
2447+
<< indent() << "/// <param name=\"protocolFactory\">The factory used to create input and output protocols.</param>" << '\n'
2448+
<< indent() << "public Client(TTransport transport, TProtocolFactory protocolFactory) : this(transport, protocolFactory, protocolFactory)" << '\n'
2449+
<< indent() << "{" << '\n'
2450+
<< indent() << "}" << '\n'
2451+
<< '\n'
2452+
<< indent() << "/// <summary>" << '\n'
2453+
<< indent() << "/// Initializes a client that uses separate factories to create shared protocols and, when supported, per-call protocols." << '\n'
2454+
<< indent() << "/// </summary>" << '\n'
2455+
<< indent() << "/// <param name=\"transport\">The shared transport. The client owns protocols created for this transport.</param>" << '\n'
2456+
<< indent() << "/// <param name=\"inputProtocolFactory\">The factory used to create input protocols.</param>" << '\n'
2457+
<< indent() << "/// <param name=\"outputProtocolFactory\">The factory used to create output protocols.</param>" << '\n'
2458+
<< indent() << "/// <remarks>When the transport supports per-call transports, the factories create new protocols for each call.</remarks>" << '\n'
2459+
<< indent() << "public Client(TTransport transport, TProtocolFactory inputProtocolFactory, TProtocolFactory outputProtocolFactory)" << '\n'
2460+
<< indent() << " : base(transport, inputProtocolFactory, outputProtocolFactory)" << '\n'
2461+
<< indent() << "{" << '\n'
2462+
<< indent() << "}" << '\n'
2463+
<< '\n'
2464+
<< indent() << "/// <summary>" << '\n'
2465+
<< indent() << "/// Initializes a client with shared protocols and factories for per-call protocols when supported." << '\n'
2466+
<< indent() << "/// </summary>" << '\n'
2467+
<< indent() << "/// <param name=\"inputProtocol\">The shared input protocol owned by the client.</param>" << '\n'
2468+
<< indent() << "/// <param name=\"outputProtocol\">The shared output protocol owned by the client.</param>" << '\n'
2469+
<< indent() << "/// <param name=\"transport\">The shared transport used to provide per-call transports when supported.</param>" << '\n'
2470+
<< indent() << "/// <param name=\"inputProtocolFactory\">The factory used to create per-call input protocols.</param>" << '\n'
2471+
<< indent() << "/// <param name=\"outputProtocolFactory\">The factory used to create per-call output protocols.</param>" << '\n'
2472+
<< indent() << "public Client(TProtocol inputProtocol, TProtocol outputProtocol, TTransport transport, TProtocolFactory inputProtocolFactory, TProtocolFactory outputProtocolFactory)" << '\n'
2473+
<< indent() << " : base(inputProtocol, outputProtocol, transport, inputProtocolFactory, outputProtocolFactory)" << '\n'
2474+
<< indent() << "{" << '\n'
2475+
<< indent() << "}" << '\n'
24422476
<< '\n';
24432477

24442478
vector<t_function*> functions = tservice->get_functions();
@@ -2454,6 +2488,13 @@ void t_netstd_generator::generate_service_client(ostream& out, t_service* tservi
24542488
out << indent() << "public async " << function_signature_async(*functions_iterator, "") << '\n'
24552489
<< indent() << "{" << '\n';
24562490
indent_up();
2491+
out << indent()
2492+
<< (((!(*functions_iterator)->is_oneway()) && !(*functions_iterator)->get_returntype()->is_void())
2493+
? "return await "
2494+
: "await ")
2495+
<< "ExecutePerCallAsync(async () =>" << '\n'
2496+
<< indent() << "{" << '\n';
2497+
indent_up();
24572498
out << indent() << "await send_" << function_name << "(";
24582499
string call_args = argument_list((*functions_iterator)->get_arglist(),false);
24592500
if(! call_args.empty()) {
@@ -2465,6 +2506,8 @@ void t_netstd_generator::generate_service_client(ostream& out, t_service* tservi
24652506
<< "await recv_" << function_name << "(" << CANCELLATION_TOKEN_NAME << ");" << '\n';
24662507
}
24672508
indent_down();
2509+
out << indent() << "}, " << CANCELLATION_TOKEN_NAME << ");" << '\n';
2510+
indent_down();
24682511
out << indent() << "}" << '\n' << '\n';
24692512

24702513
// async send

0 commit comments

Comments
 (0)