Giter Club home page Giter Club logo

afunix's Introduction

The ultimate afunix documentation

afunix is an api to unix domain sockets. The afunix is a "plugin" to the inet/gen_tcp. The api is binary compatible with the gen_tcp interface. The afunix is not available on the windows platform, hence the unix part of afunix.

To connect to a unix domain socket you do

afunix:connect(Name, Options) -> {ok,socket()} | {error,posix_error()}

To start a unix domain socket server you do

afunix:listen(Name, Options) ->  {ok,socket()} | {error,posix_error()}

From there on you can use the "normal" inet and gen_tcp interface.

Example:

Shell 1:

1> {ok,L} = afunix:listen("/tmp/foo", []).
{ok,#Port<0.2229>}
2> {ok,S} = gen_tcp:accept(L).

Shell 2:

1> {ok,S} = afunix:connect("/tmp/foo", []).
{ok,#Port<0.2229>}
2> afunix:send(S, "Hello").
ok
3> gen_tcp:send(S, "Hej").        
ok

Shell 1:

{ok,#Port<0.2244>}
3> flush().
Shell got {tcp,#Port<0.2244>,"Hello"}
Shell got {tcp,#Port<0.2244>,"Hej"}
ok

It is also possible to use the corresponding afunix module functions, the following functions are avaiable

afunix:connect(Name::string(),Options::[connect_option()]).
afunix:connect(Name::string(),Options::[connect_option()],Tmo::timeout()).
afunix:listen(Name::string(), Options::[listen_option()]).
afunix:accept(ListenSocket::socket())
afunix:accept(ListenSocket::socket(), Tmo::timeout())
afunix:close(Socket::socket()).
afunix:send(Socket::socket(), Packet::iodata()).
afunix:send(Socket::socket(), Packet::iodata(), Options).
afunix:recv(Socket::socket(), Length::non_neg_integer()).
afunix:recv(Socket::socket(), Length::non_neg_integer(),Tmo::timeout()).
afunix:unrecv(Socket::socket(), Data::iodata()).
afunix:shutdown(Socket::socket(), read|write|read_write).
afunix:controlling_process(Socket::socket(), Pid::pid()).
afunix:fdopen(Fd::integer(), Options).

Special api functions

afunix:get_peercred(Socket::socket())

get_peercred return {ok,Uid}, the effective user id of the socket peer, or {error,Reason}.

afunix:get_peerpid(Socket::socket())

get_peerpid return {ok,Pid}, the process id of the socket peer, or {error,Reason}.

afunix's People

Contributors

tonyrog avatar potatosalad avatar tolbrino avatar shpaky avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.