auto-listen to port 8000
This commit is contained in:
parent
9c5b332e00
commit
2037444f54
66
README.md
66
README.md
@ -563,3 +563,69 @@ start_acceptor(ListenSocket) ->
|
|||||||
- Everything else is boilerplate
|
- Everything else is boilerplate
|
||||||
- So our task is to remove the relay-messages logic, and replace it with http
|
- So our task is to remove the relay-messages logic, and replace it with http
|
||||||
parse/respond logic.
|
parse/respond logic.
|
||||||
|
|
||||||
|
|
||||||
|
### Auto-listening to port `8000`
|
||||||
|
|
||||||
|
- Start commit: `9c5b332e009b88a9400a4e7008f760ce872b810a`
|
||||||
|
|
||||||
|
```diff
|
||||||
|
diff --git a/gex_httpd/src/gex_httpd.erl b/gex_httpd/src/gex_httpd.erl
|
||||||
|
index 242c82f..3a724b0 100644
|
||||||
|
--- a/gex_httpd/src/gex_httpd.erl
|
||||||
|
+++ b/gex_httpd/src/gex_httpd.erl
|
||||||
|
@@ -9,8 +9,11 @@
|
||||||
|
-copyright("Peter Harpending <peterharpending@qpq.swiss>").
|
||||||
|
|
||||||
|
|
||||||
|
+%% for our edification
|
||||||
|
-export([listen/1, ignore/0]).
|
||||||
|
--export([start/0, start/1]).
|
||||||
|
+-export([start/0]).
|
||||||
|
+
|
||||||
|
+%% erlang expects us to export these functions
|
||||||
|
-export([start/2, stop/1]).
|
||||||
|
|
||||||
|
|
||||||
|
@@ -45,17 +48,17 @@ start() ->
|
||||||
|
io:format("Starting...").
|
||||||
|
|
||||||
|
|
||||||
|
--spec start(PortNum) -> ok
|
||||||
|
- when PortNum :: inet:port_number().
|
||||||
|
-%% @doc
|
||||||
|
-%% Start the server and begin listening immediately. Slightly more convenient when
|
||||||
|
-%% playing around in the shell.
|
||||||
|
-
|
||||||
|
-start(PortNum) ->
|
||||||
|
- ok = start(),
|
||||||
|
- ok = gh_client_man:listen(PortNum),
|
||||||
|
- io:format("Startup complete, listening on ~w~n", [PortNum]).
|
||||||
|
-
|
||||||
|
+%-spec start(PortNum) -> ok
|
||||||
|
+% when PortNum :: inet:port_number().
|
||||||
|
+%%% @doc
|
||||||
|
+%%% Start the server and begin listening immediately. Slightly more convenient when
|
||||||
|
+%%% playing around in the shell.
|
||||||
|
+%
|
||||||
|
+%start(PortNum) ->
|
||||||
|
+% ok = start(),
|
||||||
|
+% ok = gh_client_man:listen(PortNum),
|
||||||
|
+% io:format("Startup complete, listening on ~w~n", [PortNum]).
|
||||||
|
+%
|
||||||
|
|
||||||
|
-spec start(normal, term()) -> {ok, pid()}.
|
||||||
|
%% @private
|
||||||
|
@@ -64,7 +67,10 @@ start(PortNum) ->
|
||||||
|
%% See: http://erlang.org/doc/apps/kernel/application.html
|
||||||
|
|
||||||
|
start(normal, _Args) ->
|
||||||
|
- gh_sup:start_link().
|
||||||
|
+ Result = gh_sup:start_link(),
|
||||||
|
+ % auto-listen to port 8000
|
||||||
|
+ ok = listen(8000),
|
||||||
|
+ Result.
|
||||||
|
|
||||||
|
|
||||||
|
-spec stop(term()) -> ok.
|
||||||
|
```
|
||||||
|
|||||||
@ -9,8 +9,11 @@
|
|||||||
-copyright("Peter Harpending <peterharpending@qpq.swiss>").
|
-copyright("Peter Harpending <peterharpending@qpq.swiss>").
|
||||||
|
|
||||||
|
|
||||||
|
%% for our edification
|
||||||
-export([listen/1, ignore/0]).
|
-export([listen/1, ignore/0]).
|
||||||
-export([start/0, start/1]).
|
-export([start/0]).
|
||||||
|
|
||||||
|
%% erlang expects us to export these functions
|
||||||
-export([start/2, stop/1]).
|
-export([start/2, stop/1]).
|
||||||
|
|
||||||
|
|
||||||
@ -45,17 +48,17 @@ start() ->
|
|||||||
io:format("Starting...").
|
io:format("Starting...").
|
||||||
|
|
||||||
|
|
||||||
-spec start(PortNum) -> ok
|
%-spec start(PortNum) -> ok
|
||||||
when PortNum :: inet:port_number().
|
% when PortNum :: inet:port_number().
|
||||||
%% @doc
|
%%% @doc
|
||||||
%% Start the server and begin listening immediately. Slightly more convenient when
|
%%% Start the server and begin listening immediately. Slightly more convenient when
|
||||||
%% playing around in the shell.
|
%%% playing around in the shell.
|
||||||
|
%
|
||||||
start(PortNum) ->
|
%start(PortNum) ->
|
||||||
ok = start(),
|
% ok = start(),
|
||||||
ok = gh_client_man:listen(PortNum),
|
% ok = gh_client_man:listen(PortNum),
|
||||||
io:format("Startup complete, listening on ~w~n", [PortNum]).
|
% io:format("Startup complete, listening on ~w~n", [PortNum]).
|
||||||
|
%
|
||||||
|
|
||||||
-spec start(normal, term()) -> {ok, pid()}.
|
-spec start(normal, term()) -> {ok, pid()}.
|
||||||
%% @private
|
%% @private
|
||||||
@ -64,7 +67,10 @@ start(PortNum) ->
|
|||||||
%% See: http://erlang.org/doc/apps/kernel/application.html
|
%% See: http://erlang.org/doc/apps/kernel/application.html
|
||||||
|
|
||||||
start(normal, _Args) ->
|
start(normal, _Args) ->
|
||||||
gh_sup:start_link().
|
Result = gh_sup:start_link(),
|
||||||
|
% auto-listen to port 8000
|
||||||
|
ok = listen(8000),
|
||||||
|
Result.
|
||||||
|
|
||||||
|
|
||||||
-spec stop(term()) -> ok.
|
-spec stop(term()) -> ok.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user