diff options
author | Loïc Hoguin <[email protected]> | 2012-12-24 16:09:40 +0100 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2012-12-24 16:09:40 +0100 |
commit | 9993923c40b96ab07752ec36692dc09c4c7648e9 (patch) | |
tree | 7df91a8df7f0ef5ee4a6883e723fe0d86fa9ff83 /src/ranch_listener.erl | |
parent | 058ad09e8b2c885a0888bda47459acd32ece917e (diff) | |
download | ranch-9993923c40b96ab07752ec36692dc09c4c7648e9.tar.gz ranch-9993923c40b96ab07752ec36692dc09c4c7648e9.tar.bz2 ranch-9993923c40b96ab07752ec36692dc09c4c7648e9.zip |
Add ranch:set_max_connections/2 and get_max_connections/1
Diffstat (limited to 'src/ranch_listener.erl')
-rw-r--r-- | src/ranch_listener.erl | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/src/ranch_listener.erl b/src/ranch_listener.erl index 52e4c32..873d860 100644 --- a/src/ranch_listener.erl +++ b/src/ranch_listener.erl @@ -24,6 +24,7 @@ -export([get_port/1]). -export([set_port/2]). -export([get_max_connections/1]). +-export([set_max_connections/2]). -export([get_protocol_options/1]). -export([set_protocol_options/2]). @@ -82,11 +83,15 @@ set_port(ServerPid, Port) -> gen_server:cast(ServerPid, {set_port, Port}). %% @doc Return the max number of connections allowed concurrently. -%% @todo Add set_max_connections. -spec get_max_connections(pid()) -> {ok, non_neg_integer()}. get_max_connections(ServerPid) -> gen_server:call(ServerPid, get_max_connections). +%% @doc Set the max number of connections allowed concurrently. +-spec set_max_connections(pid(), non_neg_integer()) -> ok. +set_max_connections(ServerPid, MaxConnections) -> + gen_server:call(ServerPid, {set_max_connections, MaxConnections}). + %% @doc Return the current protocol options. -spec get_protocol_options(pid()) -> {ok, any()}. get_protocol_options(ServerPid) -> @@ -109,6 +114,10 @@ handle_call(get_port, _From, State=#state{port=Port}) -> {reply, {ok, Port}, State}; handle_call(get_max_connections, _From, State=#state{max_conns=MaxConns}) -> {reply, {ok, MaxConns}, State}; +handle_call({set_max_connections, MaxConnections}, _From, + State=#state{ref=Ref}) -> + ranch_server:send_to_acceptors(Ref, {set_max_conns, MaxConnections}), + {reply, ok, State#state{max_conns=MaxConnections}}; handle_call(get_protocol_options, _From, State=#state{proto_opts=ProtoOpts}) -> {reply, {ok, ProtoOpts}, State}; handle_call({set_protocol_options, ProtoOpts}, _From, State=#state{ref=Ref}) -> |