Packages

Native desktop GUI framework for Gleam, powered by Iced

Current section

Files

Jump to
plushie_gleam src plushie@socket_adapter.erl
Raw

src/plushie@socket_adapter.erl

-module(plushie@socket_adapter).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/plushie/socket_adapter.gleam").
-export([start/2]).
-export_type([socket/0]).
-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.
?MODULEDOC(
" Bridges a Unix domain socket or TCP connection to the iostream\n"
" transport protocol.\n"
"\n"
" When the renderer uses `--listen`, it creates a socket. This adapter\n"
" connects to that socket and translates between gen_tcp messages and\n"
" the iostream protocol that the Bridge already speaks.\n"
"\n"
" Protocol:\n"
" Bridge sends IoStreamBridge(bridge) on init -> adapter stores it\n"
" Bridge sends IoStreamSend(data) -> adapter writes to socket\n"
" Socket sends tcp data -> adapter forwards as IoStreamData to bridge\n"
" Socket closes -> adapter sends IoStreamClosed to bridge\n"
"\n"
" Implementation uses a raw Erlang gen_server rather than the Gleam\n"
" actor framework, because the adapter must receive both typed\n"
" IoStreamMessage from the bridge subject AND raw gen_tcp messages\n"
" from the socket -- a pattern that doesn't map cleanly to Gleam's\n"
" single-typed actor model.\n"
).
-type socket() :: any().
-file("src/plushie/socket_adapter.gleam", 34).
?DOC(
" Start the socket adapter.\n"
"\n"
" Connects to the given address and returns the adapter's subject,\n"
" which speaks the IoStreamMessage protocol expected by the Bridge.\n"
"\n"
" The address is a Unix socket path (e.g. `/tmp/plushie.sock`),\n"
" a TCP port (e.g. `:4567`), or a TCP host:port (e.g. `127.0.0.1:4567`).\n"
).
-spec start(binary(), plushie@protocol:format()) -> {ok,
gleam@erlang@process:subject(plushie@bridge:io_stream_message())} |
{error, binary()}.
start(Addr, Format) ->
plushie_socket_adapter_ffi:start(Addr, Format).