aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRaimo Niskanen <[email protected]>2016-06-13 16:36:01 +0200
committerRaimo Niskanen <[email protected]>2016-06-15 08:34:00 +0200
commit853899cd68899713d5c9af69355424eea4086d41 (patch)
treec0c7da3a315d0bc77d818727b3d137f1653de975
parent16e895198a541ccbbbe6c970bd9572cf347a9c77 (diff)
downloadotp-853899cd68899713d5c9af69355424eea4086d41.tar.gz
otp-853899cd68899713d5c9af69355424eea4086d41.tar.bz2
otp-853899cd68899713d5c9af69355424eea4086d41.zip
Handle 'undefined' in fdopen
-rw-r--r--lib/kernel/src/inet.erl67
-rw-r--r--lib/kernel/src/local_tcp.erl2
2 files changed, 35 insertions, 34 deletions
diff --git a/lib/kernel/src/inet.erl b/lib/kernel/src/inet.erl
index 20c64a39ca..9485b02e13 100644
--- a/lib/kernel/src/inet.erl
+++ b/lib/kernel/src/inet.erl
@@ -1345,18 +1345,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 ->
@@ -1374,6 +1368,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);
@@ -1414,34 +1413,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.
diff --git a/lib/kernel/src/local_tcp.erl b/lib/kernel/src/local_tcp.erl
index e3c67dfbb7..90e0fa2162 100644
--- a/lib/kernel/src/local_tcp.erl
+++ b/lib/kernel/src/local_tcp.erl
@@ -175,4 +175,4 @@ accept(L, Timeout) ->
%% Create a port/socket from a file descriptor
%%
fdopen(Fd, Opts) ->
- inet:fdopen(Fd, Opts, ?PROTO, ?FAMILY, ?TYPE, ?MODULE).
+ inet:open(Fd, undefined, 0, Opts, ?PROTO, ?FAMILY, ?TYPE, ?MODULE).