aboutsummaryrefslogtreecommitdiffstats
path: root/erts/preloaded
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
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')
-rw-r--r--erts/preloaded/src/prim_file.erl40
-rw-r--r--erts/preloaded/src/prim_inet.erl25
2 files changed, 58 insertions, 7 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.
%%%
diff --git a/erts/preloaded/src/prim_inet.erl b/erts/preloaded/src/prim_inet.erl
index f144f73d68..015930c0c0 100644
--- a/erts/preloaded/src/prim_inet.erl
+++ b/erts/preloaded/src/prim_inet.erl
@@ -36,7 +36,8 @@
-export([recvfrom/2, recvfrom/3]).
-export([setopt/3, setopts/2, getopt/2, getopts/2, is_sockopt_val/2]).
-export([chgopt/3, chgopts/2]).
--export([getstat/2, getfd/1, getindex/1, getstatus/1, gettype/1,
+-export([getstat/2, getfd/1, stealfd/1, returnfd/1,
+ getindex/1, getstatus/1, gettype/1,
getifaddrs/1, getiflist/1, ifget/3, ifset/3,
gethostname/1]).
-export([getservbyname/3, getservbyport/3]).
@@ -842,6 +843,28 @@ getfd(S) when is_port(S) ->
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
+%% STEALFD(insock()) -> {ok,integer()} | {error, Reason}
+%%
+%% steal internal file descriptor
+%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+stealfd(S) when is_port(S) ->
+ getfd(S).
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%
+%% RETURNFD(insock()) -> {ok,integer()} | {error, Reason}
+%%
+%% return internal file descriptor
+%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+returnfd(S) when is_port(S) ->
+ ok.
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%
%% GETIX(insock()) -> {ok,integer()} | {error, Reason}
%%
%% get internal socket index