[erlang-questions] prim_inet socket incompatible with file:sendfile/2/5

57 views
Skip to first unread message

Zabrane Mickael

unread,
Jul 27, 2012, 12:57:00 PM7/27/12
to Erlang Questions
Hi,

Is there any reason why a client socket created from prim_inet 
do not work with the new file:sendfile fonction?

I got {error, badarg}.

Any undocumented function to solves this?

Regards,
Zabrane

Lukas Larsson

unread,
Aug 8, 2012, 5:00:21 AM8/8/12
to Zabrane Mickael, Erlang Questions
Hi!

There are a couple of reasons why this might not work. Could you show
me a small example of what you are trying to do?

Lukas
> _______________________________________________
> erlang-questions mailing list
> erlang-q...@erlang.org
> http://erlang.org/mailman/listinfo/erlang-questions
>
_______________________________________________
erlang-questions mailing list
erlang-q...@erlang.org
http://erlang.org/mailman/listinfo/erlang-questions

Zabrane Mickael

unread,
Aug 12, 2012, 6:06:57 PM8/12/12
to Lukas Larsson, Erlang Questions
Hi Lukas,

Sorry for the late response.

Please find attached a minimalistic example.

1> prim_sendfile:start().

and try:
curl http://127.0.0.1:8080/

Nothing happens.
What am I doing wrong?

If I use the standard gen_tcp:accept/1, gen_tcp:recv/2, gen_tcp:send/2 on the socket, sendfile works as expected.
But not with a socket handled by prim_inet. Why?

Thanks for your help.

Regards,
Zabrane


prim_sendfile.erl

Lukas Larsson

unread,
Aug 13, 2012, 4:40:26 AM8/13/12
to Zabrane Mickael, Erlang Questions
Hi,

When using the prim_inet API you have to be careful with what you
remove. In this case you have to call
`erlang:port_set_data(CSock,inet_tcp)` after accepting the socket. The
port data is used by erlang code to figure out which type of socket
the port represents.

Lukas

Zabrane Mickael

unread,
Aug 13, 2012, 5:06:47 AM8/13/12
to Lukas Larsson, Erlang Questions
Hi Lukas,

Perfect now.
Anything else I should know avour prim_inet usage?

Regards,
Zabrane
Reply all
Reply to author
Forward
0 new messages