Просмотр исходного кода

Merge branch 'tnt-dev-master' into devel

Conflicts:
	src/pgsql_sock.erl
David N. Welton 11 лет назад
Родитель
Сommit
99840191f4
1 измененных файлов с 37 добавлено и 32 удалено
  1. 37 32
      src/pgsql_sock.erl

+ 37 - 32
src/pgsql_sock.erl

@@ -165,37 +165,42 @@ command({connect, Host, Username, Password, Opts}, State) ->
     Timeout = proplists:get_value(timeout, Opts, 5000),
     Port = proplists:get_value(port, Opts, 5432),
     SockOpts = [{active, false}, {packet, raw}, binary, {nodelay, true}],
-    {ok, Sock} = gen_tcp:connect(Host, Port, SockOpts, Timeout),
-
-    %% Increase the buffer size.  Following the recommendation in the inet man page:
-    %%
-    %%    It is recommended to have val(buffer) >=
-    %%    max(val(sndbuf),val(recbuf)).
-
-    {ok, [{recbuf, RecBufSize}, {sndbuf, SndBufSize}]} =
-        inet:getopts(Sock, [recbuf, sndbuf]),
-    inet:setopts(Sock, [{buffer, max(RecBufSize, SndBufSize)}]),
-
-    State2 = case proplists:get_value(ssl, Opts) of
-                 T when T == true; T == required ->
-                     start_ssl(Sock, T, Opts, State);
-                 _ ->
-                     State#state{mod  = gen_tcp, sock = Sock}
-             end,
-
-    Opts2 = ["user", 0, Username, 0],
-    case proplists:get_value(database, Opts, undefined) of
-        undefined -> Opts3 = Opts2;
-        Database  -> Opts3 = [Opts2 | ["database", 0, Database, 0]]
-    end,
-    send(State2, [<<196608:?int32>>, Opts3, 0]),
-    Async   = proplists:get_value(async, Opts, undefined),
-    setopts(State2, [{active, true}]),
-    put(username, Username),
-    put(password, Password),
-    {noreply,
-     State2#state{handler = auth,
-                  async = Async}};
+    case gen_tcp:connect(Host, Port, SockOpts, Timeout) of
+        {ok, Sock} ->
+
+            %% Increase the buffer size.  Following the recommendation in the inet man page:
+            %%
+            %%    It is recommended to have val(buffer) >=
+            %%    max(val(sndbuf),val(recbuf)).
+
+            {ok, [{recbuf, RecBufSize}, {sndbuf, SndBufSize}]} =
+                inet:getopts(Sock, [recbuf, sndbuf]),
+            inet:setopts(Sock, [{buffer, max(RecBufSize, SndBufSize)}]),
+
+            State2 = case proplists:get_value(ssl, Opts) of
+                         T when T == true; T == required ->
+                             start_ssl(Sock, T, Opts, State);
+                         _ ->
+                             State#state{mod  = gen_tcp, sock = Sock}
+                     end,
+
+            Opts2 = ["user", 0, Username, 0],
+            case proplists:get_value(database, Opts, undefined) of
+                undefined -> Opts3 = Opts2;
+                Database  -> Opts3 = [Opts2 | ["database", 0, Database, 0]]
+            end,
+            send(State2, [<<196608:?int32>>, Opts3, 0]),
+            Async   = proplists:get_value(async, Opts, undefined),
+            setopts(State2, [{active, true}]),
+            put(username, Username),
+            put(password, Password),
+            {noreply,
+             State2#state{handler = auth,
+                          async = Async}};
+
+        {error, _} = Error ->
+            {stop, normal, finish(State, Error)}
+    end;
 
 command({squery, Sql}, State) ->
     send(State, ?SIMPLEQUERY, [Sql, 0]),
@@ -577,7 +582,7 @@ on_message({?BIND_COMPLETE, <<>>}, State) ->
                  execute_batch ->
                      Batch =
                          case State#state.batch of
-                             [] -> 
+                             [] ->
                                  {_, {_, B}} = queue:get(State#state.queue),
                                  B;
                              B -> B