Compare commits

1 Commits

Author SHA1 Message Date
Alexander Heldt
070d5fe910 wip
Some checks failed
test / test (push) Has been cancelled
2025-11-09 18:23:06 +01:00

42
src/ipc.gleam Normal file
View File

@@ -0,0 +1,42 @@
pub type Socket
// https://www.erlang.org/doc/apps/kernel/inet#t:address_family/0
// local socket
type Local {
Local(socket_path: String)
}
type ModeValue {
Binary
}
type GenTcpOption {
Active(Bool)
Mode(ModeValue)
}
pub type ConnectionError {
ConnectionError(String)
}
pub fn connect(socket_path: String) -> Result(Socket, ConnectionError) {
let options = [Mode(Binary), Active(False)]
// timeout in ms
let timeout = 1000
case gen_tcp_connect(Local(socket_path), 0, options, timeout) {
Error(err) -> Error(err)
Ok(socket) -> Ok(socket)
}
}
// connect/4
// https://www.erlang.org/doc/apps/kernel/gen_tcp.html#connect/4
@external(erlang, "gen_tcp", "connect")
fn gen_tcp_connect(
address: Local,
port: Int,
options: List(GenTcpOption),
timeout: Int,
) -> Result(Socket, ConnectionError)