Fix thrift_server to create transport and protocol inside the processor rather than inside the acceptor.

This fixes a process and file descriptor leak -- previously, the thrift_buffered_transport process was linked to the acceptor, which never died.


git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@666409 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/alterl/src/thrift_processor.erl b/lib/alterl/src/thrift_processor.erl
index 8e077b8..d89b91c 100644
--- a/lib/alterl/src/thrift_processor.erl
+++ b/lib/alterl/src/thrift_processor.erl
@@ -7,17 +7,18 @@
 %%%-------------------------------------------------------------------
 -module(thrift_processor).
 
--export([start/4,init/4]).
+-export([start/3,init/3]).
 
 -include("thrift_constants.hrl").
 -include("thrift_protocol.hrl").
 
 -record(state, {handler, in_protocol, out_protocol, service}).
 
-start(IProt, OProt, Service, Handler) ->
-    spawn(thrift_processor, init, [IProt, OProt, Service, Handler]).
+start(ProtocolGenerator, Service, Handler) when is_function(ProtocolGenerator, 0) ->
+    spawn(thrift_processor, init, [ProtocolGenerator, Service, Handler]).
 
-init(IProt, OProt, Service, Handler) ->
+init(ProtocolGenerator, Service, Handler) ->
+    {ok, IProt, OProt} = ProtocolGenerator(),
     io:format("Processor started~n"),
     loop(#state{in_protocol = IProt,
                 out_protocol = OProt,
diff --git a/lib/alterl/src/thrift_server.erl b/lib/alterl/src/thrift_server.erl
index e5c9cf9..a639eb0 100644
--- a/lib/alterl/src/thrift_server.erl
+++ b/lib/alterl/src/thrift_server.erl
@@ -120,11 +120,15 @@
     {ok, Socket} = gen_tcp:accept(ListenSocket),
     error_logger:info_msg("Accepted client"),
 
-    {ok, SocketTransport} = thrift_socket_transport:new(Socket),
-    {ok, BufferedTransport} = thrift_buffered_transport:new(SocketTransport),
-    {ok, Protocol} = thrift_binary_protocol:new(BufferedTransport),
 
-    thrift_processor:start(Protocol, Protocol, Service, Handler),
+    ProtoGen = fun() ->
+                       {ok, SocketTransport} = thrift_socket_transport:new(Socket),
+                       {ok, BufferedTransport} = thrift_buffered_transport:new(SocketTransport),
+                       {ok, Protocol} = thrift_binary_protocol:new(BufferedTransport),
+                       {ok, Protocol, Protocol}
+               end,
+
+    thrift_processor:start(ProtoGen, Service, Handler),
     receive
         refresh ->
             error_logger:info_msg("Acceptor refreshing~n"),