diff options
author | Lukas Larsson <[email protected]> | 2011-11-27 17:24:04 +0100 |
---|---|---|
committer | Lukas Larsson <[email protected]> | 2011-12-02 10:39:38 +0100 |
commit | 4d198cb07025a8fc341a1e7fd7f9906b5fb714d6 (patch) | |
tree | ee5b540ade5b8b6a965cee3d7b6b4619ddc60e23 /erts/preloaded | |
parent | 836410f5c9e092be4b77b26b3fc9f7abde0c89de (diff) | |
download | otp-4d198cb07025a8fc341a1e7fd7f9906b5fb714d6.tar.gz otp-4d198cb07025a8fc341a1e7fd7f9906b5fb714d6.tar.bz2 otp-4d198cb07025a8fc341a1e7fd7f9906b5fb714d6.zip |
Only allow tcp sockets as target for sendfile
Diffstat (limited to 'erts/preloaded')
-rw-r--r-- | erts/preloaded/src/prim_file.erl | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/erts/preloaded/src/prim_file.erl b/erts/preloaded/src/prim_file.erl index fb19521382..6f35162feb 100644 --- a/erts/preloaded/src/prim_file.erl +++ b/erts/preloaded/src/prim_file.erl @@ -545,17 +545,24 @@ write_file(_, _) -> %sendfile(_,_,_,_,_,_,_,_,_,_) -> % {error, enotsup}; sendfile(#file_descriptor{module = ?MODULE, data = {Port, _}}, - DestFD, Offset, Bytes, ChunkSize, Headers, Trailers, - Nodiskio, MNowait, Sync) -> - drv_command(Port, [<<?FILE_SENDFILE, DestFD:32, - (get_bit(Nodiskio)):1, - (get_bit(MNowait)):1, - (get_bit(Sync)):1,0:5, - Offset:64/unsigned, - Bytes:64/unsigned, - (iolist_size(Headers)):32/unsigned, - (iolist_size(Trailers)):32/unsigned>>, - Headers,Trailers]). + Dest, Offset, Bytes, _ChunkSize, _Headers, _Trailers, + _Nodiskio, _MNowait, _Sync) -> + case erlang:port_get_data(Dest) of + Data when Data == inet_tcp; Data == inet6_tcp -> + ok = inet:lock_socket(Dest,true), + {ok, DestFD} = prim_inet:getfd(Dest), + try drv_command(Port, [<<?FILE_SENDFILE, DestFD:32, + 0:8, + Offset:64/unsigned, + Bytes:64/unsigned, + 0:32/unsigned, + 0:32/unsigned>>]) + after + ok = inet:lock_socket(Dest,false) + end; + _Else -> + {error,badarg} + end. get_bit(true) -> 1; |