瀏覽代碼

ft: 代码优化

master
SisMaker 3 年之前
父節點
當前提交
bf58def288
共有 7 個檔案被更改,包括 41 行新增36 行删除
  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 查看文件

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

+ 5
- 6
src/proxyPt/ntPptListener.erl 查看文件

@ -45,8 +45,8 @@ system_get_state(State) ->
{ok, State}.
-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) ->
try register(Name, self()) of
@ -78,8 +78,7 @@ loop(Parent, State) ->
{ok, NewState} ->
loop(Parent, NewState);
{stop, Reason} ->
terminate(Reason, State),
exit(Reason)
terminate(Reason, State)
end
end.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% genActor end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@ -119,11 +118,11 @@ handleMsg({'$gen_call', From, miListenPort}, #state{listenPort = LPort} = _State
handleMsg(_Msg, _State) ->
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]),
%% LSock tcp_close acctptor进程
catch port_close(LSock),
ok.
exit(Reason).
startAcceptor(0, _LSock, _AptSupName, _ConMod, _ConArgs) ->
ok;

+ 7
- 4
src/ssl/ntSslAcceptor.erl 查看文件

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

+ 5
- 6
src/ssl/ntSslListener.erl 查看文件

@ -45,8 +45,8 @@ system_get_state(State) ->
{ok, State}.
-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) ->
try register(Name, self()) of
@ -78,8 +78,7 @@ loop(Parent, State) ->
{ok, NewState} ->
loop(Parent, NewState);
{stop, Reason} ->
terminate(Reason, State),
exit(Reason)
terminate(Reason, State)
end
end.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% genActor end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@ -119,11 +118,11 @@ handleMsg({'$gen_call', From, miListenPort}, #state{listenPort = LPort} = _State
handleMsg(_Msg, _State) ->
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]),
%% LSock tcp_close acctptor进程
catch port_close(LSock),
ok.
exit(Reason).
startAcceptor(0, _LSock, _AptSupName, _ConMod, _ConArgs) ->
ok;

+ 7
- 4
src/tcp/ntTcpAcceptor.erl 查看文件

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

+ 5
- 6
src/tcp/ntTcpListener.erl 查看文件

@ -45,8 +45,8 @@ system_get_state(State) ->
{ok, State}.
-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) ->
try register(Name, self()) of
@ -78,8 +78,7 @@ loop(Parent, State) ->
{ok, NewState} ->
loop(Parent, NewState);
{stop, Reason} ->
terminate(Reason, State),
exit(Reason)
terminate(Reason, State)
end
end.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% genActor end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@ -119,11 +118,11 @@ handleMsg({'$gen_call', From, miListenPort}, #state{listenPort = LPort} = _State
handleMsg(_Msg, _State) ->
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]),
%% LSock tcp_close acctptor进程
catch port_close(LSock),
ok.
exit(Reason).
startAcceptor(0, _LSock, _AptSupName, _ConMod, _ConArgs) ->
ok;

+ 5
- 6
src/udp/ntUdpSrv.erl 查看文件

@ -45,8 +45,8 @@ system_get_state(State) ->
{ok, State}.
-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) ->
try register(Name, self()) of
@ -78,8 +78,7 @@ loop(Parent, State) ->
{ok, NewState} ->
loop(Parent, NewState);
{stop, Reason} ->
terminate(Reason, State),
exit(Reason)
terminate(Reason, State)
end
end.
@ -175,10 +174,10 @@ handleMsg(_Msg, _State) ->
?ntErr("~p unexpected info: ~p ~n", [?MODULE, _Msg]),
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]),
catch gen_udp:close(LSock),
ok.
exit(Reason).
-spec getOpts(pid()) -> [listenOpt()].
getOpts(Listener) ->

Loading…
取消
儲存