From 9e0acc8f442549f1f5ee4271816cbfbeb25d8719 Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Thu, 7 Jun 2018 11:03:27 +0200 Subject: [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. --- erts/doc/src/socket.xml | 39 ++++++++++++++++--------------- 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 @@ - + socket() +

As returned by + open/2,3,4 and + accept/1,2.

+
@@ -134,7 +138,7 @@

Bind a name to a socket.

When a socket is created - (with open), + (with open), it has no address assigned to it. bind assigns the address specified by the Addr argument.

The rules used for name binding vary between domains.

@@ -199,22 +203,18 @@ Create an endpoint for communication.

Creates an endpoint (socket) for communication.

-

For some types there is a default protocol, which will +

For some types there is a default protocol, which will be used if no protocol is specified:

- - stream - -

tcp

-
- dgram - -

udp

-
- seqpacket - -

sctp

-
-
+ + +

stream: tcp

+

dgram: udp

+

seqpacket: sctp

+
+ +

The Extra argument is intended for "obscure" options. + Currently the only supported option is netns, which + is only supported on the linux platform.

@@ -282,8 +282,9 @@ Set options on a socket.

Set options on a socket.

-

What properties are valid depend on what kind of socket - it is (domain, type and protocol).

+

What properties are valid depend both on Level and on + what kind of socket it is (domain, type and + protocol).

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 -- cgit v1.2.3