deleting relay logic
This commit is contained in:
parent
2037444f54
commit
f0725700f0
93
README.md
93
README.md
@ -629,3 +629,96 @@ index 242c82f..3a724b0 100644
|
||||
|
||||
-spec stop(term()) -> ok.
|
||||
```
|
||||
|
||||
### Deleting the relay logic
|
||||
|
||||
- Start commit: `2037444f54d8f95a959c7e67673d55782fad5ad3`
|
||||
|
||||
```diff
|
||||
diff --git a/gex_httpd/src/gh_client.erl b/gex_httpd/src/gh_client.erl
|
||||
index ea5b3ef..44d206d 100644
|
||||
--- a/gex_httpd/src/gh_client.erl
|
||||
+++ b/gex_httpd/src/gh_client.erl
|
||||
@@ -127,22 +127,10 @@ listen(Parent, Debug, ListenSocket) ->
|
||||
loop(Parent, Debug, State = #s{socket = Socket}) ->
|
||||
ok = inet:setopts(Socket, [{active, once}]),
|
||||
receive
|
||||
- {tcp, Socket, <<"bye\r\n">>} ->
|
||||
- ok = io:format("~p Client saying goodbye. Bye!~n", [self()]),
|
||||
- ok = gen_tcp:send(Socket, "Bye!\r\n"),
|
||||
- ok = gen_tcp:shutdown(Socket, read_write),
|
||||
- exit(normal);
|
||||
{tcp, Socket, Message} ->
|
||||
ok = io:format("~p received: ~tp~n", [self(), Message]),
|
||||
ok = gh_client_man:echo(Message),
|
||||
loop(Parent, Debug, State);
|
||||
- {relay, Sender, Message} when Sender == self() ->
|
||||
- ok = gen_tcp:send(Socket, ["Message from YOU: ", Message]),
|
||||
- loop(Parent, Debug, State);
|
||||
- {relay, Sender, Message} ->
|
||||
- From = io_lib:format("Message from ~tp: ", [Sender]),
|
||||
- ok = gen_tcp:send(Socket, [From, Message]),
|
||||
- loop(Parent, Debug, State);
|
||||
{tcp_closed, Socket} ->
|
||||
ok = io:format("~p Socket closed, retiring.~n", [self()]),
|
||||
exit(normal);
|
||||
diff --git a/gex_httpd/src/gh_client_man.erl b/gex_httpd/src/gh_client_man.erl
|
||||
index 9c78921..c913dcc 100644
|
||||
--- a/gex_httpd/src/gh_client_man.erl
|
||||
+++ b/gex_httpd/src/gh_client_man.erl
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
|
||||
-export([listen/1, ignore/0]).
|
||||
--export([enroll/0, echo/1]).
|
||||
+-export([enroll/0]).
|
||||
-export([start_link/0]).
|
||||
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
|
||||
code_change/3, terminate/2]).
|
||||
@@ -74,17 +74,6 @@ enroll() ->
|
||||
gen_server:cast(?MODULE, {enroll, self()}).
|
||||
|
||||
|
||||
--spec echo(Message) -> ok
|
||||
- when Message :: string().
|
||||
-%% @doc
|
||||
-%% The function that tells the manager to broadcast a message to all clients.
|
||||
-%% This can broadcast arbitrary strings to clients from non-clients as well.
|
||||
-
|
||||
-echo(Message) ->
|
||||
- gen_server:cast(?MODULE, {echo, Message, self()}).
|
||||
-
|
||||
-
|
||||
-
|
||||
%%% Startup Functions
|
||||
|
||||
|
||||
@@ -145,9 +134,6 @@ handle_call(Unexpected, From, State) ->
|
||||
handle_cast({enroll, Pid}, State) ->
|
||||
NewState = do_enroll(Pid, State),
|
||||
{noreply, NewState};
|
||||
-handle_cast({echo, Message, Sender}, State) ->
|
||||
- ok = do_echo(Message, Sender, State),
|
||||
- {noreply, State};
|
||||
handle_cast(ignore, State) ->
|
||||
NewState = do_ignore(State),
|
||||
{noreply, NewState};
|
||||
@@ -262,17 +248,6 @@ do_enroll(Pid, State = #s{clients = Clients}) ->
|
||||
end.
|
||||
|
||||
|
||||
--spec do_echo(Message, Sender, State) -> ok
|
||||
- when Message :: string(),
|
||||
- Sender :: pid(),
|
||||
- State :: state().
|
||||
-%% @private
|
||||
-%% The "doer" procedure called when an "echo" message is received.
|
||||
-
|
||||
-do_echo(Message, Sender, #s{clients = Clients}) ->
|
||||
- Send = fun(Client) -> Client ! {relay, Sender, Message} end,
|
||||
- lists:foreach(Send, Clients).
|
||||
-
|
||||
|
||||
-spec handle_down(Mon, Pid, Reason, State) -> NewState
|
||||
when Mon :: reference(),
|
||||
```
|
||||
|
||||
@ -127,22 +127,10 @@ listen(Parent, Debug, ListenSocket) ->
|
||||
loop(Parent, Debug, State = #s{socket = Socket}) ->
|
||||
ok = inet:setopts(Socket, [{active, once}]),
|
||||
receive
|
||||
{tcp, Socket, <<"bye\r\n">>} ->
|
||||
ok = io:format("~p Client saying goodbye. Bye!~n", [self()]),
|
||||
ok = gen_tcp:send(Socket, "Bye!\r\n"),
|
||||
ok = gen_tcp:shutdown(Socket, read_write),
|
||||
exit(normal);
|
||||
{tcp, Socket, Message} ->
|
||||
ok = io:format("~p received: ~tp~n", [self(), Message]),
|
||||
ok = gh_client_man:echo(Message),
|
||||
loop(Parent, Debug, State);
|
||||
{relay, Sender, Message} when Sender == self() ->
|
||||
ok = gen_tcp:send(Socket, ["Message from YOU: ", Message]),
|
||||
loop(Parent, Debug, State);
|
||||
{relay, Sender, Message} ->
|
||||
From = io_lib:format("Message from ~tp: ", [Sender]),
|
||||
ok = gen_tcp:send(Socket, [From, Message]),
|
||||
loop(Parent, Debug, State);
|
||||
{tcp_closed, Socket} ->
|
||||
ok = io:format("~p Socket closed, retiring.~n", [self()]),
|
||||
exit(normal);
|
||||
|
||||
@ -17,7 +17,7 @@
|
||||
|
||||
|
||||
-export([listen/1, ignore/0]).
|
||||
-export([enroll/0, echo/1]).
|
||||
-export([enroll/0]).
|
||||
-export([start_link/0]).
|
||||
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
|
||||
code_change/3, terminate/2]).
|
||||
@ -74,17 +74,6 @@ enroll() ->
|
||||
gen_server:cast(?MODULE, {enroll, self()}).
|
||||
|
||||
|
||||
-spec echo(Message) -> ok
|
||||
when Message :: string().
|
||||
%% @doc
|
||||
%% The function that tells the manager to broadcast a message to all clients.
|
||||
%% This can broadcast arbitrary strings to clients from non-clients as well.
|
||||
|
||||
echo(Message) ->
|
||||
gen_server:cast(?MODULE, {echo, Message, self()}).
|
||||
|
||||
|
||||
|
||||
%%% Startup Functions
|
||||
|
||||
|
||||
@ -145,9 +134,6 @@ handle_call(Unexpected, From, State) ->
|
||||
handle_cast({enroll, Pid}, State) ->
|
||||
NewState = do_enroll(Pid, State),
|
||||
{noreply, NewState};
|
||||
handle_cast({echo, Message, Sender}, State) ->
|
||||
ok = do_echo(Message, Sender, State),
|
||||
{noreply, State};
|
||||
handle_cast(ignore, State) ->
|
||||
NewState = do_ignore(State),
|
||||
{noreply, NewState};
|
||||
@ -262,17 +248,6 @@ do_enroll(Pid, State = #s{clients = Clients}) ->
|
||||
end.
|
||||
|
||||
|
||||
-spec do_echo(Message, Sender, State) -> ok
|
||||
when Message :: string(),
|
||||
Sender :: pid(),
|
||||
State :: state().
|
||||
%% @private
|
||||
%% The "doer" procedure called when an "echo" message is received.
|
||||
|
||||
do_echo(Message, Sender, #s{clients = Clients}) ->
|
||||
Send = fun(Client) -> Client ! {relay, Sender, Message} end,
|
||||
lists:foreach(Send, Clients).
|
||||
|
||||
|
||||
-spec handle_down(Mon, Pid, Reason, State) -> NewState
|
||||
when Mon :: reference(),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user