From 59b076fe1bdf8aeee6a9579f0d2266f8c3186098 Mon Sep 17 00:00:00 2001 From: Jesper Louis Andersen Date: Mon, 21 Jul 2008 16:04:34 +0200 Subject: [PATCH] Push #piece handling function to the etorrent_piece module. --- lib/etorrent-1.0/src/etorrent_chunk.erl | 13 ++----------- lib/etorrent-1.0/src/etorrent_piece.erl | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/lib/etorrent-1.0/src/etorrent_chunk.erl b/lib/etorrent-1.0/src/etorrent_chunk.erl index 4b8f6c5..8c73ea2 100644 --- a/lib/etorrent-1.0/src/etorrent_chunk.erl +++ b/lib/etorrent-1.0/src/etorrent_chunk.erl @@ -137,7 +137,8 @@ store_chunk(Id, PieceNum, {Offset, Len}, Pid) -> case Present of fetched -> ok; true -> ok; - false -> t_decrease_missing_chunks(Id, PieceNum) + false -> + etorrent_piece:t_decrease_missing_chunks(Id, PieceNum) end end), Res. @@ -436,13 +437,3 @@ t_update_chunk_assignment(Id, PieceNum, Pid, end end. -t_decrease_missing_chunks(Id, PieceNum) -> - [P] = mnesia:read(piece, {Id, PieceNum}, write), - NewP = P#piece { left = P#piece.left - 1 }, - mnesia:write(NewP), - case NewP#piece.left of - 0 -> - full; - N when is_integer(N) -> - ok - end. diff --git a/lib/etorrent-1.0/src/etorrent_piece.erl b/lib/etorrent-1.0/src/etorrent_piece.erl index 94a4919..c4392b6 100644 --- a/lib/etorrent-1.0/src/etorrent_piece.erl +++ b/lib/etorrent-1.0/src/etorrent_piece.erl @@ -16,6 +16,8 @@ select/1, select/2, num_not_fetched/1, delete/1, valid/2, interesting/2, bitfield/1, check_interest/2]). +-export([t_decrease_missing_chunks/2]). + -export([t_fetched/2]). %%==================================================================== @@ -199,6 +201,23 @@ num_not_fetched(Id) when is_integer(Id) -> {atomic, N} = mnesia:transaction(F), N. +%%-------------------------------------------------------------------- +%% Function: t_decrease_missing_chunks/2 +%% Args: Id ::= integer() - torrent id +%% PieceNum ::= integer() - piece index +%% Description: Decrease missing chunks for the {Id, PieceNum} pair. +%%-------------------------------------------------------------------- +t_decrease_missing_chunks(Id, PieceNum) -> + [P] = mnesia:read(piece, {Id, PieceNum}, write), + NewP = P#piece { left = P#piece.left - 1 }, + mnesia:write(NewP), + case NewP#piece.left of + 0 -> + full; + N when is_integer(N) -> + ok + end. + %%==================================================================== %% Internal functions %%==================================================================== -- 2.11.4.GIT