Skip to content

Commit afe5b9f

Browse files
committed
More scaffolding—found some pain points to address
1 parent 8008360 commit afe5b9f

File tree

6 files changed

+66
-6
lines changed

6 files changed

+66
-6
lines changed

lib/tcp/accepter_pool_impl.ex

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
defmodule Tcp.AccepterPoolImpl do
2+
use Tcp.ListenerChor.Chorex, :accepterpool
3+
4+
def spawn_handler(_socket) do
5+
# startup instance of the handler choreography
6+
end
7+
end

lib/tcp/client_impl.ex

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
defmodule Tcp.ClientImpl do
2+
use Tcp.HandlerChor.Chorex, :tcpclient
3+
4+
def send_over_socket(_sock, _msg) do
5+
end
6+
end

lib/tcp/handler_chor.ex

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,49 @@ defmodule Tcp.HandlerChor do
22
import Chorex
33

44
defchor [Handler, TcpClient] do
5-
def loop(Handler.(_x)) do
5+
def loop(TcpClient.(sock)) do
66
with Handler.(resp) <- Handler.run() do
77
if Handler.continue?(resp) do
88
Handler[L] ~> TcpClient
99
Handler.fmt_reply(resp) ~> TcpClient.(resp)
10-
TcpClient.send(resp)
11-
loop(Handler.(nil))
10+
TcpClient.send_over_socket(sock, resp)
11+
loop(TcpClient.(sock))
1212
else
1313
Handler[R] ~> TcpClient
1414
Handler.fmt_reply(resp) ~> TcpClient.(resp)
15-
TcpClient.send(resp)
15+
TcpClient.send_over_socket(sock, resp)
1616
end
1717
end
1818
end
1919

20-
loop(Handler.(nil))
20+
def init(TcpClient.(sock)) do
21+
loop(TcpClient.(sock))
22+
end
2123
end
24+
25+
# quote do
26+
# defchor [Handler, TcpClient] do
27+
# def loop(TcpClient.(sock)) do
28+
# with Handler.(resp) <- Handler.run() do
29+
# if Handler.continue?(resp) do
30+
# Handler[L] ~> TcpClient
31+
# Handler.fmt_reply(resp) ~> TcpClient.(resp)
32+
# TcpClient.send_over_socket(sock, resp)
33+
# loop(TcpClient.(sock))
34+
# else
35+
# Handler[R] ~> TcpClient
36+
# Handler.fmt_reply(resp) ~> TcpClient.(resp)
37+
# TcpClient.send_over_socket(sock, resp)
38+
# end
39+
# end
40+
# end
41+
42+
# def init(TcpClient.(sock)) do
43+
# loop(TcpClient.(sock))
44+
# end
45+
# end
46+
# end
47+
# |> Macro.expand_once(__ENV__)
48+
# |> Macro.to_string()
49+
# |> IO.puts()
2250
end

lib/tcp/handler_impl.ex

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
defmodule Tcp.HandlerImpl do
2+
use Tcp.HandlerChor.Chorex, :handler
3+
4+
def run() do
5+
end
6+
7+
def continue?({:continue, _resp}), do: true
8+
def continue?({:halt, _resp}), do: false
9+
10+
def fmt_reply({_status, resp}), do: resp
11+
12+
end

lib/tcp/listener_chor.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ defmodule Tcp.ListenerChor do
22
import Chorex
33

44
defchor [Listener, AccepterPool] do
5-
def loop(Listener.(_x)) do # FIXME: functions without an argument; or is it that all branches loop?
5+
def loop(Listener.(_x)) do
66
Listener.await_connection() ~> AccepterPool.(socket)
77
AccepterPool.spawn_handler(socket)
88
loop(Listener.(nil))

lib/tcp/listener_impl.ex

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
defmodule Tcp.ListenerImpl do
2+
use Tcp.ListenerChor.Chorex, :listener
3+
4+
def await_connection() do
5+
42
6+
end
7+
end

0 commit comments

Comments
 (0)