[thrift] preliminary Erlang support (initial import)
Summary:
* missing {list,map,set}s, inheritance is spotty
* loose source code, plus everything is one process (application / gen_server behavior is forthcoming)
* codegen is a mess, need t_fp_generator
Test Plan:
* codegen invoked without -erl generates identical code for test/
* calculatorHandler plus 'thrift -erl -r tutorial.thrift' more or less works
Revert Plan: ok
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665146 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/erl/src-loose/server/tServer.erl b/lib/erl/src-loose/server/tServer.erl
new file mode 100644
index 0000000..0c3182e
--- /dev/null
+++ b/lib/erl/src-loose/server/tServer.erl
@@ -0,0 +1,62 @@
+-module(tServer).
+
+-include("thrift/thrift.hrl").
+-include("thrift/protocol/tProtocol.hrl").
+-include("thrift/protocol/tBinaryProtocol.hrl").
+% -include("thrift/transport/tTransport.hrl").
+-include("tServer.hrl").
+
+-export([new/3, serve/1]).
+
+% now processor is the module with process_*, not an object
+
+new(ProcessorModule, HandlerModule, ServerTransport) ->
+ #tServer{processorModule=ProcessorModule,
+ handlerModule=HandlerModule,
+ serverTransport=ServerTransport}.
+
+serverTransport(This) ->
+ This#tServer.serverTransport.
+
+serve(This) ->
+ ST1 = ?M0(serverTransport(This), listen_MUTABLE),
+ This1 = This#tServer{serverTransport=ST1},
+ serve_loop(This1).
+
+processorModule(This) ->
+ This#tServer.processorModule.
+
+handlerModule(This) ->
+ This#tServer.handlerModule.
+
+serve_loop(This) ->
+ io:format("~nready.~n", []),
+ Client = ?M0(serverTransport(This), accept_MUTABLE),
+ This1 = This#tServer{serverTransport=Client},
+
+ Trans = Client, % factory
+ Prot = tBinaryProtocol:new(Trans),
+ serve_loop_loop(This1, Prot), % giggle loop?
+ ?M0(Trans, close_MUTABLE), % don't "assign" ... discard
+ serve_loop(This).
+
+serve_loop_loop(This, Prot) ->
+ Next = try
+ Val = (processorModule(This)):process(handlerModule(This), Prot, Prot),
+ io:format("request processed: rv=~p~n", [Val]),
+ loop
+ catch
+ %% TODO(cpiro) case when is_record(...) to pick out our exception
+ %% records vs. normal erlang throws
+ {tTransportException,_,_} ->
+ io:format("tTransportException (normal-ish?)~n", []),
+ close;
+ E ->
+ io:format("EXCEPTION: ~p~n", [E]),
+ close
+ end,
+ case Next of
+ loop -> serve_loop_loop(This, Prot);
+ close -> ok
+ end.
+
diff --git a/lib/erl/src-loose/server/tServer.hrl b/lib/erl/src-loose/server/tServer.hrl
new file mode 100644
index 0000000..23da029
--- /dev/null
+++ b/lib/erl/src-loose/server/tServer.hrl
@@ -0,0 +1 @@
+-record(tServer, {processorModule, handlerModule, serverTransport}).