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