You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by dr...@apache.org on 2008/06/11 03:01:56 UTC

svn commit: r666448 - in /incubator/thrift/trunk/lib/alterl/src: thrift_client.erl thrift_framed_transport.erl

Author: dreiss
Date: Tue Jun 10 18:01:56 2008
New Revision: 666448

URL: http://svn.apache.org/viewvc?rev=666448&view=rev
Log:
erlang thrift_client will return {stop, Error} in start_link on a gen_tcp:connect error rather than exiting

Modified:
    incubator/thrift/trunk/lib/alterl/src/thrift_client.erl
    incubator/thrift/trunk/lib/alterl/src/thrift_framed_transport.erl

Modified: incubator/thrift/trunk/lib/alterl/src/thrift_client.erl
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/alterl/src/thrift_client.erl?rev=666448&r1=666447&r2=666448&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/alterl/src/thrift_client.erl (original)
+++ incubator/thrift/trunk/lib/alterl/src/thrift_client.erl Tue Jun 10 18:01:56 2008
@@ -65,27 +65,30 @@
 init([Host, Port, Service, Options]) ->
     State = parse_options(Options, #state{}),
 
-    {ok, Sock} = gen_tcp:connect(Host, Port,
-                                 [binary,
-                                  {packet, 0},
-                                  {active, false},
-                                  {nodelay, true}
-                                 ],
-                                State#state.connect_timeout),
-
-    {ok, Transport} = thrift_socket_transport:new(Sock),
-    {ok, BufTransport} =
-        case State#state.framed of
-            true  -> thrift_framed_transport:new(Transport);
-            false -> thrift_buffered_transport:new(Transport)
-        end,
-    {ok, Protocol} = thrift_binary_protocol:new(BufTransport,
-                         [{strict_read,  State#state.strict_read},
-                          {strict_write, State#state.strict_write}]),
-
-    {ok, State#state{service  = Service,
-                     protocol = Protocol,
-                     seqid    = 0}}.
+    TcpOptions = [binary,
+                  {packet, 0},
+                  {active, false},
+                  {nodelay, true}],
+    TcpTimeout = State#state.connect_timeout,
+
+    case gen_tcp:connect(Host, Port, TcpOptions, TcpTimeout) of
+        {ok, Sock} ->
+            {ok, Transport} = thrift_socket_transport:new(Sock),
+            {ok, BufTransport} =
+                case State#state.framed of
+                    true  -> thrift_framed_transport:new(Transport);
+                    false -> thrift_buffered_transport:new(Transport)
+                end,
+            {ok, Protocol} = thrift_binary_protocol:new(BufTransport,
+                                 [{strict_read,  State#state.strict_read},
+                                  {strict_write, State#state.strict_write}]),
+
+            {ok, State#state{service  = Service,
+                             protocol = Protocol,
+                             seqid    = 0}};
+        Error ->
+            {stop, Error}
+    end.
 
 parse_options([], State) ->
     State;

Modified: incubator/thrift/trunk/lib/alterl/src/thrift_framed_transport.erl
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/alterl/src/thrift_framed_transport.erl?rev=666448&r1=666447&r2=666448&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/alterl/src/thrift_framed_transport.erl (original)
+++ incubator/thrift/trunk/lib/alterl/src/thrift_framed_transport.erl Tue Jun 10 18:01:56 2008
@@ -119,7 +119,7 @@
                 %% then read the data
                 {ok, Bin} =
                     thrift_transport:read(Wrapped, FrameLen),
-                {Bin, size(Bin)};
+                {Bin, erlang:byte_size(Bin)};
             Sz ->
                 {RBuf, Sz}
         end,