fix
This commit is contained in:
parent
d1e51d635d
commit
c24007efc3
@ -17,6 +17,8 @@ start(_StartType, _StartArgs) ->
|
|||||||
%% 启动mnesia数据库
|
%% 启动mnesia数据库
|
||||||
start_mnesia(),
|
start_mnesia(),
|
||||||
|
|
||||||
|
start_http_server(),
|
||||||
|
|
||||||
start_tcp_server(),
|
start_tcp_server(),
|
||||||
|
|
||||||
iot_sup:start_link().
|
iot_sup:start_link().
|
||||||
@ -26,6 +28,33 @@ stop(_State) ->
|
|||||||
|
|
||||||
%% internal functions
|
%% internal functions
|
||||||
|
|
||||||
|
%% 启动http服务
|
||||||
|
start_http_server() ->
|
||||||
|
{ok, Props} = application:get_env(iot, http_server),
|
||||||
|
Acceptors = proplists:get_value(acceptors, Props, 50),
|
||||||
|
MaxConnections = proplists:get_value(max_connections, Props, 10240),
|
||||||
|
Backlog = proplists:get_value(backlog, Props, 1024),
|
||||||
|
Port = proplists:get_value(port, Props),
|
||||||
|
|
||||||
|
Dispatcher = cowboy_router:compile([
|
||||||
|
{'_', [
|
||||||
|
{"/host/[...]", http_protocol, [host_handler]},
|
||||||
|
{"/device/[...]", http_protocol, [device_handler]},
|
||||||
|
{"/service/[...]", http_protocol, [service_handler]}
|
||||||
|
]}
|
||||||
|
]),
|
||||||
|
|
||||||
|
TransOpts = [
|
||||||
|
{port, Port},
|
||||||
|
{num_acceptors, Acceptors},
|
||||||
|
{backlog, Backlog},
|
||||||
|
{max_connections, MaxConnections}
|
||||||
|
],
|
||||||
|
|
||||||
|
{ok, Pid} = cowboy:start_clear(http_listener, TransOpts, #{env => #{dispatch => Dispatcher}}),
|
||||||
|
|
||||||
|
lager:debug("[iot_app] the http server start at: ~p, pid is: ~p", [Port, Pid]).
|
||||||
|
|
||||||
%% 启动tcp服务
|
%% 启动tcp服务
|
||||||
start_tcp_server() ->
|
start_tcp_server() ->
|
||||||
{ok, Props} = application:get_env(iot, tcp_server),
|
{ok, Props} = application:get_env(iot, tcp_server),
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user