fix
This commit is contained in:
parent
e886dce82d
commit
836917c733
@ -5,7 +5,7 @@
|
||||
{mod, {efka_app, []}},
|
||||
{applications,
|
||||
[
|
||||
% sync,
|
||||
sync,
|
||||
hackney,
|
||||
lager,
|
||||
esockd,
|
||||
|
||||
@ -22,7 +22,7 @@
|
||||
-record(state, {
|
||||
host :: string(),
|
||||
port :: integer(),
|
||||
socket
|
||||
socket :: undefined | ssl:sslsocket()
|
||||
}).
|
||||
|
||||
%%%===================================================================
|
||||
@ -84,6 +84,8 @@ handle_cast(_Request, State = #state{}) ->
|
||||
handle_info({timeout, _, create_connection}, State = #state{host = Host, port = Port}) ->
|
||||
case connect(Host, Port) of
|
||||
{ok, Socket} ->
|
||||
ok = ssl:send(Socket, <<"hello world">>),
|
||||
lager:debug("[efka_agent] connected success"),
|
||||
{noreply, State#state{socket = Socket}};
|
||||
{error, Reason} ->
|
||||
lager:debug("[efka_agent] create_connection get error: ~p", [Reason]),
|
||||
@ -93,7 +95,6 @@ handle_info({timeout, _, create_connection}, State = #state{host = Host, port =
|
||||
|
||||
handle_info({ssl, Socket, Data}, State = #state{socket = Socket}) ->
|
||||
lager:debug("[efka_agent] socket get message: ~p", [Data]),
|
||||
retry_connect(),
|
||||
{noreply, State#state{socket = undefined}};
|
||||
|
||||
handle_info({ssl_error, Socket, Reason}, State = #state{socket = Socket}) ->
|
||||
@ -133,9 +134,11 @@ code_change(_OldVsn, State = #state{}, _Extra) ->
|
||||
retry_connect() ->
|
||||
erlang:start_timer(5000, self(), create_connection).
|
||||
|
||||
-spec connect(Host :: string(), Port :: integer()) -> {ok, Socket :: ssl:sslsocket()} | {error, Reason :: any()}.
|
||||
connect(Host, Port) when is_list(Host), is_integer(Port) ->
|
||||
SslOptions = [
|
||||
{verify, verify_none},
|
||||
{active, true}
|
||||
{packet, 4},
|
||||
{active, true},
|
||||
{verify, verify_none}
|
||||
],
|
||||
ssl:connect(Host, Port, SslOptions, 5000).
|
||||
@ -4,7 +4,7 @@
|
||||
|
||||
{tls_server, [
|
||||
{host, "localhost"},
|
||||
{port, 18080}
|
||||
{port, 443}
|
||||
]}
|
||||
]},
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user