From 0348a9c9c0114ddf83d776adc3d01ac60dfcccfc Mon Sep 17 00:00:00 2001 From: Lukas Larsson Date: Fri, 25 Nov 2011 10:48:46 +0100 Subject: Implement sendfile using blocking io in asynch threads Move the command handling to outputv in preparation for header and trailer inclusion in the sendfile api. Use the standard efile communication functions for sendfile. --- erts/preloaded/src/prim_file.erl | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-) (limited to 'erts/preloaded') diff --git a/erts/preloaded/src/prim_file.erl b/erts/preloaded/src/prim_file.erl index 606d7d5aab..0767067682 100644 --- a/erts/preloaded/src/prim_file.erl +++ b/erts/preloaded/src/prim_file.erl @@ -539,30 +539,22 @@ write_file(File, Bin) when (is_list(File) orelse is_binary(File)) -> end; write_file(_, _) -> {error, badarg}. - + %% Returns {error, Reason} | {ok, BytesCopied} -sendfile(_,_,_,_,_,_,_,_,_,_) -> - {error, enotsup}; +%sendfile(_,_,_,_,_,_,_,_,_,_) -> +% {error, enotsup}; sendfile(#file_descriptor{module = ?MODULE, data = {Port, _}}, DestFD, Offset, Bytes, ChunkSize, Headers, Trailers, Nodiskio, MNowait, Sync) -> - ok = drv_command(Port, <>), - Self = self(), - %% Should we use a ref()? - receive - {efile_reply, Self, Port, {ok, _Written}=OKRes}-> - OKRes; - {efile_reply, Self, Port, {error, _PosixError}=Error}-> - Error - end. + drv_command(Port, <>). get_bit(true) -> 1; @@ -578,8 +570,11 @@ encode_hdtl(List) -> encode_hdtl([], Acc, Cnt) -> <>; +encode_hdtl([Bin|T], Acc, Cnt) when is_binary(Bin) -> + encode_hdtl(T, <<(byte_size(Bin)):32, Bin/binary, Acc/binary>>,Cnt + 1); encode_hdtl([Bin|T], Acc, Cnt) -> - encode_hdtl(T, <<(byte_size(Bin)):32, Bin/binary, Acc/binary>>,Cnt + 1). + encode_hdtl(T, <<(iolist_size(Bin)):32, (iolist_to_binary(Bin))/binary, + Acc/binary>>,Cnt + 1). -- cgit v1.2.3