aboutsummaryrefslogtreecommitdiffstats
path: root/lib/kernel/src
diff options
context:
space:
mode:
authorLukas Larsson <[email protected]>2011-11-09 11:52:14 +0100
committerLukas Larsson <[email protected]>2011-12-01 14:10:02 +0100
commit54bdd9a15d2e130c76f76ca322af56b306d02078 (patch)
tree13a2f1d7c3d38291464d94b805b63a6feeeaee82 /lib/kernel/src
parentbfa81856150b59ea4578e0eef79b97ab0decb8f7 (diff)
downloadotp-54bdd9a15d2e130c76f76ca322af56b306d02078.tar.gz
otp-54bdd9a15d2e130c76f76ca322af56b306d02078.tar.bz2
otp-54bdd9a15d2e130c76f76ca322af56b306d02078.zip
Implement blocking calls for sendfile
Move sendfile data to invoke data instead of file_descr. Remove usage of ready_output when doing a send. If told to send 0 bytes, file_sendfile now sends the entire file for linux.
Diffstat (limited to 'lib/kernel/src')
-rw-r--r--lib/kernel/src/gen_tcp.erl23
1 files changed, 10 insertions, 13 deletions
diff --git a/lib/kernel/src/gen_tcp.erl b/lib/kernel/src/gen_tcp.erl
index ea25dc3dc3..26afed4ff9 100644
--- a/lib/kernel/src/gen_tcp.erl
+++ b/lib/kernel/src/gen_tcp.erl
@@ -314,14 +314,14 @@ unrecv(S, Data) when is_port(S) ->
%% Send data using sendfile
%%
--define(MAX_CHUNK_SIZE, (1 bsl 30)*2-1).
+-define(MAX_CHUNK_SIZE, (1 bsl 20)*20). %% 20 MB, has to fit in primary memory
-spec sendfile(File, Sock, Offset, Bytes, Opts) ->
{'ok', non_neg_integer()} | {'error', inet:posix()} when
File :: file:io_device(),
Sock :: socket(),
- Offset :: non_neg_integer() | undefined,
- Bytes :: non_neg_integer() | undefined,
+ Offset :: non_neg_integer(),
+ Bytes :: non_neg_integer(),
Opts :: [sendfile_option()].
sendfile(File, Sock, Offset, Bytes, Opts) when is_pid(File) ->
Ref = erlang:monitor(process, File),
@@ -359,8 +359,7 @@ sendfile(File, Sock) ->
{error, Reason} ->
{error, Reason};
{ok, Fd} ->
- {ok, #file_info{size = Bytes}} = file:read_file_info(File),
- Res = sendfile(Fd, Sock, 0, Bytes, []),
+ Res = sendfile(Fd, Sock, 0, 0, []),
file:close(Fd),
Res
end.
@@ -461,21 +460,17 @@ sendfile_fallback(File, Sock, Offset, Bytes, ChunkSize, Headers, Trailers) ->
end.
-sendfile_fallback(File, Sock, undefined, Bytes, ChunkSize) ->
- sendfile_fallback_int(File, Sock, Bytes, ChunkSize, 0);
sendfile_fallback(File, Sock, Offset, Bytes, ChunkSize) ->
- {ok, CurrPos} = file:position(File, 0),
+ {ok, CurrPos} = file:position(File, {cur, 0}),
{ok, _NewPos} = file:position(File, {bof, Offset}),
Res = sendfile_fallback_int(File, Sock, Bytes, ChunkSize, 0),
file:position(File, {bof, CurrPos}),
Res.
-sendfile_fallback_int(_File, _Sock, BytesSent, _ChunkSize, BytesSent) ->
- {ok, BytesSent};
sendfile_fallback_int(File, Sock, Bytes, ChunkSize, BytesSent)
- when Bytes > BytesSent; Bytes == undefined ->
- Size = if Bytes == undefined ->
+ when Bytes > BytesSent; Bytes == 0 ->
+ Size = if Bytes == 0 ->
ChunkSize;
(Bytes - BytesSent + ChunkSize) > 0 ->
Bytes - BytesSent;
@@ -496,7 +491,9 @@ sendfile_fallback_int(File, Sock, Bytes, ChunkSize, BytesSent)
{ok, BytesSent};
Error ->
Error
- end.
+ end;
+sendfile_fallback_int(_File, _Sock, BytesSent, _ChunkSize, BytesSent) ->
+ {ok, BytesSent}.
sendfile_send(Sock, Data, Old) ->
Len = iolist_size(Data),