Skip to content
Browse files

first commit

  • Loading branch information...
0 parents commit 2971dbaa5739ff5535cb9d1fb22797016580ea45 @tonyrog committed
Showing with 5,678 additions and 0 deletions.
  1. 0 README.md
  2. +5,514 −0 c_src/afunix_drv.c
  3. +2 −0 ebin/.gitignore
  4. +1 −0 priv/.gitignore
  5. 0 rebar.config
  6. +8 −0 src/afunix.app.src
  7. +153 −0 src/afunix.erl
0 README.md
No changes.
5,514 c_src/afunix_drv.c
5,514 additions, 0 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
2 ebin/.gitignore
@@ -0,0 +1,2 @@
+*.beam
+*.app
1 priv/.gitignore
@@ -0,0 +1 @@
+*.so
0 rebar.config
No changes.
8 src/afunix.app.src
@@ -0,0 +1,8 @@
+{application, afunix,
+ [{description, "AF_UNIX socket driver"},
+ {vsn, git},
+ {modules, [afunix]},
+ {registered, []},
+ {env, []},
+ {applications,[kernel,stdlib]}
+ ]}.
153 src/afunix.erl
@@ -0,0 +1,153 @@
+%%
+%% %CopyrightBegin%
+%%
+%% Copyright Ericsson AB 1997-2011. All Rights Reserved.
+%%
+%% The contents of this file are subject to the Erlang Public License,
+%% Version 1.1, (the "License"); you may not use this file except in
+%% compliance with the License. You should have received a copy of the
+%% Erlang Public License along with this software. If not, it can be
+%% retrieved online at http://www.erlang.org/.
+%%
+%% Software distributed under the License is distributed on an "AS IS"
+%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
+%% the License for the specific language governing rights and limitations
+%% under the License.
+%%
+%% %CopyrightEnd%
+%%
+-module(afunix).
+
+%% Socket server for TCP/IP
+
+-export([connect/3, connect/4, listen/2, accept/1, accept/2, close/1]).
+-export([send/2, send/3, recv/2, recv/3, unrecv/2]).
+-export([shutdown/2]).
+-export([controlling_process/2]).
+-export([fdopen/2]).
+
+-export([getserv/1, getaddr/1, getaddr/2, getaddrs/1, getaddrs/2]).
+
+
+-include_lib("kernel/src/inet_int.hrl").
+
+%% inet_tcp port lookup
+getserv(Port) when is_integer(Port) -> {ok, Port};
+getserv(Name) when is_atom(Name) -> inet:getservbyname(Name,tcp).
+
+%% inet_tcp address lookup
+getaddr(Address) -> inet:getaddr(Address, inet).
+getaddr(Address,Timer) -> inet:getaddr_tm(Address, inet, Timer).
+
+%% inet_tcp address lookup
+getaddrs(Address) -> inet:getaddrs(Address, inet).
+getaddrs(Address,Timer) -> inet:getaddrs_tm(Address,inet,Timer).
+
+%%
+%% Send data on a socket
+%%
+send(Socket, Packet, Opts) -> prim_inet:send(Socket, Packet, Opts).
+send(Socket, Packet) -> prim_inet:send(Socket, Packet, []).
+
+%%
+%% Receive data from a socket (inactive only)
+%%
+recv(Socket, Length) -> prim_inet:recv(Socket, Length).
+recv(Socket, Length, Timeout) -> prim_inet:recv(Socket, Length, Timeout).
+
+unrecv(Socket, Data) -> prim_inet:unrecv(Socket, Data).
+
+%%
+%% Shutdown one end of a socket
+%%
+shutdown(Socket, How) ->
+ prim_inet:shutdown(Socket, How).
+
+%%
+%% Close a socket (async)
+%%
+close(Socket) ->
+ inet:tcp_close(Socket).
+
+%%
+%% Set controlling process
+%%
+controlling_process(Socket, NewOwner) ->
+ inet:tcp_controlling_process(Socket, NewOwner).
+
+%%
+%% Connect
+%%
+connect(Address, Port, Opts) ->
+ do_connect(Address, Port, Opts, infinity).
+
+connect(Address, Port, Opts, infinity) ->
+ do_connect(Address, Port, Opts, infinity);
+connect(Address, Port, Opts, Timeout) when is_integer(Timeout),
+ Timeout >= 0 ->
+ do_connect(Address, Port, Opts, Timeout).
+
+do_connect({A,B,C,D}, Port, Opts, Time) when ?ip(A,B,C,D), ?port(Port) ->
+ case inet:connect_options(Opts, inet) of
+ {error, Reason} -> exit(Reason);
+ {ok, #connect_opts{fd=Fd,
+ ifaddr=BAddr={Ab,Bb,Cb,Db},
+ port=BPort,
+ opts=SockOpts}}
+ when ?ip(Ab,Bb,Cb,Db), ?port(BPort) ->
+ case inet:open(Fd,BAddr,BPort,SockOpts,tcp,inet,stream,?MODULE) of
+ {ok, S} ->
+ case prim_inet:connect(S, {A,B,C,D}, Port, Time) of
+ ok -> {ok,S};
+ Error -> prim_inet:close(S), Error
+ end;
+ Error -> Error
+ end;
+ {ok, _} -> exit(badarg)
+ end.
+
+%%
+%% Listen
+%%
+listen(Port, Opts) ->
+ case inet:listen_options([{port,Port} | Opts], inet) of
+ {error,Reason} -> exit(Reason);
+ {ok, #listen_opts{fd=Fd,
+ ifaddr=BAddr={A,B,C,D},
+ port=BPort,
+ opts=SockOpts}=R}
+ when ?ip(A,B,C,D), ?port(BPort) ->
+ case inet:open(Fd,BAddr,BPort,SockOpts,tcp,inet,stream,?MODULE) of
+ {ok, S} ->
+ case prim_inet:listen(S, R#listen_opts.backlog) of
+ ok -> {ok, S};
+ Error -> prim_inet:close(S), Error
+ end;
+ Error -> Error
+ end;
+ {ok, _} -> exit(badarg)
+ end.
+
+%%
+%% Accept
+%%
+accept(L) ->
+ case prim_inet:accept(L) of
+ {ok, S} ->
+ inet_db:register_socket(S, ?MODULE),
+ {ok,S};
+ Error -> Error
+ end.
+
+accept(L,Timeout) ->
+ case prim_inet:accept(L,Timeout) of
+ {ok, S} ->
+ inet_db:register_socket(S, ?MODULE),
+ {ok,S};
+ Error -> Error
+ end.
+%%
+%% Create a port/socket from a file descriptor
+%%
+fdopen(Fd, Opts) ->
+ inet:fdopen(Fd, Opts, tcp, inet, stream, ?MODULE).

0 comments on commit 2971dba

Please sign in to comment.
Something went wrong with that request. Please try again.