Compare commits
1 Commits
4e95c440d3
...
070d5fe910
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
070d5fe910 |
42
src/ipc.gleam
Normal file
42
src/ipc.gleam
Normal 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)
|
||||||
Reference in New Issue
Block a user