From: David Reiss Date: Thu, 2 Apr 2009 19:22:31 +0000 (+0000) Subject: THRIFT-388. Create a "ONEWAY" message type that is an alias for "CALL" X-Git-Tag: 0.2.0~173 X-Git-Url: https://source.supwisdom.com/gerrit/gitweb?a=commitdiff_plain;h=deda141392d0b242e1fce0c0682ceedb45642a18;p=common%2Fthrift.git THRIFT-388. Create a "ONEWAY" message type that is an alias for "CALL" Pave the way for a new message type for oneway function calls. For now, just define the constant in all languages and make server implementations treat it the same way as a normal call. Only C++ and Erlang currently check the message type (on the server side). There is a little bit of redundancy in the Erlang code, but the alternative is a bit gross, and this split-up will be necessary eventually when we start handling one-way calls differently. git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@761389 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/compiler/cpp/src/generate/t_cpp_generator.cc b/compiler/cpp/src/generate/t_cpp_generator.cc index 9d572697..00c813ef 100644 --- a/compiler/cpp/src/generate/t_cpp_generator.cc +++ b/compiler/cpp/src/generate/t_cpp_generator.cc @@ -1909,7 +1909,7 @@ void t_cpp_generator::generate_service_processor(t_service* tservice) { endl << indent() << "iprot->readMessageBegin(fname, mtype, seqid);" << endl << endl << - indent() << "if (mtype != apache::thrift::protocol::T_CALL) {" << endl << + indent() << "if (mtype != apache::thrift::protocol::T_CALL && mtype != apache::thrift::protocol::T_ONEWAY) {" << endl << indent() << " iprot->skip(apache::thrift::protocol::T_STRUCT);" << endl << indent() << " iprot->readMessageEnd();" << endl << indent() << " iprot->getTransport()->readEnd();" << endl << diff --git a/lib/cocoa/src/protocol/TProtocol.h b/lib/cocoa/src/protocol/TProtocol.h index 126f5df9..cc8cdb4b 100644 --- a/lib/cocoa/src/protocol/TProtocol.h +++ b/lib/cocoa/src/protocol/TProtocol.h @@ -25,7 +25,8 @@ enum { TMessageType_CALL = 1, TMessageType_REPLY = 2, - TMessageType_EXCEPTION = 3 + TMessageType_EXCEPTION = 3, + TMessageType_ONEWAY = 4 }; enum { diff --git a/lib/cpp/src/protocol/TProtocol.h b/lib/cpp/src/protocol/TProtocol.h index 37d08016..0c513d14 100644 --- a/lib/cpp/src/protocol/TProtocol.h +++ b/lib/cpp/src/protocol/TProtocol.h @@ -97,7 +97,8 @@ enum TType { enum TMessageType { T_CALL = 1, T_REPLY = 2, - T_EXCEPTION = 3 + T_EXCEPTION = 3, + T_ONEWAY = 4 }; /** diff --git a/lib/csharp/src/Protocol/TMessageType.cs b/lib/csharp/src/Protocol/TMessageType.cs index 42a6a205..ab07cf6c 100644 --- a/lib/csharp/src/Protocol/TMessageType.cs +++ b/lib/csharp/src/Protocol/TMessageType.cs @@ -25,6 +25,7 @@ namespace Thrift.Protocol { Call = 1, Reply = 2, - Exception = 3 + Exception = 3, + Oneway = 4 } } diff --git a/lib/erl/include/thrift_constants.hrl b/lib/erl/include/thrift_constants.hrl index 40c0c169..36eb49bf 100644 --- a/lib/erl/include/thrift_constants.hrl +++ b/lib/erl/include/thrift_constants.hrl @@ -36,6 +36,7 @@ -define(tMessageType_CALL, 1). -define(tMessageType_REPLY, 2). -define(tMessageType_EXCEPTION, 3). +-define(tMessageType_ONEWAY, 4). % TApplicationException -define(TApplicationException_Structure, diff --git a/lib/erl/src/thrift_processor.erl b/lib/erl/src/thrift_processor.erl index 1adea67c..e26fb330 100644 --- a/lib/erl/src/thrift_processor.erl +++ b/lib/erl/src/thrift_processor.erl @@ -40,6 +40,10 @@ loop(State = #thrift_processor{in_protocol = IProto, type = ?tMessageType_CALL} -> ok = handle_function(State, list_to_atom(Function)), loop(State); + #protocol_message_begin{name = Function, + type = ?tMessageType_ONEWAY} -> + ok = handle_function(State, list_to_atom(Function)), + loop(State); {error, timeout} -> thrift_protocol:close_transport(OProto), ok; diff --git a/lib/hs/src/Thrift.hs b/lib/hs/src/Thrift.hs index b3ce8a40..293edf15 100644 --- a/lib/hs/src/Thrift.hs +++ b/lib/hs/src/Thrift.hs @@ -118,6 +118,7 @@ module Thrift (TransportExn(..),TransportExn_Type(..),TTransport(..), T_type(..) data Message_type = M_CALL | M_REPLY | M_EXCEPTION + | M_ONEWAY | M_UNKNOWN deriving Eq instance Enum Message_type where @@ -126,12 +127,14 @@ module Thrift (TransportExn(..),TransportExn_Type(..),TTransport(..), T_type(..) M_CALL -> 1 M_REPLY -> 2 M_EXCEPTION -> 3 + M_ONEWAY -> 4 M_UNKNOWN -> -1 toEnum t = case t of 1 -> M_CALL 2 -> M_REPLY 3 -> M_EXCEPTION + 4 -> M_ONEWAY _ -> M_UNKNOWN diff --git a/lib/java/src/org/apache/thrift/protocol/TMessageType.java b/lib/java/src/org/apache/thrift/protocol/TMessageType.java index 714ea709..aa3f9317 100644 --- a/lib/java/src/org/apache/thrift/protocol/TMessageType.java +++ b/lib/java/src/org/apache/thrift/protocol/TMessageType.java @@ -27,4 +27,5 @@ public final class TMessageType { public static final byte CALL = 1; public static final byte REPLY = 2; public static final byte EXCEPTION = 3; + public static final byte ONEWAY = 4; } diff --git a/lib/ocaml/src/Thrift.ml b/lib/ocaml/src/Thrift.ml index 0d164704..8dc9afa3 100644 --- a/lib/ocaml/src/Thrift.ml +++ b/lib/ocaml/src/Thrift.ml @@ -141,16 +141,19 @@ struct | CALL | REPLY | EXCEPTION + | ONEWAY let message_type_to_i = function | CALL -> 1 | REPLY -> 2 | EXCEPTION -> 3 + | ONEWAY -> 4 let message_type_of_i = function | 1 -> CALL | 2 -> REPLY | 3 -> EXCEPTION + | 4 -> ONEWAY | _ -> raise Thrift_error class virtual t (trans: Transport.t) = diff --git a/lib/perl/lib/Thrift.pm b/lib/perl/lib/Thrift.pm index 2560df7e..fe0f8e72 100644 --- a/lib/perl/lib/Thrift.pm +++ b/lib/perl/lib/Thrift.pm @@ -53,6 +53,7 @@ package TMessageType; use constant CALL => 1; use constant REPLY => 2; use constant EXCEPTION => 3; +use constant ONEWAY => 4; 1; package Thrift::TException; diff --git a/lib/php/src/Thrift.php b/lib/php/src/Thrift.php index dd1e0d75..ef6ab8a4 100644 --- a/lib/php/src/Thrift.php +++ b/lib/php/src/Thrift.php @@ -51,6 +51,7 @@ class TMessageType { const CALL = 1; const REPLY = 2; const EXCEPTION = 3; + const ONEWAY = 4; } /** diff --git a/lib/py/src/Thrift.py b/lib/py/src/Thrift.py index 601b41cb..21d7aa4e 100644 --- a/lib/py/src/Thrift.py +++ b/lib/py/src/Thrift.py @@ -40,6 +40,7 @@ class TMessageType: CALL = 1 REPLY = 2 EXCEPTION = 3 + ONEWAY = 4 class TProcessor: diff --git a/lib/rb/lib/thrift/types.rb b/lib/rb/lib/thrift/types.rb index 6d70eb58..20e4ca2c 100644 --- a/lib/rb/lib/thrift/types.rb +++ b/lib/rb/lib/thrift/types.rb @@ -94,6 +94,7 @@ module Thrift CALL = 1 REPLY = 2 EXCEPTION = 3 + ONEWAY = 4 end end