file:sendfile/2 over unix domain socket

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

file:sendfile/2 over unix domain socket

Michael Buhot
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.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} ->"sent #{sent} bytes")
    error ->

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?


erlang-questions mailing list
[hidden email]