Packages
glisten
4.0.0
9.0.1
9.0.0
9.0.0-rc1
8.0.3
8.0.2
8.0.1
8.0.0
8.0.0-rc1
7.0.1
7.0.0
6.0.0
5.0.0
4.0.0
3.0.0
2.0.0
1.0.0
0.11.0
0.10.2
0.10.1
0.10.0
0.9.3
0.9.2
0.9.1
0.9.0
0.8.2
0.8.1
0.8.0
0.7.0
0.6.9
0.6.8
0.6.7
0.6.6
0.6.5
0.6.4
0.6.3
0.6.2
0.6.1
0.6.0
0.5.1
0.5.0
0.4.0
0.3.2
0.3.1
0.3.0
0.2.2
0.2.1
0.2.0
0.1.3
0.1.2
0.1.1
0.1.0
a shiny Gleam TCP/TLS server
Current section
Files
Jump to
Current section
Files
src/glisten@socket@options.erl
-module(glisten@socket@options).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-export([to_dict/1, merge_with_defaults/1]).
-export_type([socket_mode/0, active_state/0, tcp_option/0]).
-type socket_mode() :: binary.
-type active_state() :: once | passive | {count, integer()} | active.
-type tcp_option() :: {backlog, integer()} |
{nodelay, boolean()} |
{linger, {boolean(), integer()}} |
{send_timeout, integer()} |
{send_timeout_close, boolean()} |
{reuseaddr, boolean()} |
{active_mode, active_state()} |
{mode, socket_mode()} |
{certfile, binary()} |
{keyfile, binary()} |
{alpn_preferred_protocols, list(binary())} |
inet6 |
{buffer, integer()}.
-spec to_dict(list(tcp_option())) -> gleam@dict:dict(gleam@dynamic:dynamic_(), gleam@dynamic:dynamic_()).
to_dict(Options) ->
Opt_decoder = gleam@dynamic:tuple2(
fun gleam@dynamic:dynamic/1,
fun gleam@dynamic:dynamic/1
),
_pipe = Options,
_pipe@1 = gleam@list:map(_pipe, fun(Opt) -> case Opt of
{active_mode, passive} ->
gleam@dynamic:from(
{erlang:binary_to_atom(<<"active"/utf8>>), false}
);
{active_mode, active} ->
gleam@dynamic:from(
{erlang:binary_to_atom(<<"active"/utf8>>), true}
);
{active_mode, {count, N}} ->
gleam@dynamic:from(
{erlang:binary_to_atom(<<"active"/utf8>>), N}
);
{active_mode, once} ->
gleam@dynamic:from(
{erlang:binary_to_atom(<<"active"/utf8>>),
erlang:binary_to_atom(<<"once"/utf8>>)}
);
Other ->
gleam@dynamic:from(Other)
end end),
_pipe@2 = gleam@list:filter_map(_pipe@1, Opt_decoder),
maps:from_list(_pipe@2).
-spec merge_with_defaults(list(tcp_option())) -> list(tcp_option()).
merge_with_defaults(Options) ->
Overrides = to_dict(Options),
_pipe = [{backlog, 1024},
{nodelay, true},
{send_timeout, 30000},
{send_timeout_close, true},
{reuseaddr, true},
{mode, binary},
{active_mode, passive}],
_pipe@1 = to_dict(_pipe),
_pipe@2 = gleam@dict:merge(_pipe@1, Overrides),
_pipe@3 = maps:to_list(_pipe@2),
_pipe@4 = gleam@list:map(_pipe@3, fun gleam@dynamic:from/1),
glisten_ffi:add_inet6(_pipe@4).