Unix Domain Sockets in v19

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Unix Domain Sockets in v19

Shapovalov Taras
Hey guys,

I would like to try the experimental feature of v19 -- unix sockets, but cannot get how it should be used. For example, if I send some request to docker with gen_udp, then I will get  {error,eprototype}:

[taras@dev1 ~]$ erl
Erlang/OTP 19 [erts-8.1] [source] [64-bit] [smp:4:4] [async-threads:10] [kernel-poll:false]

Eshell V8.1  (abort with ^G)
1> {ok, Sockout} = gen_udp:open(0, [{ifaddr, {local, "/tmp/testsockout"}}]).
{ok,#Port<0.413>}
2> gen_udp:send(Sockout, {local, "/var/run/docker.sock"}, 0, "http:/containers/json").
{error,eprototype}
3>

The socket is available and accessable by the user. Say, this works fine:

curl --unix-socket /var/run/docker.sock http:/containers/json

Any idea what is going wrong there?

I will appreciate if someone points me to any documentation (I know the final description of the feature is not ready for now, but maybe there is some draft already exists?).

Also do you know if httpc module supports the unix sockets since 19.0? If yes, how to do the same with httpc?

Best regards,

Taras

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: Unix Domain Sockets in v19

Vans S
    {ok, Socket} = gen_tcp:connect({local, <<"/tmp/unix_socket">>}, 0, [{active, true}, binary], 10000),
    ok = gen_tcp:send(Socket, <<"Hello to socket">>)),

use as regular socket now. Same thing for listening.  Listening will fail if a file exists with same name as the unix_socket.


On Sunday, October 16, 2016 1:35 PM, Taras Shapovalov <[hidden email]> wrote:


Hey guys,

I would like to try the experimental feature of v19 -- unix sockets, but cannot get how it should be used. For example, if I send some request to docker with gen_udp, then I will get  {error,eprototype}:

[taras@dev1 ~]$ erl
Erlang/OTP 19 [erts-8.1] [source] [64-bit] [smp:4:4] [async-threads:10] [kernel-poll:false]

Eshell V8.1  (abort with ^G)
1> {ok, Sockout} = gen_udp:open(0, [{ifaddr, {local, "/tmp/testsockout"}}]).
{ok,#Port<0.413>}
2> gen_udp:send(Sockout, {local, "/var/run/docker.sock"}, 0, "http:/containers/json").
{error,eprototype}
3>

The socket is available and accessable by the user. Say, this works fine:

curl --unix-socket /var/run/docker.sock http:/containers/json

Any idea what is going wrong there?

I will appreciate if someone points me to any documentation (I know the final description of the feature is not ready for now, but maybe there is some draft already exists?).

Also do you know if httpc module supports the unix sockets since 19.0? If yes, how to do the same with httpc?

Best regards,

Taras

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions



_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: Unix Domain Sockets in v19

Peter Lemenkov-3
In reply to this post by Shapovalov Taras
Hello All!
I belive this wasn't standartized prior to documenting, so there might
be some discrepancies. Here is how I send arbitrary data to DGRAM
Unix-socket:

https://gist.github.com/lemenkov/22c4d621b432c3a27574facddd9862f8

{ok, UnixSock} = gen_udp:open(0, [local]),
gen_udp:send(UnixSock, {local, "/dev/log"}, 0, "HELLO").

it works fine.


2016-10-16 19:34 GMT+02:00 Taras Shapovalov <[hidden email]>:

> Hey guys,
>
> I would like to try the experimental feature of v19 -- unix sockets, but
> cannot get how it should be used. For example, if I send some request to
> docker with gen_udp, then I will get  {error,eprototype}:
>
> [taras@dev1 ~]$ erl
> Erlang/OTP 19 [erts-8.1] [source] [64-bit] [smp:4:4] [async-threads:10]
> [kernel-poll:false]
>
> Eshell V8.1  (abort with ^G)
> 1> {ok, Sockout} = gen_udp:open(0, [{ifaddr, {local, "/tmp/testsockout"}}]).
> {ok,#Port<0.413>}
> 2> gen_udp:send(Sockout, {local, "/var/run/docker.sock"}, 0,
> "http:/containers/json").
> {error,eprototype}
> 3>
>
> The socket is available and accessable by the user. Say, this works fine:
>
> curl --unix-socket /var/run/docker.sock http:/containers/json
>
> Any idea what is going wrong there?
>
> I will appreciate if someone points me to any documentation (I know the
> final description of the feature is not ready for now, but maybe there is
> some draft already exists?).
>
> Also do you know if httpc module supports the unix sockets since 19.0? If
> yes, how to do the same with httpc?
>
> Best regards,
>
> Taras
>
> _______________________________________________
> erlang-questions mailing list
> [hidden email]
> http://erlang.org/mailman/listinfo/erlang-questions
>



--
With best regards, Peter Lemenkov.
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: Unix Domain Sockets in v19

Сергей Прохоров-2
In reply to this post by Shapovalov Taras
One more example of UNIX sockets in erl19 there:

http://tryerl.seriyps.ru/#id=6ef3

(see unix_sockets/0 function)

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: Unix Domain Sockets in v19

Raimo Niskanen-2
In reply to this post by Shapovalov Taras
On Sun, Oct 16, 2016 at 08:34:22PM +0300, Taras Shapovalov wrote:

> Hey guys,
>
> I would like to try the experimental feature of v19 -- unix sockets, but
> cannot get how it should be used. For example, if I send some request to
> docker with gen_udp, then I will get  {error,eprototype}:
>
> [taras@dev1 ~]$ erl
> Erlang/OTP 19 [erts-8.1] [source] [64-bit] [smp:4:4] [async-threads:10]
> [kernel-poll:false]
>
> Eshell V8.1  (abort with ^G)
> 1> {ok, Sockout} = gen_udp:open(0, [{ifaddr, {local, "/tmp/testsockout"}}]).
> {ok,#Port<0.413>}
> 2> gen_udp:send(Sockout, {local, "/var/run/docker.sock"}, 0,
> "http:/containers/json").
> {error,eprototype}
> 3>
>
> The socket is available and accessable by the user. Say, this works fine:
>
> curl --unix-socket /var/run/docker.sock http:/containers/json
>
> Any idea what is going wrong there?

You send an UDP datagram to a TCP socket.
Other than that your code looks just fine...

 find /usr/include -type f | xargs fgrep EPROTOTYPE
 :
 /usr/include/asm-generic/errno.h:#define EPROTOTYPE 91 /* Protocol wrong type for socket */

>
> I will appreciate if someone points me to any documentation (I know the
> final description of the feature is not ready for now, but maybe there is
> some draft already exists?).
>
> Also do you know if httpc module supports the unix sockets since 19.0? If
> yes, how to do the same with httpc?

I should pass all options through to gen_tcp, so it is not impossible that
it can handle the 'local' address family.  Give it a try!

>
> Best regards,
>
> Taras


--

/ Raimo Niskanen, Erlang/OTP, Ericsson AB
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: Unix Domain Sockets in v19

Shapovalov Taras
Thank you, guys, for the comments.

I am still staggelling with gen_tcp. It is clear how to use gen_udp for this purpose, but not clear what to do with gen_tcp.

[taras@dev1 ~]$ erl
Erlang/OTP 19 [erts-8.1] [source] [64-bit] [smp:4:4] [async-threads:10] [hipe] [kernel-poll:false]

Eshell V8.1  (abort with ^G)
1> {ok, S1} = gen_tcp:connect({local, <<"/var/run/docker.sock">>}, 0, [local]).                           
{ok,#Port<0.448>}
3> gen_tcp:send(S1, <<"http:/containers/json">>).   
ok
4> A = gen_tcp:recv(S1,0).  
{error,einval}
5>

I don't get how to receive an answer from TCP unix socket.
Should I create one more socket (to listen it) and somehow link them?

I should pass all options through to gen_tcp, so it is not impossible that
it can handle the 'local' address family.  Give it a try!

Would be nice to see it in httpc as well!
 
Best regards,

Taras

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: Unix Domain Sockets in v19

Raimo Niskanen-2
On Tue, Oct 18, 2016 at 09:59:46AM +0300, Taras Shapovalov wrote:

> Thank you, guys, for the comments.
>
> I am still staggelling with gen_tcp. It is clear how to use gen_udp for
> this purpose, but not clear what to do with gen_tcp.
>
> [taras@dev1 ~]$ erl
> Erlang/OTP 19 [erts-8.1] [source] [64-bit] [smp:4:4] [async-threads:10]
> [hipe] [kernel-poll:false]
>
> Eshell V8.1  (abort with ^G)
> 1> {ok, S1} = gen_tcp:connect({local, <<"/var/run/docker.sock">>}, 0,
> [local]).
> {ok,#Port<0.448>}
> 3> gen_tcp:send(S1, <<"http:/containers/json">>).
> ok
> 4> A = gen_tcp:recv(S1,0).
> {error,einval}

To use gen_tcp:recv/2,3 on a socket it has to be opened with option
{active,false}, otherwise you get the messages as process messages.

  http://erlang.org/doc/man/gen_tcp.html#recv-2
    :
    Receives a packet from a socket in passive mode. ...

and the description of process messages under

  http://erlang.org/doc/man/gen_tcp.html#connect-3

> 5>
>
> I don't get how to receive an answer from TCP unix socket.
> Should I create one more socket (to listen it) and somehow link them?
>
> I should pass all options through to gen_tcp, so it is not impossible that
> > it can handle the 'local' address family.  Give it a try!
> >
>
> Would be nice to see it in httpc as well!
>
> Best regards,
>
> Taras

> _______________________________________________
> erlang-questions mailing list
> [hidden email]
> http://erlang.org/mailman/listinfo/erlang-questions


--

/ Raimo Niskanen, Erlang/OTP, Ericsson AB
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: Unix Domain Sockets in v19

Benoit Chesneau-2
In reply to this post by Shapovalov Taras
hackney is supporting local sockets if you need an http client. hackney:get<<"http+unix://...">>

- benoît

On Tue, 18 Oct 2016 at 09:00, Taras Shapovalov <[hidden email]> wrote:
Thank you, guys, for the comments.

I am still staggelling with gen_tcp. It is clear how to use gen_udp for this purpose, but not clear what to do with gen_tcp.

[taras@dev1 ~]$ erl
Erlang/OTP 19 [erts-8.1] [source] [64-bit] [smp:4:4] [async-threads:10] [hipe] [kernel-poll:false]


Eshell V8.1  (abort with ^G)
1> {ok, S1} = gen_tcp:connect({local, <<"/var/run/docker.sock">>}, 0, [local]).                           
{ok,#Port<0.448>}
3> gen_tcp:send(S1, <<"http:/containers/json">>).   
ok
4> A = gen_tcp:recv(S1,0).  
{error,einval}
5>

I don't get how to receive an answer from TCP unix socket.
Should I create one more socket (to listen it) and somehow link them?

I should pass all options through to gen_tcp, so it is not impossible that
it can handle the 'local' address family.  Give it a try!

Would be nice to see it in httpc as well!
 
Best regards,

Taras
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions