aboutsummaryrefslogtreecommitdiffstats
path: root/lib/kernel/src/inet.erl
diff options
context:
space:
mode:
authorRaimo Niskanen <[email protected]>2016-06-17 10:35:02 +0200
committerRaimo Niskanen <[email protected]>2016-06-17 10:35:02 +0200
commit79e72ea213a7ddc22cbd77102f57be2c9f528645 (patch)
tree29ce99f52cbbffb85b19596ef4258c42c05fead3 /lib/kernel/src/inet.erl
parentf8d466b82f156e656371ab4c0f5af34217cbd655 (diff)
parenta3626105809abf8be1869f6b0725b6cfa912dedd (diff)
downloadotp-79e72ea213a7ddc22cbd77102f57be2c9f528645.tar.gz
otp-79e72ea213a7ddc22cbd77102f57be2c9f528645.tar.bz2
otp-79e72ea213a7ddc22cbd77102f57be2c9f528645.zip
Merge branch 'raimo/uds-support/OTP-13643'
* raimo/uds-support/OTP-13643: Update test cases after daily builds Return eafnosupport when not supported Add AF_LOCAL test cases Handle 'undefined' in fdopen
Diffstat (limited to 'lib/kernel/src/inet.erl')
-rw-r--r--lib/kernel/src/inet.erl67
1 files changed, 34 insertions, 33 deletions
diff --git a/lib/kernel/src/inet.erl b/lib/kernel/src/inet.erl
index 9fc685e728..a91a6ed517 100644
--- a/lib/kernel/src/inet.erl
+++ b/lib/kernel/src/inet.erl
@@ -1344,18 +1344,12 @@ open(FdO, Addr, Port, Opts, Protocol, Family, Type, Module)
case prim_inet:open(Protocol, Family, Type, OpenOpts) of
{ok,S} ->
case prim_inet:setopts(S, Opts) of
+ ok when Addr =:= undefined ->
+ inet_db:register_socket(S, Module),
+ {ok,S};
ok ->
- case
- case Addr of
- undefined ->
- {ok, undefined};
- _ when is_list(Addr) ->
- bindx(S, Addr, Port);
- _ ->
- prim_inet:bind(S, Addr, Port)
- end
- of
- {ok, _} ->
+ case bind(S, Addr, Port) of
+ {ok, _} ->
inet_db:register_socket(S, Module),
{ok,S};
Error ->
@@ -1373,6 +1367,11 @@ open(Fd, Addr, Port, Opts, Protocol, Family, Type, Module)
when is_integer(Fd) ->
fdopen(Fd, Addr, Port, Opts, Protocol, Family, Type, Module).
+bind(S, Addr, Port) when is_list(Addr) ->
+ bindx(S, Addr, Port);
+bind(S, Addr, Port) ->
+ prim_inet:bind(S, Addr, Port).
+
bindx(S, [Addr], Port0) ->
{IP, Port} = set_bindx_port(Addr, Port0),
prim_inet:bind(S, IP, Port);
@@ -1413,34 +1412,36 @@ fdopen(Fd, Opts, Protocol, Family, Type, Module) ->
fdopen(Fd, any, 0, Opts, Protocol, Family, Type, Module).
fdopen(Fd, Addr, Port, Opts, Protocol, Family, Type, Module) ->
- IsAnyAddr = (Addr == {0,0,0,0} orelse Addr == {0,0,0,0,0,0,0,0}
- orelse Addr == any),
- Bound = Port == 0 andalso IsAnyAddr,
+ Bound =
+ %% We do not do any binding if default port+addr options
+ %% were given, in order to keep backwards compatability
+ %% with pre Erlang/OTP 17
+ case Addr of
+ {0,0,0,0} when Port =:= 0 -> true;
+ {0,0,0,0,0,0,0,0} when Port =:= 0 -> true;
+ any when Port =:= 0 -> true;
+ _ -> false
+ end,
case prim_inet:fdopen(Protocol, Family, Type, Fd, Bound) of
{ok, S} ->
case prim_inet:setopts(S, Opts) of
+ ok
+ when Addr =:= undefined;
+ Bound ->
+ inet_db:register_socket(S, Module),
+ {ok, S};
ok ->
- case if
- Bound ->
- %% We do not do any binding if default
- %% port+addr options where given in order
- %% to keep backwards compatability with
- %% pre Erlang/TOP 17
- {ok, ok};
- is_list(Addr) ->
- bindx(S, Addr, Port);
- true ->
- prim_inet:bind(S, Addr, Port)
- end of
- {ok, _} ->
- inet_db:register_socket(S, Module),
- {ok, S};
- Error ->
- prim_inet:close(S),
- Error
+ case bind(S, Addr, Port) of
+ {ok, _} ->
+ inet_db:register_socket(S, Module),
+ {ok, S};
+ Error ->
+ prim_inet:close(S),
+ Error
end;
Error ->
- prim_inet:close(S), Error
+ prim_inet:close(S),
+ Error
end;
Error -> Error
end.