[erlang-questions] file:sendfile/2 over unix domain socket

Michael Buhot m.buhot@REDACTED
Mon Mar 26 05:58:21 CEST 2018


I'm getting an {error, badarg} result from file:sendfile/2 when the socket
argument was originally accepted from a unix domain socket.
The elixir script below demonstrates the problem:

require Logger

File.rm("local.sock")
File.write!("tmp.txt", "Hello World\n")

{:ok, socket} = :gen_tcp.listen(0, [:binary, packet: :line, active: false,
ip: {:local, "local.sock"}])
#  {:ok, socket} = :gen_tcp.listen(4000, [:binary, packet: :line, active:
false])

{:ok, client} = :gen_tcp.accept(socket)
case :file.sendfile("tmp.txt", client) do
    {:ok, sent} ->
        Logger.info("sent #{sent} bytes")
    error ->
        Logger.error(inspect(error))
end

Swapping the call to gen_tcp:listen with the version using tcp port 4000
works successfully.
Should file:sendfile/2 work with unix domain sockets?

Thanks
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20180326/fd1c217b/attachment.htm>


More information about the erlang-questions mailing list