This is an automated email from the ASF dual-hosted git repository. jensg pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/thrift.git
commit 6228b907e0a01659515e8e4715c70f540fe07589 Author: Jens Geyer <[email protected]> AuthorDate: Fri Apr 9 22:55:11 2021 +0200 THRIFT-5395 inconsistent treatment of methods ending in "Async" Client: netstd Patch: Jens Geyer This closes #2372 --- .../cpp/src/thrift/generate/t_netstd_generator.cc | 25 ++++++---------------- .../Impl/Thrift5253/MyService.cs | 10 +++++++++ .../Thrift5253.thrift | 4 ++++ 3 files changed, 21 insertions(+), 18 deletions(-) diff --git a/compiler/cpp/src/thrift/generate/t_netstd_generator.cc b/compiler/cpp/src/thrift/generate/t_netstd_generator.cc index ed766ee..8b1c4c4 100644 --- a/compiler/cpp/src/thrift/generate/t_netstd_generator.cc +++ b/compiler/cpp/src/thrift/generate/t_netstd_generator.cc @@ -88,18 +88,6 @@ t_netstd_generator::t_netstd_generator(t_program* program, const map<string, str out_dir_base_ = "gen-netstd"; } -static string correct_function_name_for_async(string const& function_name) -{ - string const async_end = "Async"; - size_t i = function_name.find(async_end); - if (i != string::npos) - { - return function_name + async_end; - } - - return function_name; -} - /** * \brief Search and replace "_args" substring in struct name if exist (for C# class naming) * \param struct_name @@ -2011,7 +1999,8 @@ void t_netstd_generator::generate_service_client(ostream& out, t_service* tservi for (functions_iterator = functions.begin(); functions_iterator != functions.end(); ++functions_iterator) { - string function_name = correct_function_name_for_async((*functions_iterator)->get_name()); + string raw_func_name = (*functions_iterator)->get_name(); + string function_name = raw_func_name + "Async"; // async out << indent() << "public async " << function_signature_async(*functions_iterator, "") << endl @@ -2020,7 +2009,7 @@ void t_netstd_generator::generate_service_client(ostream& out, t_service* tservi string argsname = (*functions_iterator)->get_name() + "Args"; - out << indent() << "await OutputProtocol.WriteMessageBeginAsync(new TMessage(\"" << function_name + out << indent() << "await OutputProtocol.WriteMessageBeginAsync(new TMessage(\"" << raw_func_name << "\", TMessageType." << ((*functions_iterator)->is_oneway() ? "Oneway" : "Call") << ", SeqId), cancellationToken);" << endl << indent() << endl @@ -2155,8 +2144,8 @@ void t_netstd_generator::generate_service_server(ostream& out, t_service* tservi out << indent() << "_logger = logger;" << endl; for (f_iter = functions.begin(); f_iter != functions.end(); ++f_iter) { - string function_name = (*f_iter)->get_name(); - out << indent() << "processMap_[\"" << correct_function_name_for_async(function_name) << "\"] = " << function_name << "_ProcessAsync;" << endl; + string raw_func_name = (*f_iter)->get_name(); + out << indent() << "processMap_[\"" << raw_func_name << "\"] = " << raw_func_name << "_ProcessAsync;" << endl; } indent_down(); @@ -2370,7 +2359,7 @@ void t_netstd_generator::generate_process_function_async(ostream& out, t_service if (!tfunction->is_oneway()) { out << indent() << "await oprot.WriteMessageBeginAsync(new TMessage(\"" - << correct_function_name_for_async(tfunction->get_name()) << "\", TMessageType.Reply, seqid), cancellationToken); " << endl + << tfunction->get_name() << "\", TMessageType.Reply, seqid), cancellationToken); " << endl << indent() << "await result.WriteAsync(oprot, cancellationToken);" << endl; } indent_down(); @@ -2404,7 +2393,7 @@ void t_netstd_generator::generate_process_function_async(ostream& out, t_service else { out << indent() << "var x = new TApplicationException(TApplicationException.ExceptionType.InternalError,\" Internal error.\");" << endl - << indent() << "await oprot.WriteMessageBeginAsync(new TMessage(\"" << correct_function_name_for_async(tfunction->get_name()) + << indent() << "await oprot.WriteMessageBeginAsync(new TMessage(\"" << tfunction->get_name() << "\", TMessageType.Exception, seqid), cancellationToken);" << endl << indent() << "await x.WriteAsync(oprot, cancellationToken);" << endl; indent_down(); diff --git a/lib/netstd/Tests/Thrift.PublicInterfaces.Compile.Tests/Impl/Thrift5253/MyService.cs b/lib/netstd/Tests/Thrift.PublicInterfaces.Compile.Tests/Impl/Thrift5253/MyService.cs index 342dd4a..1b8d99f 100644 --- a/lib/netstd/Tests/Thrift.PublicInterfaces.Compile.Tests/Impl/Thrift5253/MyService.cs +++ b/lib/netstd/Tests/Thrift.PublicInterfaces.Compile.Tests/Impl/Thrift5253/MyService.cs @@ -51,6 +51,16 @@ namespace Thrift.PublicInterfaces.Compile.Tests.Impl.Thrift5253 return Task.FromResult(new InternalStructs() { Foo = input.Foo }); } + public Task TestAsyncAsync(CancellationToken cancellationToken = default) + { + return Task.CompletedTask; + } + + public Task TestXsyncAsync(CancellationToken cancellationToken = default) + { + return Task.CompletedTask; + } + public Task<WorksRslt> WorksAsync(WorksArrrgs input, CancellationToken cancellationToken = default) { return Task.FromResult(new WorksRslt() { Foo = input.Foo }); diff --git a/lib/netstd/Tests/Thrift.PublicInterfaces.Compile.Tests/Thrift5253.thrift b/lib/netstd/Tests/Thrift.PublicInterfaces.Compile.Tests/Thrift5253.thrift index ee3df9b..224ac85 100644 --- a/lib/netstd/Tests/Thrift.PublicInterfaces.Compile.Tests/Thrift5253.thrift +++ b/lib/netstd/Tests/Thrift.PublicInterfaces.Compile.Tests/Thrift5253.thrift @@ -42,5 +42,9 @@ service MyService{ AsyncProcessor AsyncProcessor ( 1: AsyncProcessor foo) Client Client ( 1: Client foo) IAsync IAsync ( 1: IAsync foo) + + // inconsistent treatment of methods ending in "Async" + void TestXsync() + void TestAsync() }
