aboutsummaryrefslogtreecommitdiffstats
path: root/erts/preloaded/src/prim_file.erl
diff options
context:
space:
mode:
authorLukas Larsson <[email protected]>2011-11-25 12:03:58 +0100
committerLukas Larsson <[email protected]>2011-12-01 14:10:02 +0100
commit5ba916ef7ac71bd1e7e23b4c87ae6a472f14fd6c (patch)
treeb00df99199f11dbda4c5a14063b8eefe72e451c1 /erts/preloaded/src/prim_file.erl
parent8beda283543ca89052a5e7ca6491345cd9916eff (diff)
downloadotp-5ba916ef7ac71bd1e7e23b4c87ae6a472f14fd6c.tar.gz
otp-5ba916ef7ac71bd1e7e23b4c87ae6a472f14fd6c.tar.bz2
otp-5ba916ef7ac71bd1e7e23b4c87ae6a472f14fd6c.zip
Create erlang fallback for sendfile
Created erlang fallback for sendfile in gen_tcp and moved sendfile from file to gen_tcp. Also created testcases for testing all different options to sendfile. For info about how sendfile should work see the BSD man pages as they contain a more complete API than other *nixes.
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.
%%%