aboutsummaryrefslogtreecommitdiffstats
path: root/README.md
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2011-04-02 20:27:16 +0200
committerLoïc Hoguin <[email protected]>2011-04-02 20:27:16 +0200
commite4da6956fceea1af8e2cdf9fece0e014576ab43c (patch)
treec182e61fd7f7500a40bd5346b582e50afc910431 /README.md
parente6e5b1767fe379c3fb9a9c46f2ec2b05bf485ce8 (diff)
downloadcowboy-e4da6956fceea1af8e2cdf9fece0e014576ab43c.tar.gz
cowboy-e4da6956fceea1af8e2cdf9fece0e014576ab43c.tar.bz2
cowboy-e4da6956fceea1af8e2cdf9fece0e014576ab43c.zip
Anonymize and improve the cowboy supervision tree.
* Cowboy isn't an OTP application anymore; just a supervisor. * All processes started by Cowboy are now anonymous. * All processes related to a listener are now part of its supervision tree.
Diffstat (limited to 'README.md')
-rw-r--r--README.md42
1 files changed, 26 insertions, 16 deletions
diff --git a/README.md b/README.md
index c47974c..c8e9f9f 100644
--- a/README.md
+++ b/README.md
@@ -33,30 +33,40 @@ Embedding Cowboy
Getting Started
---------------
-Cowboy can be started and stopped like any other application. However the
-Cowboy application do not start any listener, those must be started manually.
+Cowboy provides an anonymous listener supervisor that you can directly embed
+in your application's supervision tree.
A listener is a special kind of supervisor that handles a pool of acceptor
-processes. An acceptor simply accept connections and forward them to a
-protocol module, for example HTTP. You must thus define the transport and
-protocol module to use for the listener, their options and the number of
-acceptors in the pool before you can start a listener supervisor.
+processes. It also manages all its associated request processes. This allows
+you to shutdown all processes related to a listener by stopping the supervisor.
+
+An acceptor simply accepts connections and forwards them to a protocol module,
+for example HTTP. You must thus define the transport and protocol module to
+use for the listener, their options and the number of acceptors in the pool
+before you can start a listener supervisor.
For HTTP applications the transport can be either TCP or SSL for HTTP and
HTTPS respectively. On the other hand, the protocol is of course HTTP.
Code speaks more than words:
- application:start(cowboy),
- Dispatch = [
- %% {Host, list({Path, Handler, Opts})}
- {'_', [{'_', my_handler, []}]}
- ],
- %% NbAcceptors, Transport, TransOpts, Protocol, ProtoOpts
- cowboy_listener_sup:start_link(100,
- cowboy_tcp_transport, [{port, 8080}],
- cowboy_http_protocol, [{dispatch, Dispatch}]
- ).
+ -module(my_app).
+ -behaviour(application).
+ -export([start/2, stop/1]).
+
+ start(_Type, _Args) ->
+ Dispatch = [
+ %% {Host, list({Path, Handler, Opts})}
+ {'_', [{'_', my_handler, []}]}
+ ],
+ %% NbAcceptors, Transport, TransOpts, Protocol, ProtoOpts
+ cowboy_listener_sup:start_link(100,
+ cowboy_tcp_transport, [{port, 8080}],
+ cowboy_http_protocol, [{dispatch, Dispatch}]
+ ).
+
+ stop(_State) ->
+ ok.
You must also write the `my_handler` module to process requests. You can
use one of the predefined handlers or write your own. An hello world HTTP