Browse Source

ft: 代码优化

master
SisMaker 3 years ago
parent
commit
bf58def288
7 changed files with 41 additions and 36 deletions
  1. +7
    -4
      src/proxyPt/ntPptAcceptor.erl
  2. +5
    -6
      src/proxyPt/ntPptListener.erl
  3. +7
    -4
      src/ssl/ntSslAcceptor.erl
  4. +5
    -6
      src/ssl/ntSslListener.erl
  5. +7
    -4
      src/tcp/ntTcpAcceptor.erl
  6. +5
    -6
      src/tcp/ntTcpListener.erl
  7. +5
    -6
      src/udp/ntUdpSrv.erl

+ 7
- 4
src/proxyPt/ntPptAcceptor.erl View File

@ -44,8 +44,8 @@ system_get_state(State) ->
{ok, State}. {ok, State}.
-spec system_terminate(term(), pid(), [], term()) -> none(). -spec system_terminate(term(), pid(), [], term()) -> none().
system_terminate(Reason, _Parent, _Debug, _State) ->
exit(Reason).
system_terminate(Reason, _Parent, _Debug, State) ->
terminate(Reason, State).
modInit(Parent, Args) -> modInit(Parent, Args) ->
case init(Args) of case init(Args) of
@ -62,7 +62,7 @@ loop(Parent, State) ->
{system, From, Request} -> {system, From, Request} ->
sys:handle_system_msg(Request, From, Parent, ?MODULE, [], {Parent, State}); sys:handle_system_msg(Request, From, Parent, ?MODULE, [], {Parent, State});
{'EXIT', Parent, Reason} -> {'EXIT', Parent, Reason} ->
exit(Reason);
terminate(Reason, State);
Msg -> Msg ->
case handleMsg(Msg, State) of case handleMsg(Msg, State) of
kpS -> kpS ->
@ -70,7 +70,7 @@ loop(Parent, State) ->
{ok, NewState} -> {ok, NewState} ->
loop(Parent, NewState); loop(Parent, NewState);
{stop, Reason} -> {stop, Reason} ->
exit(Reason)
terminate(Reason, State)
end end
end. end.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% genActor end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% genActor end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@ -130,6 +130,9 @@ handleMsg({inet_async, LSock, Ref, Msg}, #state{lSock = LSock, sslOpts = SslOpts
handleMsg(_Msg, _State) -> handleMsg(_Msg, _State) ->
kpS. kpS.
terminate(Reason, _State) ->
exit(Reason).
newAsyncAccept(LSock, State) -> newAsyncAccept(LSock, State) ->
case prim_inet:async_accept(LSock, -1) of case prim_inet:async_accept(LSock, -1) of
{ok, Ref} -> {ok, Ref} ->

+ 5
- 6
src/proxyPt/ntPptListener.erl View File

@ -45,8 +45,8 @@ system_get_state(State) ->
{ok, State}. {ok, State}.
-spec system_terminate(term(), pid(), [], term()) -> none(). -spec system_terminate(term(), pid(), [], term()) -> none().
system_terminate(Reason, _Parent, _Debug, _State) ->
exit(Reason).
system_terminate(Reason, _Parent, _Debug, State) ->
terminate(Reason, State).
safeRegister(Name) -> safeRegister(Name) ->
try register(Name, self()) of try register(Name, self()) of
@ -78,8 +78,7 @@ loop(Parent, State) ->
{ok, NewState} -> {ok, NewState} ->
loop(Parent, NewState); loop(Parent, NewState);
{stop, Reason} -> {stop, Reason} ->
terminate(Reason, State),
exit(Reason)
terminate(Reason, State)
end end
end. end.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% genActor end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% genActor end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@ -119,11 +118,11 @@ handleMsg({'$gen_call', From, miListenPort}, #state{listenPort = LPort} = _State
handleMsg(_Msg, _State) -> handleMsg(_Msg, _State) ->
kpS. kpS.
terminate(_Reason, #state{lSock = LSock, listenAddr = Addr, listenPort = Port}) ->
terminate(Reason, #state{lSock = LSock, listenAddr = Addr, listenPort = Port}) ->
?ntInfo("stopped on ~s:~p ~n", [inet:ntoa(Addr), Port]), ?ntInfo("stopped on ~s:~p ~n", [inet:ntoa(Addr), Port]),
%% LSock tcp_close acctptor进程 %% LSock tcp_close acctptor进程
catch port_close(LSock), catch port_close(LSock),
ok.
exit(Reason).
startAcceptor(0, _LSock, _AptSupName, _ConMod, _ConArgs) -> startAcceptor(0, _LSock, _AptSupName, _ConMod, _ConArgs) ->
ok; ok;

+ 7
- 4
src/ssl/ntSslAcceptor.erl View File

@ -43,8 +43,8 @@ system_get_state(State) ->
{ok, State}. {ok, State}.
-spec system_terminate(term(), pid(), [], term()) -> none(). -spec system_terminate(term(), pid(), [], term()) -> none().
system_terminate(Reason, _Parent, _Debug, _State) ->
exit(Reason).
system_terminate(Reason, _Parent, _Debug, State) ->
terminate(Reason, State).
modInit(Parent, Args) -> modInit(Parent, Args) ->
case init(Args) of case init(Args) of
@ -61,7 +61,7 @@ loop(Parent, State) ->
{system, From, Request} -> {system, From, Request} ->
sys:handle_system_msg(Request, From, Parent, ?MODULE, [], {Parent, State}); sys:handle_system_msg(Request, From, Parent, ?MODULE, [], {Parent, State});
{'EXIT', Parent, Reason} -> {'EXIT', Parent, Reason} ->
exit(Reason);
terminate(Reason, State);
Msg -> Msg ->
case handleMsg(Msg, State) of case handleMsg(Msg, State) of
kpS -> kpS ->
@ -69,7 +69,7 @@ loop(Parent, State) ->
{ok, NewState} -> {ok, NewState} ->
loop(Parent, NewState); loop(Parent, NewState);
{stop, Reason} -> {stop, Reason} ->
exit(Reason)
terminate(Reason, State)
end end
end. end.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% genActor end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% genActor end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@ -127,6 +127,9 @@ handleMsg({inet_async, LSock, Ref, Msg}, #state{lSock = LSock, sslOpts = SslOpts
handleMsg(_Msg, _State) -> handleMsg(_Msg, _State) ->
kpS. kpS.
terminate(Reason, _State) ->
exit(Reason).
newAsyncAccept(LSock, State) -> newAsyncAccept(LSock, State) ->
case prim_inet:async_accept(LSock, -1) of case prim_inet:async_accept(LSock, -1) of
{ok, Ref} -> {ok, Ref} ->

+ 5
- 6
src/ssl/ntSslListener.erl View File

@ -45,8 +45,8 @@ system_get_state(State) ->
{ok, State}. {ok, State}.
-spec system_terminate(term(), pid(), [], term()) -> none(). -spec system_terminate(term(), pid(), [], term()) -> none().
system_terminate(Reason, _Parent, _Debug, _State) ->
exit(Reason).
system_terminate(Reason, _Parent, _Debug, State) ->
terminate(Reason, State).
safeRegister(Name) -> safeRegister(Name) ->
try register(Name, self()) of try register(Name, self()) of
@ -78,8 +78,7 @@ loop(Parent, State) ->
{ok, NewState} -> {ok, NewState} ->
loop(Parent, NewState); loop(Parent, NewState);
{stop, Reason} -> {stop, Reason} ->
terminate(Reason, State),
exit(Reason)
terminate(Reason, State)
end end
end. end.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% genActor end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% genActor end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@ -119,11 +118,11 @@ handleMsg({'$gen_call', From, miListenPort}, #state{listenPort = LPort} = _State
handleMsg(_Msg, _State) -> handleMsg(_Msg, _State) ->
kpS. kpS.
terminate(_Reason, #state{lSock = LSock, listenAddr = Addr, listenPort = Port}) ->
terminate(Reason, #state{lSock = LSock, listenAddr = Addr, listenPort = Port}) ->
?ntInfo("stopped on ~s:~p ~n", [inet:ntoa(Addr), Port]), ?ntInfo("stopped on ~s:~p ~n", [inet:ntoa(Addr), Port]),
%% LSock tcp_close acctptor进程 %% LSock tcp_close acctptor进程
catch port_close(LSock), catch port_close(LSock),
ok.
exit(Reason).
startAcceptor(0, _LSock, _AptSupName, _ConMod, _ConArgs) -> startAcceptor(0, _LSock, _AptSupName, _ConMod, _ConArgs) ->
ok; ok;

+ 7
- 4
src/tcp/ntTcpAcceptor.erl View File

@ -41,8 +41,8 @@ system_get_state(State) ->
{ok, State}. {ok, State}.
-spec system_terminate(term(), pid(), [], term()) -> none(). -spec system_terminate(term(), pid(), [], term()) -> none().
system_terminate(Reason, _Parent, _Debug, _State) ->
exit(Reason).
system_terminate(Reason, _Parent, _Debug, State) ->
terminate(Reason, State).
modInit(Parent, Args) -> modInit(Parent, Args) ->
case init(Args) of case init(Args) of
@ -59,7 +59,7 @@ loop(Parent, State) ->
{system, From, Request} -> {system, From, Request} ->
sys:handle_system_msg(Request, From, Parent, ?MODULE, [], {Parent, State}); sys:handle_system_msg(Request, From, Parent, ?MODULE, [], {Parent, State});
{'EXIT', Parent, Reason} -> {'EXIT', Parent, Reason} ->
exit(Reason);
terminate(Reason, State);
Msg -> Msg ->
case handleMsg(Msg, State) of case handleMsg(Msg, State) of
kpS -> kpS ->
@ -67,7 +67,7 @@ loop(Parent, State) ->
{ok, NewState} -> {ok, NewState} ->
loop(Parent, NewState); loop(Parent, NewState);
{stop, Reason} -> {stop, Reason} ->
exit(Reason)
terminate(Reason, State)
end end
end. end.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% genActor end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% genActor end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@ -123,6 +123,9 @@ handleMsg({inet_async, LSock, Ref, Msg}, #state{lSock = LSock, ref = Ref, conMod
handleMsg(_Msg, _State) -> handleMsg(_Msg, _State) ->
kpS. kpS.
terminate(Reason, _State) ->
exit(Reason).
newAsyncAccept(LSock, State) -> newAsyncAccept(LSock, State) ->
case prim_inet:async_accept(LSock, -1) of case prim_inet:async_accept(LSock, -1) of
{ok, Ref} -> {ok, Ref} ->

+ 5
- 6
src/tcp/ntTcpListener.erl View File

@ -45,8 +45,8 @@ system_get_state(State) ->
{ok, State}. {ok, State}.
-spec system_terminate(term(), pid(), [], term()) -> none(). -spec system_terminate(term(), pid(), [], term()) -> none().
system_terminate(Reason, _Parent, _Debug, _State) ->
exit(Reason).
system_terminate(Reason, _Parent, _Debug, State) ->
terminate(Reason, State).
safeRegister(Name) -> safeRegister(Name) ->
try register(Name, self()) of try register(Name, self()) of
@ -78,8 +78,7 @@ loop(Parent, State) ->
{ok, NewState} -> {ok, NewState} ->
loop(Parent, NewState); loop(Parent, NewState);
{stop, Reason} -> {stop, Reason} ->
terminate(Reason, State),
exit(Reason)
terminate(Reason, State)
end end
end. end.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% genActor end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% genActor end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@ -119,11 +118,11 @@ handleMsg({'$gen_call', From, miListenPort}, #state{listenPort = LPort} = _State
handleMsg(_Msg, _State) -> handleMsg(_Msg, _State) ->
kpS. kpS.
terminate(_Reason, #state{lSock = LSock, listenAddr = Addr, listenPort = Port}) ->
terminate(Reason, #state{lSock = LSock, listenAddr = Addr, listenPort = Port}) ->
?ntInfo("stopped on ~s:~p ~n", [inet:ntoa(Addr), Port]), ?ntInfo("stopped on ~s:~p ~n", [inet:ntoa(Addr), Port]),
%% LSock tcp_close acctptor进程 %% LSock tcp_close acctptor进程
catch port_close(LSock), catch port_close(LSock),
ok.
exit(Reason).
startAcceptor(0, _LSock, _AptSupName, _ConMod, _ConArgs) -> startAcceptor(0, _LSock, _AptSupName, _ConMod, _ConArgs) ->
ok; ok;

+ 5
- 6
src/udp/ntUdpSrv.erl View File

@ -45,8 +45,8 @@ system_get_state(State) ->
{ok, State}. {ok, State}.
-spec system_terminate(term(), pid(), [], term()) -> none(). -spec system_terminate(term(), pid(), [], term()) -> none().
system_terminate(Reason, _Parent, _Debug, _State) ->
exit(Reason).
system_terminate(Reason, _Parent, _Debug, State) ->
terminate(Reason, State).
safeRegister(Name) -> safeRegister(Name) ->
try register(Name, self()) of try register(Name, self()) of
@ -78,8 +78,7 @@ loop(Parent, State) ->
{ok, NewState} -> {ok, NewState} ->
loop(Parent, NewState); loop(Parent, NewState);
{stop, Reason} -> {stop, Reason} ->
terminate(Reason, State),
exit(Reason)
terminate(Reason, State)
end end
end. end.
@ -175,10 +174,10 @@ handleMsg(_Msg, _State) ->
?ntErr("~p unexpected info: ~p ~n", [?MODULE, _Msg]), ?ntErr("~p unexpected info: ~p ~n", [?MODULE, _Msg]),
kpS. kpS.
terminate(_Reason, #state{oSock = LSock, listenAddr = Addr, listenPort = Port}) ->
terminate(Reason, #state{oSock = LSock, listenAddr = Addr, listenPort = Port}) ->
?ntInfo("stopped on ~s:~p ~n", [inet:ntoa(Addr), Port]), ?ntInfo("stopped on ~s:~p ~n", [inet:ntoa(Addr), Port]),
catch gen_udp:close(LSock), catch gen_udp:close(LSock),
ok.
exit(Reason).
-spec getOpts(pid()) -> [listenOpt()]. -spec getOpts(pid()) -> [listenOpt()].
getOpts(Listener) -> getOpts(Listener) ->

Loading…
Cancel
Save