Created
September 21, 2016 18:07
-
-
Save essen/3affa1c8e7805a7dc867156b03c1854f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
COWBOY:START_CLEAR(3) COWBOY:START_CLEAR(3) | |
NAME | |
cowboy:start_clear - Listen for connections using plain TCP | |
DESCRIPTION | |
start_clear(Name :: ranch:ref(), | |
NumAcceptors :: non_neg_integer(), | |
TransportOpts :: ranch_tcp:opts(), | |
ProtocolOpts :: opts()) | |
-> {ok, ListenerPid :: pid()} | |
| {error, any()} | |
Start listening for connections over a clear TCP channel. | |
Both HTTP/1.1 and HTTP/2 are supported on this listener. HTTP/2 has | |
two methods of establishing a connection over a clear TCP channel. | |
Both the upgrade and the prior knowledge methods are supported. | |
ARGUMENTS | |
Name | |
The listener name is used to refer to this listener in future | |
calls, for example when stopping it or when updating the routes | |
defined. | |
It can be any Erlang term. An atom is generally good enough, for | |
example api, my_app_clear or my_app_tls. | |
NumAcceptors | |
The number of acceptors is the number of processes that will | |
accept connections. Tweak this value to improve the accept rate | |
for incoming connections. | |
The ideal value is between 10 and 100 on most systems. Larger | |
values may have the opposite effect and reduce the accept rate. | |
It’s generally safe to start with a value of 100 (or 10 on low | |
memory systems). Then, when accept rates become a concern, measure | |
the performance and update the value accordingly. | |
This value is unrelated to the maximum number of concurrent | |
connections. | |
TransportOpts | |
The transport options are where the TCP options, including the | |
listener’s port number, are defined. Transport options are | |
provided as a list of keys and values, for example [{port, 8080}]. | |
ProtocolOpts | |
The protocol options is a map containing all the options for the | |
different protocols that may be involved when connecting to this | |
listener, including HTTP/1.1 and HTTP/2 but also subprotocols like | |
Websocket. | |
RETURN VALUE | |
An ok tuple is returned on success. It contains the pid of the | |
top-level supervisor for the listener. | |
An error tuple is returned on error. The error reason may be any | |
Erlang term. | |
CHANGELOG | |
· 2.0: Function introduced. Replaces cowboy:start_http/4. | |
EXAMPLES | |
Start a listener. | |
Dispatch = cowboy_router:compile([ | |
{'_', [ | |
{"/", toppage_h, []} | |
]} | |
]), | |
{ok, _} = cowboy:start_clear(example, 100, [{port, 8080}], #{ | |
env => #{dispatch => Dispatch} | |
}). | |
Start a listener on a random port. | |
Name = example, | |
{ok, _} = cowboy:start_clear(Name, 100, [], #{ | |
env => #{dispatch => Dispatch} | |
}), | |
Port = ranch:get_port(Name). | |
SEE ALSO | |
cowboy(3), cowboy:start_tls(3), ranch(3) | |
09/21/2016 COWBOY:START_CLEAR(3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment