Permalink
Browse files

Remove debug messages + bug fix

  • Loading branch information...
1 parent 41f5ba0 commit 114f3abe4d7c5a9527bb9d52dbf88d552a417bab @lpgauth lpgauth committed Jul 19, 2011
Showing with 11 additions and 35 deletions.
  1. +5 −7 src/lhttpc_client.erl
  2. +5 −16 src/lhttpc_lb.erl
  3. +1 −12 src/lhttpc_sock.erl
View
12 src/lhttpc_client.erl
@@ -255,7 +255,7 @@ read_response(State, Vsn, {StatusCode, _} = Status, Hdrs) ->
Response = handle_response_body(State, Vsn, Status, Hdrs),
NewHdrs = element(2, Response),
ReqHdrs = State#client_state.request_headers,
- NewSocket = maybe_close_socket(Socket, Ssl, Vsn, ReqHdrs, NewHdrs),
+ NewSocket = maybe_close_socket(Lb, Socket, Vsn, ReqHdrs, NewHdrs),
{Response, NewSocket};
{error, closed} ->
% Either we only noticed that the socket was closed after we
@@ -612,24 +612,22 @@ read_until_closed(Socket, Acc, Hdrs, Ssl) ->
erlang:error(Reason)
end.
-maybe_close_socket(Socket, Ssl, {1, Minor}, ReqHdrs, RespHdrs) when Minor >= 1->
+maybe_close_socket(Lb, Socket, {1, Minor}, ReqHdrs, RespHdrs) when Minor >= 1->
ClientConnection = ?CONNECTION_HDR(ReqHdrs, "keep-alive"),
ServerConnection = ?CONNECTION_HDR(RespHdrs, "keep-alive"),
if
ClientConnection =:= "close"; ServerConnection =:= "close" ->
- error_logger:error_report("close"),
- lhttpc_sock:close(Socket, Ssl),
+ gen_server:cast(Lb, {remove, Socket}),
undefined;
ClientConnection =/= "close", ServerConnection =/= "close" ->
Socket
end;
-maybe_close_socket(Socket, Ssl, _, ReqHdrs, RespHdrs) ->
+maybe_close_socket(Lb, Socket, _, ReqHdrs, RespHdrs) ->
ClientConnection = ?CONNECTION_HDR(ReqHdrs, "keep-alive"),
ServerConnection = ?CONNECTION_HDR(RespHdrs, "close"),
if
ClientConnection =:= "close"; ServerConnection =/= "keep-alive" ->
- error_logger:error_report("close"),
- lhttpc_sock:close(Socket, Ssl),
+ gen_server:cast(Lb, {remove, Socket}),
undefined;
ClientConnection =/= "close", ServerConnection =:= "keep-alive" ->
Socket
View
21 src/lhttpc_lb.erl
@@ -21,10 +21,10 @@
sockets = dict:new(),
idle_sockets = queue:new(),
timeout = 1000000 :: non_neg_integer(),
- max_sockets = 1 :: non_neg_integer()
+ max_sockets = 10 :: non_neg_integer()
}).
-%% @spec () -> {ok, pid()}
+%% @spec (any()) -> {ok, pid()}
%% @doc Starts and link to the gen server.
%% This is normally called by a supervisor.
%% @end
@@ -49,22 +49,19 @@ init({Host, Port, Ssl}) ->
-spec handle_call(any(), any(), #httpc_man{}) ->
{reply, any(), #httpc_man{}}.
handle_call({socket, Pid, ConnectOptions}, _, State) ->
- error_logger:error_report(find),
{Reply, NewState} = find_socket(Pid, ConnectOptions, State),
{reply, Reply, NewState};
handle_call(_, _, State) ->
{reply, {error, unknown_request}, State}.
%% @hidden
-spec handle_cast(any(), #httpc_man{}) -> {noreply, #httpc_man{}}.
-handle_cast({remove, Socket}, State) ->
- error_logger:error_report(remove),
- NewState = remove_socket(Socket, State),
- {noreply, NewState};
handle_cast({store, Socket}, State) ->
- error_logger:error_report(store),
NewState = store_socket(Socket, State),
{noreply, NewState};
+handle_cast({remove, Socket}, State) ->
+ NewState = remove_socket(Socket, State),
+ {noreply, NewState};
handle_cast({terminate}, State) ->
terminate(undefined, State),
{noreply, State};
@@ -76,28 +73,20 @@ handle_cast(_, State) ->
%% @hidden
-spec handle_info(any(), #httpc_man{}) -> {noreply, #httpc_man{}}.
handle_info({tcp_closed, Socket}, State) ->
- error_logger:error_report(tcp_closed),
{noreply, remove_socket(Socket, State)};
handle_info({ssl_closed, Socket}, State) ->
- error_logger:error_report(ssl_closed),
{noreply, remove_socket(Socket, State)};
handle_info({timeout, Socket}, State) ->
- error_logger:error_report(timeout),
{noreply, remove_socket(Socket, State)};
handle_info({tcp_error, Socket, _}, State) ->
- error_logger:error_report(tcp_error),
{noreply, remove_socket(Socket, State)};
handle_info({ssl_error, Socket, _}, State) ->
- error_logger:error_report(ssl_error),
{noreply, remove_socket(Socket, State)};
handle_info({tcp, Socket, _}, State) ->
- error_logger:error_report(tcp),
{noreply, remove_socket(Socket, State)}; % got garbage
handle_info({ssl, Socket, _}, State) ->
- error_logger:error_report(ssl),
{noreply, remove_socket(Socket, State)}; % got garbage
handle_info(_, State) ->
- error_logger:error_report(other),
{noreply, State}.
%% @hidden
View
13 src/lhttpc_sock.erl
@@ -63,7 +63,6 @@
connect(Host, Port, Options, Timeout, true) ->
ssl:connect(Host, Port, Options, Timeout);
connect(Host, Port, Options, Timeout, false) ->
- error_logger:error_report([connect, Host, Port, Options, Timeout]),
gen_tcp:connect(Host, Port, Options, Timeout).
%% @spec (Socket, SslFlag) -> {ok, Data} | {error, Reason}
@@ -82,11 +81,7 @@ connect(Host, Port, Options, Timeout, false) ->
recv(Socket, true) ->
ssl:recv(Socket, 0);
recv(Socket, false) ->
- % error_logger:error_report([recv, Socket]),
- % error_logger:error_report([inet_db, inet_db:lookup_socket(Socket)]),
- X = inet_tcp:recv(Socket, 0),
- error_logger:error_report(X),
- X.
+ inet_tcp:recv(Socket, 0).
%% @spec (Socket, Length, SslFlag) -> {ok, Data} | {error, Reason}
%% Socket = socket()
@@ -104,7 +99,6 @@ recv(_, 0, _) ->
recv(Socket, Length, true) ->
ssl:recv(Socket, Length);
recv(Socket, Length, false) ->
- error_logger:error_report([rcv, Socket, Length]),
gen_tcp:recv(Socket, Length).
%% @spec (Socket, Data, SslFlag) -> ok | {error, Reason}
@@ -121,7 +115,6 @@ recv(Socket, Length, false) ->
send(Socket, Request, true) ->
ssl:send(Socket, Request);
send(Socket, Request, false) ->
- error_logger:error_report([send, Socket, Request]),
gen_tcp:send(Socket, Request).
%% @spec (Socket, Pid, SslFlag) -> ok | {error, Reason}
@@ -137,8 +130,6 @@ send(Socket, Request, false) ->
controlling_process(Socket, Pid, true) ->
ssl:controlling_process(Socket, Pid);
controlling_process(Socket, Pid, false) ->
- error_logger:error_report([controlling_process, Socket, Pid]),
- error_logger:error_report(process_info(Pid)),
gen_tcp:controlling_process(Socket, Pid).
%% @spec (Socket, Options, SslFlag) -> ok | {error, Reason}
@@ -154,7 +145,6 @@ controlling_process(Socket, Pid, false) ->
setopts(Socket, Options, true) ->
ssl:setopts(Socket, Options);
setopts(Socket, Options, false) ->
- error_logger:error_report([setopts, Socket, Options]),
inet:setopts(Socket, Options).
%% @spec (Socket, SslFlag) -> ok | {error, Reason}
@@ -168,5 +158,4 @@ setopts(Socket, Options, false) ->
close(Socket, true) ->
ssl:close(Socket);
close(Socket, false) ->
- error_logger:error_report([close, socket]),
gen_tcp:close(Socket).

0 comments on commit 114f3ab

Please sign in to comment.