diff options
author | Lukas Larsson <[email protected]> | 2011-11-25 10:48:46 +0100 |
---|---|---|
committer | Lukas Larsson <[email protected]> | 2011-12-01 14:10:02 +0100 |
commit | 0348a9c9c0114ddf83d776adc3d01ac60dfcccfc (patch) | |
tree | 109a4d4c9b55d5ef5a4a2cc2f49e9e64a1e748f5 /erts/preloaded | |
parent | 5ba916ef7ac71bd1e7e23b4c87ae6a472f14fd6c (diff) | |
download | otp-0348a9c9c0114ddf83d776adc3d01ac60dfcccfc.tar.gz otp-0348a9c9c0114ddf83d776adc3d01ac60dfcccfc.tar.bz2 otp-0348a9c9c0114ddf83d776adc3d01ac60dfcccfc.zip |
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.
Diffstat (limited to 'erts/preloaded')
-rw-r--r-- | erts/preloaded/src/prim_file.erl | 33 |
1 files changed, 14 insertions, 19 deletions
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, <<?FILE_SENDFILE, DestFD:32, Offset:64, Bytes:64, - ChunkSize:64, - (get_bit(Nodiskio)):1, - (get_bit(MNowait)):1, - (get_bit(Sync)):1,0:5, - (encode_hdtl(Headers))/binary, - (encode_hdtl(Trailers))/binary>>), - 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, <<?FILE_SENDFILE, DestFD:32, Offset:64, Bytes:64, + ChunkSize:64, + (get_bit(Nodiskio)):1, + (get_bit(MNowait)):1, + (get_bit(Sync)):1,0:5, + (encode_hdtl(Headers))/binary, + (encode_hdtl(Trailers))/binary>>). get_bit(true) -> 1; @@ -578,8 +570,11 @@ encode_hdtl(List) -> encode_hdtl([], Acc, Cnt) -> <<Cnt:8, Acc/binary>>; +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). |