From e4f07bccd05ea87693e3cc39a633e2650ab63c14 Mon Sep 17 00:00:00 2001 From: SisMaker <1713699517@qq.com> Date: Sat, 31 Oct 2020 01:20:44 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rebar.config | 3 ++- src/sync/esScanner.erl | 33 ++++++++++++++++++++++++++------- src/sync/esUtils.erl | 8 ++++---- 3 files changed, 32 insertions(+), 12 deletions(-) diff --git a/rebar.config b/rebar.config index d2b9122..f107fab 100644 --- a/rebar.config +++ b/rebar.config @@ -1,6 +1,7 @@ {erl_opts, [no_debug_info]}. {deps, [ - {erlGbh, ".*", {git, "https://github.com/SisMaker/erlGbh.git", {branch, "master"}}} + + {erlGbh, ".*", {git, "http://120.77.213.39:53000/SisMaker/erlGbh.git", {branch, "master"}}} ]}. {shell, [ diff --git a/src/sync/esScanner.erl b/src/sync/esScanner.erl index 82424c8..0d792be 100644 --- a/src/sync/esScanner.erl +++ b/src/sync/esScanner.erl @@ -45,8 +45,8 @@ , srcFileTimes = undefined :: [{file:filename(), timestamp()}] | undefined , onsyncFun = undefined , swSyncNode = false - , sockMod - , sock + , sockMod = undefined + , sock = undefined }). %% ************************************ API start *************************** @@ -119,20 +119,27 @@ handleAfter(_, waiting, State) -> ListenPort = ?esCfgSync:getv(?listenPort), case gen_tcp:listen(ListenPort, ?TCP_DEFAULT_OPTIONS) of {ok, LSock} -> - os:cmd("./priv/fileSync \"./\"" ++ integer_to_list(ListenPort)), case prim_inet:async_accept(LSock, -1) of {ok, _Ref} -> {ok, SockMod} = inet_db:lookup_socket(LSock), - {kpS, State#state{sockMod = SockMod}, {sTimeout, 2000}}; + io:format("IMY******************11111"), + spawn(fun() -> case os:type() of + {win32, _Osname} -> + os:cmd("start ./priv/fileSync ./ " ++ integer_to_list(ListenPort)); + _ -> + os:cmd("./priv/fileSync ./ " ++ integer_to_list(ListenPort)) + end end), + io:format("IMY******************22222 "), + {kpS, State#state{sockMod = SockMod}, {sTimeout, 2000000, waitConnOver}}; {error, Reason} -> Msg = io_lib:format("init prim_inet:async_accept error ~p~n", [Reason]), esUtils:logErrors(Msg), - {kpS, State, {sTimeout, 2000}} + {kpS, State, {sTimeout, 2000, waitConnOver}} end; {error, Reason} -> Msg = io_lib:format("failed to listen on ~p - ~p (~s) ~n", [ListenPort, Reason, inet:format_error(Reason)]), esUtils:logErrors(Msg), - {kpS, State, {sTimeout, 2000}} + {kpS, State, {sTimeout, 2000, waitConnOver}} end. handleCall(miGetOnsync, _, #state{onsyncFun = OnSync} = State, _From) -> @@ -225,11 +232,17 @@ handleCast({miSyncNode, IsSync}, _, State) -> handleCast(_Msg, _, _State) -> kpS_S. -handleInfo({inet_async, _LSock, _Ref, Msg}, waiting, #state{sockMod = SockMod} = State) -> +handleInfo({inet_async, LSock, _Ref, Msg}, _, #state{sockMod = SockMod} = State) -> + io:format("IMY************** get inet_async msg ~p~n", [Msg]), case Msg of {ok, Sock} -> %% make it look like gen_tcp:accept inet_db:register_socket(Sock, SockMod), + io:format("IMY************** socket optinon111 ~p~n", [inet:getopts(Sock, [active, packet])]), + io:format("IMY************** socket optinon222 ~p~n", [inet:getopts(LSock, [active, packet])]), + inet:setopts(Sock, [{active, true}]), + io:format("IMY************** socket optinon111 ~p~n", [inet:getopts(Sock, [active, packet])]), + prim_inet:async_accept(LSock, -1), {nextS, running, State#state{sock = Sock}}; {error, closed} -> Msg = io_lib:format("error, closed listen sock error ~p~n",[closed]), @@ -241,16 +254,22 @@ handleInfo({inet_async, _LSock, _Ref, Msg}, waiting, #state{sockMod = SockMod} = {stop, {lsock, Reason}} end; handleInfo({tcp, Socket, Data}, running, State) -> + io:format("IMY************** get tcp msg ~p~n", [Data]), kpS_S; handleInfo({tcp_closed, Socket}, running, State) -> + io:format("IMY************** get tcp msg ~p~n", [close]), kpS_S; handleInfo({tcp_error, Socket, Reason},running, State) -> + io:format("IMY************** get tcp msg ~p~n", [111]), kpS_S; handleInfo(_Msg, _, _State) -> + io:format("IMY************** get tcp msg ~p~n", [_Msg]), kpS_S. handleOnevent({doSync, _}, Msg, Status, State) -> handleCast(Msg, Status, State); +handleOnevent(sTimeout, waitConnOver, Status, State) -> + stop; handleOnevent(_EventType, _EventContent, _Status, _State) -> kpS_S. diff --git a/src/sync/esUtils.erl b/src/sync/esUtils.erl index 08766a4..2b4c268 100644 --- a/src/sync/esUtils.erl +++ b/src/sync/esUtils.erl @@ -228,18 +228,18 @@ fixDescendantSource([], _IsFile) -> fixDescendantSource(Path, IsFile) -> {ok, Cwd} = file:get_cwd(), PathParts = filename:split(Path), - case makeDescendantSource(Cwd, PathParts) of + case makeDescendantSource(PathParts, Cwd) of undefined -> case IsFile of true -> Path; _ -> undefined end; FoundPath -> FoundPath end. -makeDescendantSource(_Cwd, []) -> +makeDescendantSource([], _Cwd) -> undefined; -makeDescendantSource(Cwd, [_ | T]) -> +makeDescendantSource([_ | T], Cwd) -> PathAttempt = filename:join([Cwd | T]), case filelib:is_regular(PathAttempt) of true -> PathAttempt; - false -> makeDescendantSource(Cwd, T) + false -> makeDescendantSource(T, Cwd) end. isDescendent(Path) ->