Browse Source

修改

master
SisMaker 4 years ago
parent
commit
e4f07bccd0
3 changed files with 32 additions and 12 deletions
  1. +2
    -1
      rebar.config
  2. +26
    -7
      src/sync/esScanner.erl
  3. +4
    -4
      src/sync/esUtils.erl

+ 2
- 1
rebar.config View File

@ -1,6 +1,7 @@
{erl_opts, [no_debug_info]}. {erl_opts, [no_debug_info]}.
{deps, [ {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, [ {shell, [

+ 26
- 7
src/sync/esScanner.erl View File

@ -45,8 +45,8 @@
, srcFileTimes = undefined :: [{file:filename(), timestamp()}] | undefined , srcFileTimes = undefined :: [{file:filename(), timestamp()}] | undefined
, onsyncFun = undefined , onsyncFun = undefined
, swSyncNode = false , swSyncNode = false
, sockMod
, sock
, sockMod = undefined
, sock = undefined
}). }).
%% ************************************ API start *************************** %% ************************************ API start ***************************
@ -119,20 +119,27 @@ handleAfter(_, waiting, State) ->
ListenPort = ?esCfgSync:getv(?listenPort), ListenPort = ?esCfgSync:getv(?listenPort),
case gen_tcp:listen(ListenPort, ?TCP_DEFAULT_OPTIONS) of case gen_tcp:listen(ListenPort, ?TCP_DEFAULT_OPTIONS) of
{ok, LSock} -> {ok, LSock} ->
os:cmd("./priv/fileSync \"./\"" ++ integer_to_list(ListenPort)),
case prim_inet:async_accept(LSock, -1) of case prim_inet:async_accept(LSock, -1) of
{ok, _Ref} -> {ok, _Ref} ->
{ok, SockMod} = inet_db:lookup_socket(LSock), {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} -> {error, Reason} ->
Msg = io_lib:format("init prim_inet:async_accept error ~p~n", [Reason]), Msg = io_lib:format("init prim_inet:async_accept error ~p~n", [Reason]),
esUtils:logErrors(Msg), esUtils:logErrors(Msg),
{kpS, State, {sTimeout, 2000}}
{kpS, State, {sTimeout, 2000, waitConnOver}}
end; end;
{error, Reason} -> {error, Reason} ->
Msg = io_lib:format("failed to listen on ~p - ~p (~s) ~n", [ListenPort, Reason, inet:format_error(Reason)]), Msg = io_lib:format("failed to listen on ~p - ~p (~s) ~n", [ListenPort, Reason, inet:format_error(Reason)]),
esUtils:logErrors(Msg), esUtils:logErrors(Msg),
{kpS, State, {sTimeout, 2000}}
{kpS, State, {sTimeout, 2000, waitConnOver}}
end. end.
handleCall(miGetOnsync, _, #state{onsyncFun = OnSync} = State, _From) -> handleCall(miGetOnsync, _, #state{onsyncFun = OnSync} = State, _From) ->
@ -225,11 +232,17 @@ handleCast({miSyncNode, IsSync}, _, State) ->
handleCast(_Msg, _, _State) -> handleCast(_Msg, _, _State) ->
kpS_S. 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 case Msg of
{ok, Sock} -> {ok, Sock} ->
%% make it look like gen_tcp:accept %% make it look like gen_tcp:accept
inet_db:register_socket(Sock, SockMod), 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}}; {nextS, running, State#state{sock = Sock}};
{error, closed} -> {error, closed} ->
Msg = io_lib:format("error, closed listen sock error ~p~n",[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}} {stop, {lsock, Reason}}
end; end;
handleInfo({tcp, Socket, Data}, running, State) -> handleInfo({tcp, Socket, Data}, running, State) ->
io:format("IMY************** get tcp msg ~p~n", [Data]),
kpS_S; kpS_S;
handleInfo({tcp_closed, Socket}, running, State) -> handleInfo({tcp_closed, Socket}, running, State) ->
io:format("IMY************** get tcp msg ~p~n", [close]),
kpS_S; kpS_S;
handleInfo({tcp_error, Socket, Reason},running, State) -> handleInfo({tcp_error, Socket, Reason},running, State) ->
io:format("IMY************** get tcp msg ~p~n", [111]),
kpS_S; kpS_S;
handleInfo(_Msg, _, _State) -> handleInfo(_Msg, _, _State) ->
io:format("IMY************** get tcp msg ~p~n", [_Msg]),
kpS_S. kpS_S.
handleOnevent({doSync, _}, Msg, Status, State) -> handleOnevent({doSync, _}, Msg, Status, State) ->
handleCast(Msg, Status, State); handleCast(Msg, Status, State);
handleOnevent(sTimeout, waitConnOver, Status, State) ->
stop;
handleOnevent(_EventType, _EventContent, _Status, _State) -> handleOnevent(_EventType, _EventContent, _Status, _State) ->
kpS_S. kpS_S.

+ 4
- 4
src/sync/esUtils.erl View File

@ -228,18 +228,18 @@ fixDescendantSource([], _IsFile) ->
fixDescendantSource(Path, IsFile) -> fixDescendantSource(Path, IsFile) ->
{ok, Cwd} = file:get_cwd(), {ok, Cwd} = file:get_cwd(),
PathParts = filename:split(Path), PathParts = filename:split(Path),
case makeDescendantSource(Cwd, PathParts) of
case makeDescendantSource(PathParts, Cwd) of
undefined -> case IsFile of true -> Path; _ -> undefined end; undefined -> case IsFile of true -> Path; _ -> undefined end;
FoundPath -> FoundPath FoundPath -> FoundPath
end. end.
makeDescendantSource(_Cwd, []) ->
makeDescendantSource([], _Cwd) ->
undefined; undefined;
makeDescendantSource(Cwd, [_ | T]) ->
makeDescendantSource([_ | T], Cwd) ->
PathAttempt = filename:join([Cwd | T]), PathAttempt = filename:join([Cwd | T]),
case filelib:is_regular(PathAttempt) of case filelib:is_regular(PathAttempt) of
true -> PathAttempt; true -> PathAttempt;
false -> makeDescendantSource(Cwd, T)
false -> makeDescendantSource(T, Cwd)
end. end.
isDescendent(Path) -> isDescendent(Path) ->

Loading…
Cancel
Save