Skip to content

Commit

Permalink
Make lhttpc_client check the return value from lhttpc_sock:setopts, i…
Browse files Browse the repository at this point in the history
…f setopts returns an error, we can't use the socket...
  • Loading branch information
oscarh committed Sep 7, 2011
1 parent 679b5f1 commit 6f7c563
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/lhttpc_client.erl
Expand Up @@ -244,7 +244,7 @@ check_send_result(#client_state{socket = Sock, ssl = Ssl}, {error, Reason}) ->
throw(Reason).

read_response(#client_state{socket = Socket, ssl = Ssl} = State) ->
lhttpc_sock:setopts(Socket, [{packet, http}], Ssl),
ok = lhttpc_sock:setopts(Socket, [{packet, http}], Ssl),
read_response(State, nil, {nil, nil}, []).

read_response(State, Vsn, {StatusCode, _} = Status, Hdrs) ->
Expand All @@ -266,7 +266,7 @@ read_response(State, Vsn, {StatusCode, _} = Status, Hdrs) ->
% status responses MAY be ignored by a user agent.
read_response(State, nil, {nil, nil}, []);
{ok, http_eoh} ->
lhttpc_sock:setopts(Socket, [{packet, raw}], Ssl),
ok = lhttpc_sock:setopts(Socket, [{packet, raw}], Ssl),
Response = handle_response_body(State, Vsn, Status, Hdrs),
NewHdrs = element(2, Response),
ReqHdrs = State#client_state.request_headers,
Expand Down Expand Up @@ -474,7 +474,7 @@ read_partial_chunked_body(State, Hdrs, Window, BufferSize, Buffer, RemSize) ->
end.

read_chunk_size(Socket, Ssl) ->
lhttpc_sock:setopts(Socket, [{packet, line}], Ssl),
ok = lhttpc_sock:setopts(Socket, [{packet, line}], Ssl),
case lhttpc_sock:recv(Socket, Ssl) of
{ok, ChunkSizeExt} ->
chunk_size(ChunkSizeExt);
Expand Down Expand Up @@ -527,7 +527,7 @@ chunk_size(<<Char, Binary/binary>>, Chars) ->
read_partial_chunk(Socket, Ssl, ChunkSize, ChunkSize) ->
{read_chunk(Socket, Ssl, ChunkSize), 0};
read_partial_chunk(Socket, Ssl, Size, ChunkSize) ->
lhttpc_sock:setopts(Socket, [{packet, raw}], Ssl),
ok = lhttpc_sock:setopts(Socket, [{packet, raw}], Ssl),
case lhttpc_sock:recv(Socket, Size, Ssl) of
{ok, Chunk} ->
{Chunk, ChunkSize - Size};
Expand All @@ -536,7 +536,7 @@ read_partial_chunk(Socket, Ssl, Size, ChunkSize) ->
end.

read_chunk(Socket, Ssl, Size) ->
lhttpc_sock:setopts(Socket, [{packet, raw}], Ssl),
ok = lhttpc_sock:setopts(Socket, [{packet, raw}], Ssl),
case lhttpc_sock:recv(Socket, Size + 2, Ssl) of
{ok, <<Chunk:Size/binary, "\r\n">>} ->
Chunk;
Expand All @@ -547,7 +547,7 @@ read_chunk(Socket, Ssl, Size) ->
end.

read_trailers(Socket, Ssl, Trailers, Hdrs) ->
lhttpc_sock:setopts(Socket, [{packet, httph}], Ssl),
ok = lhttpc_sock:setopts(Socket, [{packet, httph}], Ssl),
case lhttpc_sock:recv(Socket, Ssl) of
{ok, http_eoh} ->
{Trailers, Hdrs};
Expand Down

0 comments on commit 6f7c563

Please sign in to comment.