aboutsummaryrefslogtreecommitdiffstats
path: root/erts/preloaded/src/prim_file.erl
diff options
context:
space:
mode:
Diffstat (limited to 'erts/preloaded/src/prim_file.erl')
-rw-r--r--erts/preloaded/src/prim_file.erl40
1 files changed, 34 insertions, 6 deletions
diff --git a/erts/preloaded/src/prim_file.erl b/erts/preloaded/src/prim_file.erl
index f3f977a30b..606d7d5aab 100644
--- a/erts/preloaded/src/prim_file.erl
+++ b/erts/preloaded/src/prim_file.erl
@@ -27,7 +27,7 @@
%% Generic file contents operations
-export([open/2, close/1, datasync/1, sync/1, advise/4, position/2, truncate/1,
write/2, pwrite/2, pwrite/3, read/2, read_line/1, pread/2, pread/3,
- copy/3, sendfile/5]).
+ copy/3, sendfile/10]).
%% Specialized file operations
-export([open/1, open/3]).
@@ -542,21 +542,49 @@ write_file(_, _) ->
%% Returns {error, Reason} | {ok, BytesCopied}
+sendfile(_,_,_,_,_,_,_,_,_,_) ->
+ {error, enotsup};
sendfile(#file_descriptor{module = ?MODULE, data = {Port, _}},
- DestFD, Offset, Bytes, ChunkSize) ->
+ DestFD, Offset, Bytes, ChunkSize, Headers, Trailers,
+ Nodiskio, MNowait, Sync) ->
+
ok = drv_command(Port, <<?FILE_SENDFILE, DestFD:32, Offset:64, Bytes:64,
- ChunkSize: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;
- Unexpected ->
- Unexpected
+ Error
end.
+get_bit(true) ->
+ 1;
+get_bit(false) ->
+ 0.
+
+encode_hdtl(undefined) ->
+ <<0>>;
+encode_hdtl([]) ->
+ <<0>>;
+encode_hdtl(List) ->
+ encode_hdtl(List,<<>>,0).
+
+encode_hdtl([], Acc, Cnt) ->
+ <<Cnt:8, Acc/binary>>;
+encode_hdtl([Bin|T], Acc, Cnt) ->
+ encode_hdtl(T, <<(byte_size(Bin)):32, Bin/binary, Acc/binary>>,Cnt + 1).
+
+
+
+
+
%%%-----------------------------------------------------------------
%%% Functions operating on files without handle to the file. ?DRV.
%%%