From 46102e6ca3cc52e94241618d2bb606033f91b9b1 Mon Sep 17 00:00:00 2001 From: Jesper Louis Andersen Date: Thu, 31 Jul 2008 21:02:41 +0200 Subject: [PATCH] Use a try..catch in etorrent_fs:read_pieces_and_assemble/3. --- lib/etorrent-1.0/src/etorrent_fs.erl | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/etorrent-1.0/src/etorrent_fs.erl b/lib/etorrent-1.0/src/etorrent_fs.erl index e87de00..12a47bb 100644 --- a/lib/etorrent-1.0/src/etorrent_fs.erl +++ b/lib/etorrent-1.0/src/etorrent_fs.erl @@ -178,14 +178,16 @@ create_file_process(Id, S) -> read_pieces_and_assemble([], FileData, S) -> {ok, list_to_binary(lists:reverse(FileData)), S}; read_pieces_and_assemble([{Id, Offset, Size} | Rest], Done, S) -> + %% 2 Notes: This can't be tail recursive due to catch-handler on stack. + %% I've seen exit:{timeout, ...}. We should probably just warn + %% And try again ;) case dict:find(Id, S#state.file_process_dict) of {ok, Pid} -> - Ref = make_ref(), - case catch({Ref, - etorrent_fs_process:get_data(Pid, Offset, Size)}) of - {Ref, Data} -> - read_pieces_and_assemble(Rest, [Data | Done], S); - {'EXIT', {noproc, _}} -> + try + Data = etorrent_fs_process:get_data(Pid, Offset, Size), + read_pieces_and_assemble(Rest, [Data | Done], S) + catch + exit:{noproc, _} -> D = remove_file_process(Pid, S#state.file_process_dict), read_pieces_and_assemble([{Id, Offset, Size} | Rest], Done, -- 2.11.4.GIT