在项目中会遇到一中情况,就是ftp:recv_bin没有返回值,进程也没有响应的情况,
解决方式就是利用gen_server:call(GenServer, Req, Timeout)的方式去加入超时来解决,超时未响应的问题。
{ok, Pid} = ftp:open(Host, [{port, Port}, {timeout, 6000},{dtimeout, 6000}]),
call(Pid, {recv_bin, RemoteFile}, bin, timer:seconds(60)),
call(GenServer, Msg, Format, Timeout) ->
Req = {self(), Msg},
case (catch gen_server:call(GenServer, Req, Timeout)) of
{ok, Bin} when is_binary(Bin) andalso (Format =:= string) ->
{ok, binary_to_list(Bin)};
{'EXIT', Re} ->
log4erl:error("*** ~p(~4.10.0w) ftp download fail !Reason = ~p", [?MODULE, ?LINE, Re]),
{error, eclosed};
Result ->
Result
end.
来解决超时的问题。