aboutsummaryrefslogtreecommitdiffstats
path: root/lib/ssl
diff options
context:
space:
mode:
authorIngela Anderton Andin <ingela@erlang.org>2012-12-03 16:16:06 +0100
committerBjörn-Egil Dahlberg <egil@erlang.org>2012-12-06 14:47:04 +0100
commitc433c9089e3aeff7c9ae04248e2ec0993b0b9e9f (patch)
tree90cec6d148b651b43b42985eddf422b35e7925bb /lib/ssl
parenta1bd47a9e8b562bdc8dca741bbd9e1bc4c0f9b2b (diff)
downloadotp-c433c9089e3aeff7c9ae04248e2ec0993b0b9e9f.tar.gz
otp-c433c9089e3aeff7c9ae04248e2ec0993b0b9e9f.tar.bz2
otp-c433c9089e3aeff7c9ae04248e2ec0993b0b9e9f.zip
ssl: Fix recv after timeout expired
Reset state so that "recv data" is not sent as "active data" after a recv timed out and no new recv has been called.
Diffstat (limited to 'lib/ssl')
-rw-r--r--lib/ssl/src/ssl_connection.erl11
-rw-r--r--lib/ssl/test/ssl_basic_SUITE.erl8
2 files changed, 15 insertions, 4 deletions
diff --git a/lib/ssl/src/ssl_connection.erl b/lib/ssl/src/ssl_connection.erl
index c5280d26f0..3849d240da 100644
--- a/lib/ssl/src/ssl_connection.erl
+++ b/lib/ssl/src/ssl_connection.erl
@@ -988,7 +988,8 @@ handle_info({cancel_start_or_recv, StartFrom}, StateName, #state{renegotiation =
handle_info({cancel_start_or_recv, RecvFrom}, StateName, #state{start_or_recv_from = RecvFrom} = State) ->
gen_fsm:reply(RecvFrom, {error, timeout}),
- {next_state, StateName, State#state{start_or_recv_from = undefined}, get_timeout(State)};
+ {next_state, StateName, State#state{start_or_recv_from = undefined,
+ bytes_to_read = undefined}, get_timeout(State)};
handle_info({cancel_start_or_recv, _RecvFrom}, StateName, State) ->
{next_state, StateName, State, get_timeout(State)};
@@ -1747,7 +1748,7 @@ read_application_data(Data, #state{user_application = {_Mon, Pid},
SocketOpt = deliver_app_data(SOpts, ClientData, Pid, RecvFrom),
State = State0#state{user_data_buffer = Buffer,
start_or_recv_from = undefined,
- bytes_to_read = 0,
+ bytes_to_read = undefined,
socket_options = SocketOpt
},
if
@@ -1760,6 +1761,8 @@ read_application_data(Data, #state{user_application = {_Mon, Pid},
end;
{more, Buffer} -> % no reply, we need more data
next_record(State0#state{user_data_buffer = Buffer});
+ {passive, Buffer} ->
+ next_record_if_active(State0#state{user_data_buffer = Buffer});
{error,_Reason} -> %% Invalid packet in packet mode
deliver_packet_error(SOpts, Buffer1, Pid, RecvFrom),
{stop, normal, State0}
@@ -1801,6 +1804,9 @@ is_time_to_renegotiate(_,_) ->
%% Picks ClientData
get_data(_, _, <<>>) ->
{more, <<>>};
+%% Recv timed out save buffer data until next recv
+get_data(#socket_options{active=false}, undefined, Buffer) ->
+ {passive, Buffer};
get_data(#socket_options{active=Active, packet=Raw}, BytesToRead, Buffer)
when Raw =:= raw; Raw =:= 0 -> %% Raw Mode
if
@@ -2106,7 +2112,6 @@ initial_state(Role, Host, Port, Socket, {SSLOptions, SocketOptions}, User,
tls_record_buffer = <<>>,
tls_cipher_texts = [],
user_application = {Monitor, User},
- bytes_to_read = 0,
user_data_buffer = <<>>,
log_alert = true,
session_cache_cb = SessionCacheCb,
diff --git a/lib/ssl/test/ssl_basic_SUITE.erl b/lib/ssl/test/ssl_basic_SUITE.erl
index 7689da7200..112ed85ec5 100644
--- a/lib/ssl/test/ssl_basic_SUITE.erl
+++ b/lib/ssl/test/ssl_basic_SUITE.erl
@@ -4080,7 +4080,13 @@ send_recv_result(Socket) ->
send_recv_result_timeout_client(Socket) ->
{error, timeout} = ssl:recv(Socket, 11, 500),
ssl:send(Socket, "Hello world"),
- {ok, "Hello world"} = ssl:recv(Socket, 11),
+ receive
+ Msg ->
+ io:format("Msg ~p~n",[Msg])
+ after 500 ->
+ ok
+ end,
+ {ok, "Hello world"} = ssl:recv(Socket, 11, 500),
ok.
send_recv_result_timeout_server(Socket) ->
ssl:send(Socket, "Hello"),