Packages
glisten
0.3.2
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.erl
-module(glisten).
-compile(no_auto_import).
-export([serve/3]).
-export_type([start_error/0]).
-type start_error() :: listener_closed |
listener_timeout |
acceptor_timeout |
{acceptor_failed, gleam@otp@process:exit_reason()} |
{acceptor_crashed, gleam@dynamic:dynamic()}.
-spec serve(
integer(),
fun((glisten@tcp:handler_message(), glisten@tcp:loop_state(GVG)) -> gleam@otp@actor:next(glisten@tcp:loop_state(GVG))),
GVG
) -> {ok, nil} | {error, start_error()}.
serve(Port, Handler, Initial_state) ->
case begin
_pipe = Port,
_pipe@1 = glisten@tcp:listen(_pipe, []),
_pipe@2 = gleam@result:map_error(_pipe@1, fun(Err) -> case Err of
closed ->
listener_closed;
timeout ->
listener_timeout
end end),
gleam@result:then(
_pipe@2,
fun(Socket) ->
_pipe@3 = Socket,
_pipe@4 = glisten@tcp:start_acceptor_pool(
_pipe@3,
Handler,
Initial_state,
10
),
gleam@result:map_error(_pipe@4, fun(Err@1) -> case Err@1 of
init_timeout ->
acceptor_timeout;
{init_failed, Reason} ->
{acceptor_failed, Reason};
{init_crashed, Reason@1} ->
{acceptor_crashed, Reason@1}
end end)
end
)
end of
{error, _try} -> {error, _try};
{ok, _@1} ->
{ok, nil}
end.