Permalink
Browse files

Merge remote-tracking branch 'klaar/rlimit'

Conflicts:
	apps/etorrent/src/etorrent_app.erl
	rel/reltool.config
  • Loading branch information...
2 parents 2edd431 + 8b4e3f0 commit 67fd6bad846b65c20c6e1efda027832e28b16ca8 @jlouis committed Oct 25, 2011
@@ -44,6 +44,7 @@ start(_Type, _Args) ->
case etorrent_sup:start_link(PeerId) of
{ok, Pid} ->
etorrent_log:init_settings(),
+ ok = etorrent_rlimit:init(),
ok = etorrent_memory_logger:add_handler(),
ok = etorrent_file_logger:add_handler(),
ok = etorrent_callback_handler:add_handler(),
@@ -18,6 +18,7 @@
dropped/2,
fetched/5,
stored/5,
+ contents/5,
forward/1]).
%% inspection functions
@@ -100,6 +101,14 @@ stored(Piece, Offset, Length, Peerpid, Srvpid) ->
Srvpid ! {chunk, {stored, Piece, Offset, Length, Peerpid}},
ok.
+%% @doc Send the contents of a chunk to a process.
+%% @end
+-spec contents(non_neg_integer(), non_neg_integer(),
+ non_neg_integer(), binary(), pid()) -> ok.
+contents(Piece, Offset, Length, Data, PeerPid) ->
+ PeerPid ! {chunk, {contents, Piece, Offset, Length, Data}},
+ ok.
+
%% @doc
%% @end
@@ -159,7 +168,8 @@ chunkstate_test_() ->
?_test(test_dropped_all()),
?_test(test_fetched()),
?_test(test_stored()),
- ?_test(test_forward())]}.
+ ?_test(test_forward()),
+ ?_test(test_contents())]}.
test_request() ->
Peer = self(),
@@ -216,6 +226,10 @@ test_stored() ->
ok = ?chunkstate:stored(1, 2, 3, Pid, self()),
?assertEqual({chunk, {stored, 1, 2, 3, Pid}}, pop()).
+test_contents() ->
+ ok = ?chunkstate:contents(1, 2, 3, <<1,2,3>>, self()),
+ ?assertEqual({chunk, {contents, 1, 2, 3, <<1,2,3>>}}, pop()).
+
test_forward() ->
Main = self(),
Pid = make_pid(),
@@ -22,6 +22,7 @@
max_files/0,
max_peers/0,
max_upload_rate/0,
+ max_download_rate/0,
max_upload_slots/0,
optimistic_slots/0,
profiling/0,
@@ -57,7 +58,8 @@ configuration_specification() ->
optional(fs_watermark_high, 128),
optional(max_upload_slots, auto),
required(min_upload),
- required(max_upload_rate),
+ optional(max_upload_rate, infinity),
+ optional(max_download_rate, infinity),
required(port),
required(logger_dir),
required(logger_fname),
@@ -131,9 +133,12 @@ max_upload_slots() -> call(max_upload_slots).
-spec optimistic_slots() -> pos_integer().
optimistic_slots() -> call(min_upload).
--spec max_upload_rate() -> pos_integer().
+-spec max_upload_rate() -> pos_integer() | infinity.
max_upload_rate() -> call(max_upload_rate).
+-spec max_download_rate() -> pos_integer() | infinity.
+max_download_rate() -> call(max_download_rate).
+
-spec listen_port() -> pos_integer().
listen_port() -> call(port).
@@ -55,6 +55,7 @@
piece_sizes/1,
read_piece/2,
read_chunk/4,
+ aread_chunk/4,
write_chunk/4,
file_paths/1,
file_sizes/1,
@@ -178,6 +179,21 @@ read_chunk(TorrentID, Piece, Offset, Length) ->
BlockList = read_file_blocks(TorrentID, ChunkPositions),
{ok, iolist_to_binary(BlockList)}.
+
+%% @doc Read a chunk from disk and send it to the calling process.
+%% @end
+-spec aread_chunk(torrent_id(), piece_index(),
+ chunk_offset(), chunk_len()) -> {ok, pid()}.
+aread_chunk(TorrentID, Piece, Offset, Length) ->
+ Caller = self(),
+ Pid = spawn_link(fun() ->
+ {ok, Data} = read_chunk(TorrentID, Piece, Offset, Length),
+ ok = etorrent_chunkstate:contents(Piece, Offset, Length, Data, Caller)
+ end),
+ {ok, Pid}.
+
+
+
%% @doc
%% Write a chunk to a piece by writing parts of the block
%% to each file that the block occurs in.
Oops, something went wrong.

0 comments on commit 67fd6ba

Please sign in to comment.