[thrift] Erlang client receive socket options

Summary: we want {active, false}, etc. for client sockets.  make it so.

Reviewed By: eletuchy

Test Plan: ok

Revert Plan: ok


git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665337 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/erl/src/transport/tSocket.erl b/lib/erl/src/transport/tSocket.erl
index c438203..f002fd8 100644
--- a/lib/erl/src/transport/tSocket.erl
+++ b/lib/erl/src/transport/tSocket.erl
@@ -1,6 +1,6 @@
 %%% Copyright (c) 2007- Facebook
 %%% Distributed under the Thrift Software License
-%%% 
+%%%
 %%% See accompanying file LICENSE or visit the Thrift site at:
 %%% http://developers.facebook.com/thrift/
 
@@ -10,7 +10,6 @@
 
 -include("thrift.hrl").
 -include("transport/tTransportException.hrl").
-% -include("transport/tTransport.hrl").
 -include("transport/tSocket.hrl").
 
 -behavior(oop).
@@ -18,8 +17,8 @@
 -export([attr/4, super/0, inspect/1]).
 
 -export([new/0, new/1, new/2,
-	 effectful_setHandle/2, effectful_open/1,
-	 isOpen/1, effectful_write/2, read/2, effectful_close/1]).
+         effectful_setHandle/2, effectful_open/1,
+         isOpen/1, effectful_write/2, read/2, effectful_close/1]).
 
 %%%
 %%% define attributes
@@ -30,11 +29,11 @@
 ?DEFINE_ATTR(host);
 ?DEFINE_ATTR(port);
 ?DEFINE_ATTR(handle).
-   
+
 %%%
 %%% behavior callbacks
 %%%
- 
+
 %%% super() -> SuperModule = atom()
 %%%             |  none
 
@@ -61,7 +60,7 @@
 
 new() ->
     new("localhost", 9090).
-    
+
 %%%
 %%% instance methods
 %%%
@@ -69,19 +68,19 @@
 effectful_setHandle(This, Handle) ->
     {ok, oop:set(This, handle, Handle)}.
 
-effectful_open(This) -> 
+effectful_open(This) ->
     Host = oop:get(This, host),
     Port = oop:get(This, port),
-    Options = [],
+    Options = [binary, {packet, 0}, {active, false}],
 
     case gen_tcp:connect(Host, Port, Options) of
-	{error, _} ->
-	    exit(tTransportException:new(
-		   ?tTransportException_NOT_OPEN,
-		   "Could not connect to " ++ Host ++ ":" ++ Port)
-		 );
-	{ok, Socket} ->
-	    {ok, oop:set(This, handle, Socket)}
+        {error, _} ->
+            exit(tTransportException:new(
+                   ?tTransportException_NOT_OPEN,
+                   "Could not connect to " ++ Host ++ ":" ++ Port)
+                );
+        {ok, Socket} ->
+            effectful_setHandle(This, Socket)
     end.
 
 isOpen(This) ->
@@ -95,34 +94,34 @@
     %% error_logger:info_msg("tSocket: wrote ~p~n", [Str]),
 
     %% error_logger:info_msg("WRITE |~p| (~p)", [Str,Val]),
-    
+
     case Val of
-	{error, _} ->
-	    throw(tTransportException:new(?tTransportException_NOT_OPEN, "in write"));
-	ok ->
-	    {ok, This}
+        {error, _} ->
+            throw(tTransportException:new(?tTransportException_NOT_OPEN, "in write"));
+        ok ->
+            {ok, This}
     end.
 
 read(This, Sz) ->
     Handle = oop:get(This, handle),
     case gen_tcp:recv(Handle, Sz) of
-	{ok, []} ->
-	    Host = oop:get(This, host),
-	    Port = oop:get(This, port),
-	    throw(tTransportException:new(?tTransportException_UNKNOWN, "TSocket: Could not read " ++ Sz ++ "bytes from " ++ Host ++ ":" ++ Port));
-	{ok, Data} ->
-	    %% DEBUG
-	    %% io:format("tSocket: read ~p~n", [Data]),
-	    Data;
-	{error, Error} ->
-	    exit(tTransportException:new(?tTransportException_NOT_OPEN, "in tSocket:read/2: gen_tcp:recv"))
-	end.
-	    
+        {ok, []} ->
+            Host = oop:get(This, host),
+            Port = oop:get(This, port),
+            throw(tTransportException:new(?tTransportException_UNKNOWN, "TSocket: Could not read " ++ Sz ++ "bytes from " ++ Host ++ ":" ++ Port));
+        {ok, Data} ->
+            %% DEBUG
+            ?INFO("tSocket: read ~p", [Data]),
+            Data;
+        {error, Error} ->
+            exit(tTransportException:new(?tTransportException_NOT_OPEN, "in tSocket:read/2: gen_tcp:recv"))
+    end.
+
 effectful_close(This) ->
     case oop:get(This, handle) of
-	nil ->
-	    {ok, This};
-	Handle -> 
-	    gen_tcp:close(Handle),
-	    {ok, oop:set(This, handle, nil)}
+        nil ->
+            {ok, This};
+        Handle ->
+            gen_tcp:close(Handle),
+            {ok, oop:set(This, handle, nil)}
     end.