Skip to content
Browse files

Remove close/2; add listen/1

Remove close/2 which removed the Unix socket. Handle the socket deletion
in Erlang. Add listen/1 which uses a default backlog.
  • Loading branch information...
1 parent 3206498 commit fe09a258c02f820b143cedb36d8a5d7843ccad56 @msantos committed
Showing with 17 additions and 25 deletions.
  1. +2 −16 c_src/procket.c
  2. +15 −9 src/procket.erl
View
18 c_src/procket.c
@@ -162,28 +162,15 @@ nif_accept(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
/* 0: file descriptor
- * 1: path to socket
*/
static ERL_NIF_TERM
nif_close(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
{
int sockfd = -1;
- struct sockaddr_un sa = { 0 };
- switch (argc) {
- case 2:
- if (enif_get_string(env, argv[1], sa.sun_path, sizeof(sa.sun_path),
- ERL_NIF_LATIN1) < 1)
- return enif_make_badarg(env);
-
- if (unlink(sa.sun_path) < 0)
- return error_tuple(env, errno);
-
- case 1:
- if (!enif_get_int(env, argv[0], &sockfd))
- return enif_make_badarg(env);
- }
+ if (!enif_get_int(env, argv[0], &sockfd))
+ return enif_make_badarg(env);
if (close(sockfd) < 0)
return error_tuple(env, errno);
@@ -399,7 +386,6 @@ static ErlNifFunc nif_funcs[] = {
{"fdrecv", 1, nif_fdrecv},
{"close", 1, nif_close},
- {"close", 2, nif_close},
{"accept", 2, nif_accept},
{"bind", 2, nif_bind},
{"connect", 2, nif_connect},
View
24 src/procket.erl
@@ -32,13 +32,19 @@
-include("procket.hrl").
-export([
- init/0,open/1,open/2,
- socket/3, listen/2,connect/2,
+ init/0,
+ open/1,open/2,
+ socket/3,
+ listen/1,listen/2,
+ connect/2,
accept/1,accept/2,
- fdopen/1,fdrecv/1,close/1,close/2,
+ fdopen/1,fdrecv/1,
+ close/1,
recv/2,recvfrom/2,recvfrom/4,
- sendto/4,bind/2,
- ioctl/3,setsockopt/4
+ sendto/4,
+ bind/2,
+ ioctl/3,
+ setsockopt/4
]).
-export([make_args/2,progname/0]).
@@ -58,9 +64,6 @@ close(_) ->
fdrecv(_) ->
erlang:error(not_implemented).
-close(_,_) ->
- erlang:error(not_implemented).
-
accept(Socket) ->
accept(Socket, <<>>).
accept(_,_) ->
@@ -72,6 +75,8 @@ bind(_,_) ->
connect(_,_) ->
erlang:error(not_implemented).
+listen(Socket) when is_integer(Socket) ->
+ listen(Socket, ?BACKLOG).
listen(_,_) ->
erlang:error(not_implemented).
@@ -127,7 +132,8 @@ open1(Port, Options) ->
end.
cleanup(Sockfd, Pipe, Options) ->
- close(Sockfd, Pipe),
+ close(Sockfd),
+ ok = file:delete(Pipe),
case proplists:get_value(tmpdir, Options) of
false ->
ok;

0 comments on commit fe09a25

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