diff options
author | Micael Karlberg <[email protected]> | 2018-06-07 11:03:27 +0200 |
---|---|---|
committer | Micael Karlberg <[email protected]> | 2018-09-18 13:01:37 +0200 |
commit | 9e0acc8f442549f1f5ee4271816cbfbeb25d8719 (patch) | |
tree | 6910a0423e2ff14880c9eba7d4c9e0148464056f | |
parent | 63338250778d2caad08aa3180b372e5260f22aa7 (diff) | |
download | otp-9e0acc8f442549f1f5ee4271816cbfbeb25d8719.tar.gz otp-9e0acc8f442549f1f5ee4271816cbfbeb25d8719.tar.bz2 otp-9e0acc8f442549f1f5ee4271816cbfbeb25d8719.zip |
[socket-nif-doc] Fixed socket type and function open
The doc for type socket was missing (as it is opaque),
so instead its replaced with a simple text referring
to the functions open and accept.
The open function missed a spec (for open/2), the text
for default protocol needed some omrpvement and finally
the Extra argument needed explaining.
-rw-r--r-- | erts/doc/src/socket.xml | 39 | ||||
-rw-r--r-- | erts/preloaded/src/socket.erl | 54 |
2 files changed, 50 insertions, 43 deletions
diff --git a/erts/doc/src/socket.xml b/erts/doc/src/socket.xml index 9b487172c5..d0a316c4de 100644 --- a/erts/doc/src/socket.xml +++ b/erts/doc/src/socket.xml @@ -47,7 +47,11 @@ <name name="protocol"/> </datatype> <datatype> - <name name="socket"/> + <name>socket()</name> + <desc><p>As returned by + <seealso marker="#open/1"><c>open/2,3,4</c></seealso> and + <seealso marker="#accept/1"><c>accept/1,2</c></seealso>.</p> + </desc> </datatype> <datatype> <name name="ip4_address"/> @@ -134,7 +138,7 @@ <desc> <p>Bind a name to a socket.</p> <p>When a socket is created - (with <seealso marker="#open"><c>open</c></seealso>), + (with <seealso marker="#open/2"><c>open</c></seealso>), it has no address assigned to it. <c>bind</c> assigns the address specified by the <c>Addr</c> argument.</p> <p>The rules used for name binding vary between domains.</p> @@ -199,22 +203,18 @@ <fsummary>Create an endpoint for communication.</fsummary> <desc> <p>Creates an endpoint (socket) for communication.</p> - <p>For some types there is a default protocol, which will + <p>For some <c>types</c> there is a default protocol, which will be used if no protocol is specified: </p> - <taglist> - <tag><c>stream</c></tag> - <item> - <p><c>tcp</c></p> - </item> - <tag><c>dgram</c></tag> - <item> - <p><c>udp</c></p> - </item> - <tag><c>seqpacket</c></tag> - <item> - <p><c>sctp</c></p> - </item> - </taglist> + + <list> + <item><p><c>stream</c>: <c>tcp</c></p></item> + <item><p><c>dgram</c>: <c>udp</c></p></item> + <item><p><c>seqpacket</c>: <c>sctp</c></p></item> + </list> + + <p>The <c>Extra</c> argument is intended for "obscure" options. + Currently the only supported option is <c>netns</c>, which + is only supported on the linux platform.</p> </desc> </func> @@ -282,8 +282,9 @@ <fsummary>Set options on a socket.</fsummary> <desc> <p>Set options on a socket.</p> - <p>What properties are valid depend on what kind of socket - it is (<c>domain</c>, <c>type</c> and <c>protocol</c>).</p> + <p>What properties are valid depend both on <c>Level</c> and on + what kind of socket it is (<c>domain</c>, <c>type</c> and + <c>protocol</c>).</p> <note><p>Not all options are valid on all platforms. That is, even if "we" support an option, that does not mean that the diff --git a/erts/preloaded/src/socket.erl b/erts/preloaded/src/socket.erl index 2942f26505..932048ba75 100644 --- a/erts/preloaded/src/socket.erl +++ b/erts/preloaded/src/socket.erl @@ -518,6 +518,12 @@ info() -> %% open - create an endpoint for communication %% +-spec open(Domain, Type) -> {ok, Socket} | {error, Reason} when + Domain :: domain(), + Type :: type(), + Socket :: socket(), + Reason :: term(). + open(Domain, Type) -> open(Domain, Type, null). @@ -2044,30 +2050,30 @@ flush_select_msgs(LSRef, Ref) -> end. -formated_timestamp() -> - format_timestamp(os:timestamp()). - -format_timestamp(Now) -> - N2T = fun(N) -> calendar:now_to_local_time(N) end, - format_timestamp(Now, N2T, true). - -format_timestamp({_N1, _N2, N3} = N, N2T, true) -> - FormatExtra = ".~.2.0w", - ArgsExtra = [N3 div 10000], - format_timestamp(N, N2T, FormatExtra, ArgsExtra); -format_timestamp({_N1, _N2, _N3} = N, N2T, false) -> - FormatExtra = "", - ArgsExtra = [], - format_timestamp(N, N2T, FormatExtra, ArgsExtra). - -format_timestamp(N, N2T, FormatExtra, ArgsExtra) -> - {Date, Time} = N2T(N), - {YYYY,MM,DD} = Date, - {Hour,Min,Sec} = Time, - FormatDate = - io_lib:format("~.4w-~.2.0w-~.2.0w ~.2.0w:~.2.0w:~.2.0w" ++ FormatExtra, - [YYYY, MM, DD, Hour, Min, Sec] ++ ArgsExtra), - lists:flatten(FormatDate). +%% formated_timestamp() -> +%% format_timestamp(os:timestamp()). + +%% format_timestamp(Now) -> +%% N2T = fun(N) -> calendar:now_to_local_time(N) end, +%% format_timestamp(Now, N2T, true). + +%% format_timestamp({_N1, _N2, N3} = N, N2T, true) -> +%% FormatExtra = ".~.2.0w", +%% ArgsExtra = [N3 div 10000], +%% format_timestamp(N, N2T, FormatExtra, ArgsExtra); +%% format_timestamp({_N1, _N2, _N3} = N, N2T, false) -> +%% FormatExtra = "", +%% ArgsExtra = [], +%% format_timestamp(N, N2T, FormatExtra, ArgsExtra). + +%% format_timestamp(N, N2T, FormatExtra, ArgsExtra) -> +%% {Date, Time} = N2T(N), +%% {YYYY,MM,DD} = Date, +%% {Hour,Min,Sec} = Time, +%% FormatDate = +%% io_lib:format("~.4w-~.2.0w-~.2.0w ~.2.0w:~.2.0w:~.2.0w" ++ FormatExtra, +%% [YYYY, MM, DD, Hour, Min, Sec] ++ ArgsExtra), +%% lists:flatten(FormatDate). %% A timestamp in ms |