From 465edf7e6c8379a726f9daadf74d63c69eab1295 Mon Sep 17 00:00:00 2001 From: SisMaker <156736github> Date: Wed, 19 Jan 2022 23:55:38 +0800 Subject: [PATCH] =?UTF-8?q?ft:=20=E4=BB=A3=E7=A0=81=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/eWSrv.erl | 39 +++++++++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/src/eWSrv.erl b/src/eWSrv.erl index 52172a7..5610db0 100644 --- a/src/eWSrv.erl +++ b/src/eWSrv.erl @@ -5,8 +5,10 @@ -export([ start/0 , stop/0 - , startWSrv/3 - , stopWSrv/1 + , openSrv/2 + , openSrv/3 + , closeSrv/1 + , wSrvName/1 ]). start() -> @@ -15,7 +17,27 @@ start() -> stop() -> application:stop(eWSrv). -startWSrv(WSrvName, Port, WsOpts) -> +wSrvName(Port) -> + binary_to_atom(<<"$WSrv", (integer_to_binary(Port))/bianry>>). + +openSrv(Port, WsOpts) -> + T1WsOpts = lists:keystore(conMod, 1, WsOpts, {conMod, wsHttp}), + WsMod = ?wsGLV(wsMod, WsOpts, wsEgHer), + T2WsOpts = lists:keystore(conArgs, 1, T1WsOpts, {conArgs, WsMod}), + TcpOpts = ?wsGLV(tcpOpts, T2WsOpts, []), + NewTcpOpts = wsUtil:mergeOpts(?DefWsOpts, TcpOpts), + LWsOpts = lists:keystore(tcpOpts, 1, T2WsOpts, {tcpOpts, NewTcpOpts}), + + WSrvName = wSvNrame(Port), + + case ?wsGLV(sslOpts, WsOpts, false) of + false -> + {ok, _} = eNet:openTcp(WSrvName, Port, LWsOpts); + _ -> + {ok, _} = eNet:openSsl(WSrvName, Port, LWsOpts) + end. + +openSrv(WSrvName, Port, WsOpts) -> T1WsOpts = lists:keystore(conMod, 1, WsOpts, {conMod, wsHttp}), WsMod = ?wsGLV(wsMod, WsOpts, wsEgHer), T2WsOpts = lists:keystore(conArgs, 1, T1WsOpts, {conArgs, WsMod}), @@ -30,8 +52,13 @@ startWSrv(WSrvName, Port, WsOpts) -> {ok, _} = eNet:openSsl(WSrvName, Port, LWsOpts) end. -stopWSrv(WSrvName) -> - ListenName = wsUtil:lsName(WSrvName), - eNet:close(ListenName), +closeSrv(WSrvNameOrPort) -> + WSrvName = + case is_integer(WSrvNameOrPort) of + true -> + wSvNrame(WSrvNameOrPort); + _ -> + WSrvNameOrPort + end, supervisor:terminate_child(eWSrv_sup, WSrvName), supervisor:delete_child(eWSrv_sup, WSrvName). \ No newline at end of file