aboutsummaryrefslogtreecommitdiffstats
path: root/lib/kernel/src/file.erl
diff options
context:
space:
mode:
authorJohn Högberg <[email protected]>2017-11-02 21:27:56 +0100
committerJohn Högberg <[email protected]>2017-11-30 15:44:39 +0100
commit8e634f0063acb8009c2afb303111a2fd35aad78b (patch)
tree9f2221d07b699d695e831ed2581753e363ebe80a /lib/kernel/src/file.erl
parentc9fc20af633bbdc68206ca7d7438cd803793875f (diff)
downloadotp-8e634f0063acb8009c2afb303111a2fd35aad78b.tar.gz
otp-8e634f0063acb8009c2afb303111a2fd35aad78b.tar.bz2
otp-8e634f0063acb8009c2afb303111a2fd35aad78b.zip
Make file:sendfile/5 follow its documented error behavior
Diffstat (limited to 'lib/kernel/src/file.erl')
-rw-r--r--lib/kernel/src/file.erl21
1 files changed, 12 insertions, 9 deletions
diff --git a/lib/kernel/src/file.erl b/lib/kernel/src/file.erl
index b5a51c3410..d05199897f 100644
--- a/lib/kernel/src/file.erl
+++ b/lib/kernel/src/file.erl
@@ -1236,15 +1236,18 @@ sendfile(File, _Sock, _Offet, _Bytes, _Opts) when is_pid(File) ->
sendfile(File, Sock, Offset, Bytes, []) ->
sendfile(File, Sock, Offset, Bytes, ?MAX_CHUNK_SIZE, [], [], []);
sendfile(File, Sock, Offset, Bytes, Opts) ->
- ChunkSize0 = proplists:get_value(chunk_size, Opts, ?MAX_CHUNK_SIZE),
- ChunkSize = if ChunkSize0 > ?MAX_CHUNK_SIZE ->
- ?MAX_CHUNK_SIZE;
- true -> ChunkSize0
- end,
- %% Support for headers, trailers and options has been removed because the
- %% Darwin and BSD API for using it does not play nice with
- %% non-blocking sockets. See unix_efile.c for more info.
- sendfile(File, Sock, Offset, Bytes, ChunkSize, [], [], Opts).
+ try proplists:get_value(chunk_size, Opts, ?MAX_CHUNK_SIZE) of
+ ChunkSize0 when is_integer(ChunkSize0) ->
+ ChunkSize = erlang:min(ChunkSize0, ?MAX_CHUNK_SIZE),
+ %% Support for headers, trailers and options has been removed
+ %% because the Darwin and BSD API for using it does not play nice
+ %% with non-blocking sockets. See unix_efile.c for more info.
+ sendfile(File, Sock, Offset, Bytes, ChunkSize, [], [], Opts);
+ _Other ->
+ {error, badarg}
+ catch
+ error:_ -> {error, badarg}
+ end.
%% sendfile/2
-spec sendfile(Filename, Socket) ->